diff --git a/includes/class-wc-product-tables-backwards-compatibility.php b/includes/class-wc-product-tables-backwards-compatibility.php index e79ab82..5a9e344 100644 --- a/includes/class-wc-product-tables-backwards-compatibility.php +++ b/includes/class-wc-product-tables-backwards-compatibility.php @@ -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 ); } /** @@ -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 ); } /** @@ -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();