WC_Product_Variation::get_attribute( string $attribute )
Returns a single product attribute as a string.
Description Description
Parameters Parameters
- $attribute
-
(Required) to get.
Return Return
(string)
Source Source
File: includes/class-wc-product-variation.php
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 '';
}