Merge pull request #21696 from siananda/fix-21652
Prevent deleting default product category via REST API
This commit is contained in:
commit
4aad055e62
|
@ -533,6 +533,14 @@ abstract class WC_REST_Terms_Controller extends WC_REST_Controller {
|
|||
}
|
||||
|
||||
$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 === (int) $request['id'] ) {
|
||||
return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'Default product category cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) );
|
||||
}
|
||||
|
||||
$request->set_param( 'context', 'edit' );
|
||||
$response = $this->prepare_item_for_response( $term, $request );
|
||||
|
||||
|
|
Loading…
Reference in New Issue