Merge pull request #20670 from woocommerce/pr/20669
Deleting a product via API should handle children products regardless of type.
This commit is contained in:
commit
1c7b2f3100
|
@ -877,7 +877,7 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
}
|
||||
}
|
||||
|
||||
// Product parent ID for groups.
|
||||
// Product parent ID.
|
||||
if ( isset( $request['parent_id'] ) ) {
|
||||
$product->set_parent_id( $request['parent_id'] );
|
||||
}
|
||||
|
@ -1354,13 +1354,18 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
if ( $object->is_type( 'variable' ) ) {
|
||||
foreach ( $object->get_children() as $child_id ) {
|
||||
$child = wc_get_product( $child_id );
|
||||
$child->delete( true );
|
||||
if ( ! empty( $child ) ) {
|
||||
$child->delete( true );
|
||||
}
|
||||
}
|
||||
} elseif ( $object->is_type( 'grouped' ) ) {
|
||||
} else {
|
||||
// For other product types, if the product has children, remove the relationship.
|
||||
foreach ( $object->get_children() as $child_id ) {
|
||||
$child = wc_get_product( $child_id );
|
||||
$child->set_parent_id( 0 );
|
||||
$child->save();
|
||||
if ( ! empty( $child ) ) {
|
||||
$child->set_parent_id( 0 );
|
||||
$child->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -429,13 +429,18 @@ class WC_API_Products extends WC_API_Resource {
|
|||
if ( $product->is_type( 'variable' ) ) {
|
||||
foreach ( $product->get_children() as $child_id ) {
|
||||
$child = wc_get_product( $child_id );
|
||||
$child->delete( true );
|
||||
if ( ! empty( $child ) ) {
|
||||
$child->delete( true );
|
||||
}
|
||||
}
|
||||
} elseif ( $product->is_type( 'grouped' ) ) {
|
||||
} else {
|
||||
// For other product types, if the product has children, remove the relationship.
|
||||
foreach ( $product->get_children() as $child_id ) {
|
||||
$child = wc_get_product( $child_id );
|
||||
$child->set_parent_id( 0 );
|
||||
$child->save();
|
||||
if ( ! empty( $child ) ) {
|
||||
$child->set_parent_id( 0 );
|
||||
$child->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -488,13 +488,18 @@ class WC_API_Products extends WC_API_Resource {
|
|||
if ( $product->is_type( 'variable' ) ) {
|
||||
foreach ( $product->get_children() as $child_id ) {
|
||||
$child = wc_get_product( $child_id );
|
||||
$child->delete( true );
|
||||
if ( ! empty( $child ) ) {
|
||||
$child->delete( true );
|
||||
}
|
||||
}
|
||||
} elseif ( $product->is_type( 'grouped' ) ) {
|
||||
} else {
|
||||
// For other product types, if the product has children, remove the relationship.
|
||||
foreach ( $product->get_children() as $child_id ) {
|
||||
$child = wc_get_product( $child_id );
|
||||
$child->set_parent_id( 0 );
|
||||
$child->save();
|
||||
if ( ! empty( $child ) ) {
|
||||
$child->set_parent_id( 0 );
|
||||
$child->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1664,13 +1664,18 @@ class WC_REST_Products_V1_Controller extends WC_REST_Posts_Controller {
|
|||
if ( $product->is_type( 'variable' ) ) {
|
||||
foreach ( $product->get_children() as $child_id ) {
|
||||
$child = wc_get_product( $child_id );
|
||||
$child->delete( true );
|
||||
if ( ! empty( $child ) ) {
|
||||
$child->delete( true );
|
||||
}
|
||||
}
|
||||
} elseif ( $product->is_type( 'grouped' ) ) {
|
||||
} else {
|
||||
// For other product types, if the product has children, remove the relationship.
|
||||
foreach ( $product->get_children() as $child_id ) {
|
||||
$child = wc_get_product( $child_id );
|
||||
$child->set_parent_id( 0 );
|
||||
$child->save();
|
||||
if ( ! empty( $child ) ) {
|
||||
$child->set_parent_id( 0 );
|
||||
$child->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue