Automattic\WooCommerce\Internal\ProductAttributesLookup
LookupDataStore::get_attribute_taxonomies
Return the list of taxonomies used for variations on a product together with the associated term ids, with the following format:
[ 'taxonomy_name' => ['term_ids' => [id, id, ...], 'used_for_variations' => true|false
], ... ]
Method of the class: LookupDataStore{}
No Hooks.
Returns
Array. Information about the attribute taxonomies of the product.
Usage
// private - for code of main (parent) class only $result = $this->get_attribute_taxonomies( $product );
- $product(WC_Product) (required)
- The product to get the attribute taxonomies for.
LookupDataStore::get_attribute_taxonomies() LookupDataStore::get attribute taxonomies code WC 10.3.3
private function get_attribute_taxonomies( \WC_Product $product ) {
$product_attributes = $product->get_attributes();
$result = array();
foreach ( $product_attributes as $taxonomy_name => $attribute_data ) {
if ( ! $attribute_data->get_id() ) {
// Custom product attribute, not suitable for attribute-based filtering.
continue;
}
$result[ $taxonomy_name ] = array(
'term_ids' => $attribute_data->get_options(),
'used_for_variations' => $attribute_data->get_variation(),
);
}
return $result;
}