WordPress at Your Fingertips
function is not described

WC_REST_Products_V2_Controller::get_attribute_taxonomy_name() protected WC 3.0.0

Get product attribute taxonomy name.

{} It's a method of the class: WC_REST_Products_V2_Controller{}

No Hooks.

Return

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.

Code of WC_REST_Products_V2_Controller::get_attribute_taxonomy_name() WC 5.9.0

protected function get_attribute_taxonomy_name( $slug, $product ) {
	// Format slug so it matches attributes of the product.
	$slug       = wc_attribute_taxonomy_slug( $slug );
	$attributes = $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();
}