WC_Tax::get_tax_class_by( string $field, string|int $item )
Get an existing tax class.
Description Description
Parameters Parameters
- $field
-
(Required) Field to get by. Valid values are id, name, or slug.
- $item
-
(Required) Item to get.
Return Return
(array|bool) Returns the tax class as an array. False if not found.
Source Source
File: includes/class-wc-tax.php
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,
);
}
Changelog Changelog
| Version | Description |
|---|---|
| 3.7.0 | Introduced. |