{"id":12,"date":"2018-09-18T15:35:37","date_gmt":"2018-09-18T07:35:37","guid":{"rendered":"https:\/\/www.intelliwolf.com\/?p=12"},"modified":"2018-09-18T19:00:11","modified_gmt":"2018-09-18T11:00:11","slug":"how-to-show-woocommerce-categories-on-product-pages","status":"publish","type":"post","link":"https:\/\/wordpress-757293-2559390.cloudwaysapps.com\/how-to-show-woocommerce-categories-on-product-pages\/","title":{"rendered":"How To Show WooCommerce Categories On Product Pages"},"content":{"rendered":"\n

I was recently working on building a little eCommerce store for a client and they wanted to have the categories show up on the product category pages. This design didn't have a sidebar, so the usual option was out. I had to dig into the WooCommerce template code to figure it out.<\/p>\n\n\n\n

So how do you show WooCommerce categories on the product pages? Write a function that hooks into\u00a0woocommerce_before_main_content and use a conditional like\u00a0is_product_category() to display the\u00a0product_categories shortcode<\/strong>.<\/p>\n\n\n\n

Here's how I did it. I put the following code into the functions.php for the child theme...<\/p>\n\n\n\n

\/*** WooCommerce Add Categories to Product List ***\/\nadd_action ('woocommerce_before_main_content', 'add_categories_to_product_list');\n\nfunction add_categories_to_product_list()\n{\n\tif (is_product_category()) {\n\t\techo do_shortcode('[product_categories]');\n\t}\n}<\/code><\/pre>\n\n\n\n
\"\"<\/figure><\/div>\n\n\n\n

This was built using WordPress 4.9.8 and WooCommerce 3.4.5, but will work for anything over WooCommerce 3.1. If you're reading this and still<\/em> using WooCommerce pre-3.1, go right now and update on a staging site, then roll it out to your live site. No really, stop reading and go do that now.<\/p>\n\n\n\n

What Parameters Are Available For Customising The product_categories shortcode?<\/h2>\n\n\n\n

The official documentation<\/a> is surprisingly unhelpful on this. You have a number of parameters available to customise the product_categories shortcode. They are:<\/p>\n\n\n\n