WC_API_Taxes::delete_tax_class()
Delete a tax class
Method of the class: WC_API_Taxes{}
No Hooks.
Return
Array|WP_Error
.
Usage
$WC_API_Taxes = new WC_API_Taxes(); $WC_API_Taxes->delete_tax_class( $slug );
- $slug(int) (required)
- The tax class slug
Changelog
Since 2.5.0 | Introduced. |
WC_API_Taxes::delete_tax_class() WC API Taxes::delete tax class code WC 7.7.0
public function delete_tax_class( $slug ) { global $wpdb; try { // Check permissions if ( ! current_user_can( 'manage_woocommerce' ) ) { throw new WC_API_Exception( 'woocommerce_api_user_cannot_delete_tax_class', __( 'You do not have permission to delete tax classes', 'woocommerce' ), 401 ); } $slug = sanitize_title( $slug ); $tax_class = WC_Tax::get_tax_class_by( 'slug', $slug ); $deleted = WC_Tax::delete_tax_class_by( 'slug', $slug ); if ( is_wp_error( $deleted ) || ! $deleted ) { throw new WC_API_Exception( 'woocommerce_api_cannot_delete_tax_class', __( 'Could not delete the tax class', 'woocommerce' ), 401 ); } return array( 'message' => sprintf( __( 'Deleted %s', 'woocommerce' ), 'tax_class' ) ); } catch ( WC_API_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } }