Introduce filters to filter $from and $to

This will introduce two new filters:

woocommerce_from_product_type_changed
woocommerce_to_product_type_changed

to filter the $from and $to variables respectively.

This will be useful in WCS pr_3732!
This commit is contained in:
Omkar Bhagat 2020-09-09 00:33:51 +05:30
parent 4ecb468690
commit 6bca55b6d6
1 changed files with 3 additions and 3 deletions

View File

@ -127,10 +127,10 @@ class WC_Post_Data {
* @param string $to New type.
*/
public static function product_type_changed( $product, $from, $to ) {
$from_variable_type = ( false !== strpos( $from, 'variable' ) );
$to_variable_type = ( false !== strpos( $to, 'variable' ) );
apply_filters( 'woocommerce_from_product_type_changed', $from );
apply_filters( 'woocommerce_to_product_type_changed', $to );
if ( $from_variable_type && ! $to_variable_type ) {
if ( 'variable' === $from && 'variable' !== $to ) {
// If the product is no longer variable, we should ensure all variations are removed.
$data_store = WC_Data_Store::load( 'product-variable' );
$data_store->delete_variations( $product->get_id(), true );