This seems like it should be easy to do but I haven’t been able to, and cannot find any posts regarding it.
I can display all the categories associated with a product, or the top category, but how do you echo only the lowest / deepest category for a product?
Cat-A [x]
Cat-B [x]
Cat-C [x]
Cat-D [ ]
Cat-E [ ]
Cat-F [ ]
Cat-G [ ]
Cat-H [ ]
If this example is the product’s ancestry, all I want to print is “Cat-C”.
But I don’t want to manually set the category level like other solutions, I want it to always print the lowest child, be the product on the archive page, or single product page.
Any idea of how this can / should be done?
Try something like:
I finally found the anwser at https://wordpress.stackexchange.com/a/55921/59863 I added the proper taxonomy for woocommerce, and a foreach / echo at the bottom to spit out the name.
The only downside to this code is that if a product only has 1 category with a parent value of 0 it will break. I don’t need this functionality at the moment, but I am going to come back and fix this with a “if null do this instead”.