WC_REST_Products_V2_Controller::get_attribute_taxonomy_name
Get product attribute taxonomy name.
Method of the class: WC_REST_Products_V2_Controller{}
No Hooks.
Returns
String.
Usage
// protected - for code of main (parent) or child class $result = $this->get_attribute_taxonomy_name( $slug, $product );
- $slug(string) (required)
- Taxonomy name.
- $product(WC_Product) (required)
- Product data.
Changelog
| Since 3.0.0 | Introduced. |
WC_REST_Products_V2_Controller::get_attribute_taxonomy_name() WC REST Products V2 Controller::get attribute taxonomy name code WC 10.3.6
protected function get_attribute_taxonomy_name( $slug, $product ) {
// Format slug so it matches attributes of the product.
$slug = wc_attribute_taxonomy_slug( $slug );
$attributes = array_combine(
array_map( 'wc_sanitize_taxonomy_name', array_keys( $product->get_attributes() ) ),
array_values( $product->get_attributes() )
);
$attribute = false;
// pa_ attributes.
if ( isset( $attributes[ wc_attribute_taxonomy_name( $slug ) ] ) ) {
$attribute = $attributes[ wc_attribute_taxonomy_name( $slug ) ];
} elseif ( isset( $attributes[ $slug ] ) ) {
$attribute = $attributes[ $slug ];
}
if ( ! $attribute ) {
return $slug;
}
// Taxonomy attribute name.
if ( $attribute->is_taxonomy() ) {
$taxonomy = $attribute->get_taxonomy_object();
return $taxonomy->attribute_label;
}
// Custom product attribute name.
return $attribute->get_name();
}