WordPress at Your Fingertips
function is not described

WC_API_Taxes::delete_tax_class() public WC 2.5.0

Delete a tax class

{} It's a 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.

Code of WC_API_Taxes::delete_tax_class() WC 5.7.1

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() ) );
	}
}