Modify the logic for deleting variations
Implements the following expected behaviour: 1. Switch from variable subscription to non-variable one will delete variations. 2. Switch from variable subscription to variable product and vice-versa will NOT delete any variations. This shall have no side-effects in WooCommerce Core.
This commit is contained in:
parent
358ea384d6
commit
4ecb468690
|
@ -127,7 +127,10 @@ class WC_Post_Data {
|
|||
* @param string $to New type.
|
||||
*/
|
||||
public static function product_type_changed( $product, $from, $to ) {
|
||||
if ( 'variable' === $from && 'variable' !== $to ) {
|
||||
$from_variable_type = ( false !== strpos( $from, 'variable' ) );
|
||||
$to_variable_type = ( false !== strpos( $to, 'variable' ) );
|
||||
|
||||
if ( $from_variable_type && ! $to_variable_type ) {
|
||||
// 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 );
|
||||
|
|
Loading…
Reference in New Issue