WC_API_Taxes::delete_tax_class()publicWC 2.5.0

Delete a tax class

Метод класса: WC_API_Taxes{}

Хуков нет.

Возвращает

Массив|WP_Error.

Использование

$WC_API_Taxes = new WC_API_Taxes();
$WC_API_Taxes->delete_tax_class( $slug );
$slug(int) (обязательный)
The tax class slug

Список изменений

С версии 2.5.0 Введена.

Код WC_API_Taxes::delete_tax_class() WC 8.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() ) );
	}
}