0

How would I create a shortcode to show the parent taxonomy in woocommerce?

My product categories should be like:

- Food

-- Fruits

--- Healthy Fruits
--- Organic Fruits

-- Meat

--- Pork
--- Lamb
--- Beef

For example, I would like to display the taxonomy name "Fruits" in somewhere when user at the "Healthy Fruits" product archive page.

  • do you mean automatically add the shortcode? – gael May 22 at 7:34
  • no gael, I want to manually type the shortcode on "Healthy Fruits" product archive page – Needa Hell May 22 at 8:15
0

The Shortcode to display products in "Fruits" category when user is on another page or archive... is:

[products category="fruits"]

As far as I know there is no shortcode to display the parent category products without specifying the given category slug.

For your 2nd example you will have to call it in your sub category "Pork"

[products category="meat"]

and so on for each category.

You can find WooCommerce shortcodes here:

https://docs.woocommerce.com/document/woocommerce-shortcodes/

| improve this answer | |
  • Thanks gael, this is just my example. In fact I want it to show the parent category but not just hard code it. – Needa Hell May 22 at 10:13
  • For example, I would like to display "Fruits" when user at the "Healthy Fruits" product archive page. To display "Meat" when user at the "Pork" product archive. – Needa Hell May 22 at 10:14
  • Thanks gael, but hardcode is not preferred since there will be tons of categories. Therefore, I would like to know how to make a custom shortcode to my question. – Needa Hell May 22 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.