WC_Tax::get_tax_class_by()
Get an existing tax class.
Метод класса: WC_Tax{}
Хуков нет.
Возвращает
Массив|true|false
. Returns the tax class as an array. False if not found.
Использование
$result = WC_Tax::get_tax_class_by( $field, $item );
- $field(строка) (обязательный)
- Field to get by. Valid values are id, name, or slug.
- $item(строка|int) (обязательный)
- Item to get.
Список изменений
С версии 3.7.0 | Введена. |
Код WC_Tax::get_tax_class_by() WC Tax::get tax class by WC 9.5.1
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, ); }