meta_is_product_attribute()
Returns true when the passed meta name is a product attribute.
Хуков нет.
Возвращает
true|false.
Использование
meta_is_product_attribute( $name, $value, $product_id );
- $name(строка) (обязательный)
- of the attribute.
- $value(строка) (обязательный)
- of the attribute.
- $product_id(int) (обязательный)
- to check for attribute.
Код meta_is_product_attribute() meta is product attribute WC 10.8.1
function meta_is_product_attribute( $name, $value, $product_id ) {
$product = wc_get_product( $product_id );
if ( $product && method_exists( $product, 'get_variation_attributes' ) ) {
$variation_attributes = $product->get_variation_attributes();
$attributes = $product->get_attributes();
return (
in_array( $name, array_keys( $attributes ), true ) &&
isset( $variation_attributes[ $attributes[ $name ]['name'] ] ) &&
in_array( $value, $variation_attributes[ $attributes[ $name ]['name'] ], true )
);
} else {
return false;
}
}