Custom Product Tabs for WooCommerce - Version 1.5.10

Version Description

  • April 5th, 2017 =
  • Duplicating a product now duplicates custom product tabs and saved tabs correctly
Download this release

Release Info

Developer yikesitskevin
Plugin Icon 128x128 Custom Product Tabs for WooCommerce
Version 1.5.10
Comparing to
See all releases

Code changes from version 1.5.9 to 1.5.10

readme.txt CHANGED
@@ -6,7 +6,7 @@ Requires at least: 3.8
6
  Tested up to: 4.7.3
7
  Requires WooCommerce at least: 2.0
8
  Tested WooCommerce up to: 3.0.0
9
- Stable tag: 1.5.9
10
  License: GPLv2 or later
11
 
12
  Add custom tabs with content to products in WooCommerce.
@@ -74,6 +74,9 @@ Yes! Since v1.4 we've added the necessary code to ensure the custom tab data is
74
 
75
  == Changelog ==
76
 
 
 
 
77
  = 1.5.9 - April 4th, 2017 =
78
  * Tested and updated the plugin for WooCommerce v3.0.0
79
 
6
  Tested up to: 4.7.3
7
  Requires WooCommerce at least: 2.0
8
  Tested WooCommerce up to: 3.0.0
9
+ Stable tag: 1.5.10
10
  License: GPLv2 or later
11
 
12
  Add custom tabs with content to products in WooCommerce.
74
 
75
  == Changelog ==
76
 
77
+ = 1.5.10 - April 5th, 2017 =
78
+ * Duplicating a product now duplicates custom product tabs and saved tabs correctly
79
+
80
  = 1.5.9 - April 4th, 2017 =
81
  * Tested and updated the plugin for WooCommerce v3.0.0
82
 
yikes-inc-easy-custom-woocommerce-product-tabs.php CHANGED
@@ -5,7 +5,7 @@
5
  * Description: Extend WooCommerce to add and manage custom product tabs. Create as many product tabs as needed per product.
6
  * Author: YIKES, Inc
7
  * Author URI: http://www.yikesinc.com
8
- * Version: 1.5.9
9
  * Text Domain: yikes-inc-easy-custom-woocommerce-product-tabs
10
  * Domain Path: languages/
11
  *
@@ -62,7 +62,7 @@
62
  private $tab_data = false;
63
 
64
  /** plugin version number */
65
- const VERSION = '1.5.9';
66
 
67
  /** plugin text domain */
68
  const TEXT_DOMAIN = 'yikes-inc-easy-custom-woocommerce-product-tabs';
@@ -179,8 +179,11 @@
179
  // Add settings link to plugin on plugins page
180
  add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array( $this, 'add_plugin_action_links' ), 10, 1 );
181
 
 
 
 
182
  // Duplicate any saved tabs when a product is duplicated
183
- add_filter( 'woocommerce_duplicate_product', array( $this, 'yikes_woo_dupe_saved_tabs_on_product_dupe' ), 10, 2 );
184
  }
185
 
186
  /**
@@ -1211,19 +1214,34 @@
1211
  }
1212
  }
1213
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1214
  /**
1215
  * When a WooCommere product is duplicated, check for and duplicate the saved tabs.
1216
  *
1217
- * @param int | $post_id | The new post's ID
1218
- * @param object | $old_post| The old post's post object (the one that was used to duplicate - not the new, duplicated one)
1219
  */
