Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions includes/ProductSets/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
*
Expand Down Expand Up @@ -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 );
Comment thread
rawdreeg marked this conversation as resolved.
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
Expand Down Expand Up @@ -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;
}


Expand All @@ -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 );
}
}
Expand Down