WC_REST_Products_V2_Controller::get_attribute_taxonomy_name()protectedWC 3.0.0

Get product attribute taxonomy name.

Метод класса: WC_REST_Products_V2_Controller{}

Хуков нет.

Возвращает

Строку.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_attribute_taxonomy_name( $slug, $product );
$slug(строка) (обязательный)
Taxonomy name.
$product(WC_Product) (обязательный)
Product data.

Список изменений

С версии 3.0.0 Введена.

Код WC_REST_Products_V2_Controller::get_attribute_taxonomy_name() WC 8.7.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();
}