WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WC_Tax::delete_tax_class_by() public WC 3.7.0

Delete an existing tax class.

Это метод класса: WC_Tax{}

Хуков нет.

Возвращает

WP_Error/true/false. Returns true if deleted successfully, false if nothing was deleted, or WP_Error if there is an invalid request.

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

$result = WC_Tax::delete_tax_class_by( $field, $item );
$field(строка) (обязательный)
Field to delete by. Valid values are id, name, or slug.
$item(строка/число) (обязательный)
Item to delete.

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

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

Код WC_Tax::delete_tax_class_by() WC 4.5.2

woocommerce/includes/class-wc-tax.php
<?php
public static function delete_tax_class_by( $field, $item ) {
	global $wpdb;

	if ( ! in_array( $field, array( 'id', 'name', 'slug' ), true ) ) {
		return new WP_Error( 'invalid_field', __( 'Invalid field', 'woocommerce' ) );
	}

	$tax_class = self::get_tax_class_by( $field, $item );

	if ( ! $tax_class ) {
		return new WP_Error( 'invalid_tax_class', __( 'Invalid tax class', 'woocommerce' ) );
	}

	if ( 'id' === $field ) {
		$field = 'tax_rate_class_id';
	}

	$delete = $wpdb->delete(
		$wpdb->wc_tax_rate_classes,
		array(
			$field => $item,
		)
	);

	if ( $delete ) {
		// Delete associated tax rates.
		$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_class = %s;", $tax_class['slug'] ) );
		$wpdb->query( "DELETE locations FROM {$wpdb->prefix}woocommerce_tax_rate_locations locations LEFT JOIN {$wpdb->prefix}woocommerce_tax_rates rates ON rates.tax_rate_id = locations.tax_rate_id WHERE rates.tax_rate_id IS NULL;" );
	}

	wp_cache_delete( 'tax-rate-classes', 'taxes' );
	WC_Cache_Helper::invalidate_cache_group( 'taxes' );

	return (bool) $delete;
}