diff --git a/includes/ProductSets/Sync.php b/includes/ProductSets/Sync.php index 3a6b238a2..ae16c72df 100644 --- a/includes/ProductSets/Sync.php +++ b/includes/ProductSets/Sync.php @@ -71,6 +71,15 @@ class Sync { */ protected static $prev_product_set = array(); + /** + * Product's Product Set Previous Name + * + * @since x.x.x + * + * @var string + */ + protected static $prev_product_name = ""; + /** * Product's Product Set New List * @@ -80,6 +89,15 @@ class Sync { */ protected static $new_product_set = array(); + /** + * Product's Product Set New Name + * + * @since x.x.x + * + * @var string + */ + protected static $new_product_name = ""; + /** * Categories field name * @@ -122,7 +140,7 @@ public function add_hooks() { // product set hooks, compare taxonomies the lists before and after saving product to see if must sync add_action( 'created_fb_product_set', array( $this, 'fb_product_set_hook_before' ), 1 ); add_action( 'created_fb_product_set', array( $this, 'fb_product_set_hook_after' ), 99 ); - add_action( 'edited_fb_product_set', array( $this, 'fb_product_set_hook_before' ), 1 ); + add_action( 'edit_fb_product_set', array( $this, 'fb_product_set_hook_before' ), 1 ); add_action( 'edited_fb_product_set', array( $this, 'fb_product_set_hook_after' ), 99 ); // product cat and product set delete hooks, remove or check if must remove any product set @@ -240,6 +258,7 @@ public function maybe_sync_product_sets( $product_cats, $product_sets ) { */ public function fb_product_set_hook_before( $term_id ) { self::$prev_product_cat = get_term_meta( $term_id, $this->categories_field, true ); + self::$prev_product_name = get_term( $term_id )->name; } @@ -252,7 +271,8 @@ public function fb_product_set_hook_before( $term_id ) { */ public function fb_product_set_hook_after( $term_id ) { self::$new_product_cat = get_term_meta( $term_id, $this->categories_field, true ); - if ( ! empty( $this->get_all_diff( 'product_cat' ) ) ) { + self::$new_product_name = get_term( $term_id )->name; + if ( ! empty( $this->get_all_diff( 'product_cat' ) ) || self::$prev_product_name !== self::$new_product_name ) { $this->maybe_sync_product_set( $term_id ); } }