meta_is_product_attribute

Returns true when the passed meta name is a product attribute.

Description

meta_is_product_attribute( (string) $name, (string) $value, (int) $product_id ); 

Parameters (3)

0. $name (string)
Of the attribute
1. $value (string)
The value.
2. $product_id (int)
The product id.

Usage

  1. if ( !function_exists( 'meta_is_product_attribute' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-conditional-functions.php'; 
  3.  
  4. // of the attribute 
  5. $name = ''; 
  6.  
  7. // The value. 
  8. $value = ''; 
  9.  
  10. // The product id. 
  11. $product_id = -1; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = meta_is_product_attribute($name, $value, $product_id); 
  15.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-conditional-functions.php  
  1. function meta_is_product_attribute( $name, $value, $product_id ) { 
  2. $product = wc_get_product( $product_id ); 
  3.  
  4. if ( $product && method_exists( $product, 'get_variation_attributes' ) ) { 
  5. $variation_attributes = $product->get_variation_attributes(); 
  6. $attributes = $product->get_attributes(); 
  7. return ( in_array( $name, array_keys( $attributes ) ) && in_array( $value, $variation_attributes[ $attributes[ $name ]['name'] ] ) ); 
  8. } else { 
  9. return false;