WC_Product_Variation::get_attribute
Returns a single product attribute as a string.
Method of the class: WC_Product_Variation{}
No Hooks.
Returns
String.
Usage
$WC_Product_Variation = new WC_Product_Variation(); $WC_Product_Variation->get_attribute( $attribute );
- $attribute(string) (required)
- to get.
WC_Product_Variation::get_attribute() WC Product Variation::get attribute code WC 10.3.6
public function get_attribute( $attribute ) {
$attributes = $this->get_attributes();
$attribute = sanitize_title( $attribute );
if ( isset( $attributes[ $attribute ] ) ) {
$value = $attributes[ $attribute ];
$term = taxonomy_exists( $attribute ) ? get_term_by( 'slug', $value, $attribute ) : false;
return ! is_wp_error( $term ) && $term ? $term->name : $value;
}
$att_str = 'pa_' . $attribute;
if ( isset( $attributes[ $att_str ] ) ) {
$value = $attributes[ $att_str ];
$term = taxonomy_exists( $att_str ) ? get_term_by( 'slug', $value, $att_str ) : false;
return ! is_wp_error( $term ) && $term ? $term->name : $value;
}
return '';
}