Logic is not grouped specific; only for product types with children
This commit is contained in:
parent
c94a5df7a4
commit
a480cff0d2
|
@ -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,9 +1354,12 @@ 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 );
|
||||
if ( ! empty( $child ) ) {
|
||||
|
|
|
@ -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