Fix for issue #21652
Prevent deleting the default product category. Added additional checking is the category is the default category or not.
This commit is contained in:
parent
d1c90c5972
commit
50d33a5793
|
@ -533,6 +533,14 @@ abstract class WC_REST_Terms_Controller extends WC_REST_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
$term = get_term( (int) $request['id'], $taxonomy );
|
$term = get_term( (int) $request['id'], $taxonomy );
|
||||||
|
// Get default category id.
|
||||||
|
$default_category_id = absint( get_option( 'default_product_cat', 0 ) );
|
||||||
|
|
||||||
|
// Prevent deleting the default product category
|
||||||
|
if ( $default_category_id === $term ) {
|
||||||
|
return new WP_Error( 'woocommerce_rest_default_product_cat_cannot_delete', __( 'Default product category cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) );
|
||||||
|
}
|
||||||
|
|
||||||
$request->set_param( 'context', 'edit' );
|
$request->set_param( 'context', 'edit' );
|
||||||
$response = $this->prepare_item_for_response( $term, $request );
|
$response = $this->prepare_item_for_response( $term, $request );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue