WC_API_Taxes::delete_tax()
Delete a tax
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( $id );
- $id(int) (required)
- The tax ID
Changelog
Since 2.5.0 | Introduced. |
WC_API_Taxes::delete_tax() WC API Taxes::delete tax code WC 7.7.0
public function delete_tax( $id ) { global $wpdb; try { // Check permissions if ( ! current_user_can( 'manage_woocommerce' ) ) { throw new WC_API_Exception( 'woocommerce_api_user_cannot_delete_tax', __( 'You do not have permission to delete tax rates', 'woocommerce' ), 401 ); } $id = absint( $id ); WC_Tax::_delete_tax_rate( $id ); if ( 0 === $wpdb->rows_affected ) { throw new WC_API_Exception( 'woocommerce_api_cannot_delete_tax', __( 'Could not delete the tax rate', 'woocommerce' ), 401 ); } return array( 'message' => sprintf( __( 'Deleted %s', 'woocommerce' ), 'tax' ) ); } catch ( WC_API_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } }