Automattic\WooCommerce\Internal\ProductAttributesLookup

LookupDataStore::get_variation_definition_term_id()privateWC 1.0

Get the id of the term that defines a variation for a given taxonomy, or null if there's no such defining id (for variations having "Any <taxonomy>" as the definition)

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

Хуков нет.

Возвращает

int|null. The term id, or null if there's no defining id for that taxonomy in that variation.

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

// private - только в коде основоного (родительского) класса
$result = $this->get_variation_definition_term_id( $variation, $taxonomy, $term_ids_by_slug_cache );
$variation(\WC_Product_Variation) (обязательный)
The variation to get the defining term id for.
$taxonomy(строка) (обязательный)
The taxonomy to get the defining term id for.
$term_ids_by_slug_cache(массив) (обязательный)
A term ids by slug as generated by get_term_ids_by_slug_cache.

Код LookupDataStore::get_variation_definition_term_id() WC 8.7.0

private function get_variation_definition_term_id( \WC_Product_Variation $variation, string $taxonomy, array $term_ids_by_slug_cache ) {
	$variation_attributes = $variation->get_attributes();
	$term_slug            = ArrayUtil::get_value_or_default( $variation_attributes, $taxonomy );
	if ( $term_slug ) {
		return $term_ids_by_slug_cache[ $taxonomy ][ $term_slug ];
	} else {
		return null;
	}
}