WC_Product::get_attribute()
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() 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() ); }