WordPress at Your Fingertips
function is not described

WC_Tax::get_tax_class_by() public WC 3.7.0

Get an existing tax class.

{} It's a method of the class: WC_Tax{}

No Hooks.

Return

Array|true|false. Returns the tax class as an array. False if not found.

Usage

$result = WC_Tax::get_tax_class_by( $field, $item );
$field(string) (required)
Field to get by. Valid values are id, name, or slug.
$item(string|int) (required)
Item to get.

Changelog

Since 3.7.0 Introduced.

Code of WC_Tax::get_tax_class_by() WC 5.9.0

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

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

	$matches = wp_list_filter(
		self::get_tax_rate_classes(),
		array(
			$field => $item,
		)
	);

	if ( ! $matches ) {
		return false;
	}

	$tax_class = current( $matches );

	return array(
		'name' => $tax_class->name,
		'slug' => $tax_class->slug,
	);
}