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)

Method of the class: LookupDataStore{}

No Hooks.


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


// private - for code of main (parent) class only
$result = $this->get_variation_definition_term_id( $variation, $taxonomy, $term_ids_by_slug_cache );
$variation(\WC_Product_Variation) (required)
The variation to get the defining term id for.
$taxonomy(string) (required)
The taxonomy to get the defining term id for.
$term_ids_by_slug_cache(array) (required)
A term ids by slug as generated by get_term_ids_by_slug_cache.

LookupDataStore::get_variation_definition_term_id() code WC 8.9.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;