Skip to content

Commit

Permalink
*Hook woocommerce_product_type_changed to ensure product type stays s…
Browse files Browse the repository at this point in the history
  • Loading branch information
pcfreak30 committed Feb 22, 2020
1 parent dcfbf7a commit ec73407
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions includes/class-wc-product-tables-backwards-compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static function hook() {
add_filter( 'add_post_metadata', array( __CLASS__, 'add_metadata_to_tables' ), 99, 5 );
add_filter( 'update_post_metadata', array( __CLASS__, 'update_metadata_in_tables' ), 99, 5 );
add_filter( 'delete_post_metadata', array( __CLASS__, 'delete_metadata_from_tables' ), 99, 5 );
add_filter( 'woocommerce_product_type_changed', array( __CLASS__, 'sync_product_type' ), 10, 3 );
}

/**
Expand All @@ -38,6 +39,7 @@ public static function unhook() {
remove_filter( 'add_post_metadata', array( __CLASS__, 'add_metadata_to_tables' ), 99, 5 );
remove_filter( 'update_post_metadata', array( __CLASS__, 'update_metadata_in_tables' ), 99, 5 );
remove_filter( 'delete_post_metadata', array( __CLASS__, 'delete_metadata_from_tables' ), 99, 5 );
add_filter( 'woocommerce_product_type_changed', array( __CLASS__, 'sync_product_type' ), 10 );
}

/**
Expand Down Expand Up @@ -1643,6 +1645,22 @@ protected static function get_product( $product_id ) {

return $product;
}

/**
* @param \WC_Product $product
* @param string $old_type
* @param string $new_type
*
* @return void
*/
public static function sync_product_type( $product, $old_type, $new_type ) {
self::update_in_product_table( array(
'product_id' => $product->get_id(),
'column' => 'type',
'format' => '%s',
'value' => $new_type,
) );
}
}

WC_Product_Tables_Backwards_Compatibility::hook();

0 comments on commit ec73407

Please sign in to comment.