WC_API_Products::get_attributes() private WC 2.1
Get the attributes for a product or product variation
{} It's a method of the class: WC_API_Products{}
No Hooks.
Return
Array.
Usage
// private - for code of main (parent) class only $result = $this->get_attributes( $product );
$product *(WC_Product | WC_Product_Variation) (required)* |
---|
Changelog
Since 2.1 | Introduced. |
Code of WC_API_Products::get_attributes() WC API Products::get attributes WC 5.0.0
private function get_attributes( $product ) {
$attributes = array();
if ( $product->is_type( 'variation' ) ) {
// variation attributes
foreach ( $product->get_variation_attributes() as $attribute_name => $attribute ) {
// taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_`
$attributes[] = array(
'name' => ucwords( str_replace( 'attribute_', '', wc_attribute_taxonomy_slug( $attribute_name ) ) ),
'option' => $attribute,
);
}
} else {
foreach ( $product->get_attributes() as $attribute ) {
$attributes[] = array(
'name' => ucwords( wc_attribute_taxonomy_slug( $attribute['name'] ) ),
'position' => $attribute['position'],
'visible' => (bool) $attribute['is_visible'],
'variation' => (bool) $attribute['is_variation'],
'options' => $this->get_attribute_options( $product->get_id(), $attribute ),
);
}
}
return $attributes;
}