WC_Product_Variation::get_attribute()publicWC 1.0

Returns a single product attribute as a string.

Метод класса: WC_Product_Variation{}

Хуков нет.

Возвращает

Строку.

Использование

$WC_Product_Variation = new WC_Product_Variation();
$WC_Product_Variation->get_attribute( $attribute );
$attribute(строка) (обязательный)
to get.

Код WC_Product_Variation::get_attribute() WC 8.7.0

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 '';
}