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:
Md. Saiful Islam 2018-10-26 21:05:52 +06:00 committed by GitHub
parent d1c90c5972
commit 50d33a5793
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

View File

@ -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 === $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' );
$response = $this->prepare_item_for_response( $term, $request );