{"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