1220
- public function yikes_woo_dupe_saved_tabs_on_product_dupe( $post_id, $old_post ) {
1221
 
1222
  // First, let's grab our applied saved tab options array
1223
  $saved_tabs_array = get_option( 'yikes_woo_reusable_products_tabs_applied' );
1224
 
1225
  // Grab the old post's ID
1226
- $old_post_id = isset( $old_post->ID ) ? $old_post->ID : '';
1227
 
1228
  // (1) Make sure we have a non-empty array of saved tabs,
1229
  // (2) Makre sure we have the ID of the old post, and then
@@ -1233,11 +1251,11 @@
1233
  // Loop through the $saved_tabs_array and update the post_id item
1234
  $new_products_saved_tabs = $saved_tabs_array[$old_post_id];
1235
  foreach ( $new_products_saved_tabs as $saved_tab_id => $saved_tab ) {
1236
- $new_products_saved_tabs[$saved_tab_id]['post_id'] = $post_id;
1237
  }
1238
 
1239
  // Add the old post's saved tabs, with the new post's ID as the key
1240
- $saved_tabs_array[$post_id] = $new_products_saved_tabs;
1241
 
1242
  // Update the saved tab's option
1243
  update_option( 'yikes_woo_reusable_products_tabs_applied', $saved_tabs_array );
5
  * Description: Extend WooCommerce to add and manage custom product tabs. Create as many product tabs as needed per product.
6
  * Author: YIKES, Inc
7
  * Author URI: http://www.yikesinc.com
8
+ * Version: 1.5.10
9
  * Text Domain: yikes-inc-easy-custom-woocommerce-product-tabs
10
  * Domain Path: languages/
11
  *
62
  private $tab_data = false;
63
 
64
  /** plugin version number */
65
+ const VERSION = '1.5.10';
66
 
67
  /** plugin text domain */
68
  const TEXT_DOMAIN = 'yikes-inc-easy-custom-woocommerce-product-tabs';
179
  // Add settings link to plugin on plugins page
180
  add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array( $this, 'add_plugin_action_links' ), 10, 1 );
181
 
182
+ // Duplicate any custom tabs when a product is duplicated
183
+ add_action( 'woocommerce_product_duplicate', array( $this, 'yikes_woo_dupe_custom_product_tabs' ), 10, 2 );
184
+
185
  // Duplicate any saved tabs when a product is duplicated
186
+ add_filter( 'woocommerce_product_duplicate', array( $this, 'yikes_woo_dupe_saved_tabs_on_product_dupe' ), 11, 2 );
187
  }
188
 
189
  /**
1214
  }
1215
  }
1216
 
1217
+
1218
+ /**
1219
+ * When a WooCommere product is duplicated, check for and duplicate the custom tabs.
1220
+ *
1221
+ * @param object | $duplicated_product | The new, duplicated product
1222
+ * @param object | $original_product | The original product
1223
+ */
1224
+ public function yikes_woo_dupe_custom_product_tabs( $duplicate_product, $original_product ) {
1225
+ $current_products_tabs = get_post_meta( $original_product->get_id(), 'yikes_woo_products_tabs', true );
1226
+
1227
+ if ( ! empty( $current_products_tabs ) ) {
1228
+ update_post_meta( $duplicate_product->get_id(), 'yikes_woo_products_tabs', $current_products_tabs );
1229
+ }
1230
+ }
1231
+
1232
  /**
1233
  * When a WooCommere product is duplicated, check for and duplicate the saved tabs.
1234
  *
1235
+ * @param object | $duplicated_product | The new, duplicated product
1236
+ * @param object | $original_product | The original product
1237
  */
1238
+ public function yikes_woo_dupe_saved_tabs_on_product_dupe( $duplicate_product, $original_product ) {
1239
 
1240
  // First, let's grab our applied saved tab options array
1241
  $saved_tabs_array = get_option( 'yikes_woo_reusable_products_tabs_applied' );
1242
 
1243
  // Grab the old post's ID
1244
+ $old_post_id = $original_product->get_id();
1245
 
1246
  // (1) Make sure we have a non-empty array of saved tabs,
1247
  // (2) Makre sure we have the ID of the old post, and then
1251
  // Loop through the $saved_tabs_array and update the post_id item
1252
  $new_products_saved_tabs = $saved_tabs_array[$old_post_id];
1253
  foreach ( $new_products_saved_tabs as $saved_tab_id => $saved_tab ) {
1254
+ $new_products_saved_tabs[$saved_tab_id]['post_id'] = $duplicate_product->get_id();
1255
  }
1256
 
1257
  // Add the old post's saved tabs, with the new post's ID as the key
1258
+ $saved_tabs_array[$duplicate_product->get_id()] = $new_products_saved_tabs;
1259
 
1260
  // Update the saved tab's option
1261
  update_option( 'yikes_woo_reusable_products_tabs_applied', $saved_tabs_array );