WC_Product::get_attribute()publicWC 1.0

Returns a single product attribute as a string.

Method of the class: WC_Product{}

No Hooks.

Return

String.

Usage

$WC_Product = new WC_Product();
$WC_Product->get_attribute( $attribute );
$attribute(string) (required)
to get.

WC_Product::get_attribute() code WC 9.7.1

public function get_attribute( $attribute ) {
	$attributes = $this->get_attributes();
	$attribute  = sanitize_title( $attribute );

	if ( isset( $attributes[ $attribute ] ) ) {
		$attribute_object = $attributes[ $attribute ];
	} elseif ( isset( $attributes[ 'pa_' . $attribute ] ) ) {
		$attribute_object = $attributes[ 'pa_' . $attribute ];
	} else {
		return '';
	}
	return $attribute_object->is_taxonomy() ? implode( ', ', wc_get_product_terms( $this->get_id(), $attribute_object->get_name(), array( 'fields' => 'names' ) ) ) : wc_implode_text_attributes( $attribute_object->get_options() );
}