Creating an A-Z loop of Product Attribute Terms
-
Hi,
We have attributes for our products, Ingredients.
We assign the attributes to a product and have set the ingredients to appear with image and URL, each ingredient has it’s own page, in WooCommerce terms, it is a “term” of an attribute, for example:
/our-ingredients/pineapple
/product_attribute/taxomony_termI’ve created a page under /our-ingredients/ and am looking to list ALL product attribute terms, but in A-Z order, so I can create 26 seperate loops, 1 loop for ingredients starting with A (like Apple) and one for B and so on…
An example of the kind of thing we’re trying to pull off: https://www.templespa.com/discover-templespa-ingredientsNote: That is not my site.
So far, I’m using this loop which displays an array, so it can understand the fact that it’s on the “/our-ingredients/” attribute, even though I’ve cheated a bit and created a new PAGE with the slug of “our-ingredients” ??
//product attributes $attribute_taxonomies = wc_get_attribute_taxonomies(); $taxonomy_terms = array(); //print_r($attribute_taxonomies); if ( $attribute_taxonomies ) : foreach ($attribute_taxonomies as $tax) : if (taxonomy_exists(wc_attribute_taxonomy_name($tax->attribute_name))) : $taxonomy_terms[$tax->attribute_name] = get_terms( wc_attribute_taxonomy_name($tax->attribute_name), 'orderby=name' ); endif; endforeach; endif; $product_attributes = array(); foreach ( $taxonomy_terms as $attribute ) { $j=0; foreach($attribute as $dfg){ //print_r($dfg->taxonomy); $product_attributes[$dfg->taxonomy][$j] = $dfg->name; $j++; } } print_r($product_attributes);
Appreciate the help in advance
Kind Regards
- The topic ‘Creating an A-Z loop of Product Attribute Terms’ is closed to new replies.