Posted on

WooCommerce Categories Shortcodes for Products

Learn about the WooCommerce product categories shortcodes and how to use them to display categories for your visitors on different pages and posts.

WooCommerce categories shortcode

Last updated on August 20, 2024

Shortcodes can be useful for displaying a list of product categories on a page or post. It also helps provide an overview of the product categories available on your website.

This makes it easier for visitors to navigate the desired products and make a purchase in a few minutes.

It’s also flexible and customizable as it allows you to specify which categories to display and how they should be ordered.

This blog simply lists down the WooCommerce categories shortcodes for products.

All the WooCommerce shortcodes

For an in-depth guide on all the shortcodes and how to use them using the Classic Editor and Block Editor, refer to our WooCommerce shortcodes blog.

You’ll find the WooCommerce cart shortcode, WooCommerce checkout shortcode, WooCommerce My account shortcode, WooCommerce products shortcode and other shortcodes in more detail.

Let’s look at the product categories’ shortcodes for now.

Two WooCommerce categories shortcodes

You can use these shortcodes to display your product categories on any page:

  1. [product_category] – displays products in a specified product category.
  2. [product_categories] – displays all your product categories. It’s a generic shortcode to display a particular category. You’ll need to add a specific parameter, in order to actually display one (or more).

One of the best things in WooCommerce is the [products] shortcode. It is robust and allows you to display products by categories, SKU, attributes, post ID with support for pagination, random sorting and product tags.

The [products] shortcode replaced the need for multiple shortcodes like [sale_products], [best_selling_products], [recent_products], [featured_products], [top_rated_products], and [product_attribute], used in WooCommerce versions below 3.2.

There are a ton of parameters that allow you to customize the types and quantities of products displayed.

To add a parameter, write its name, followed by the equals sign and the value inside quotation marks. Make sure that it is inside of the [products] shortcode.

For example, if you want to display three products from the Electronics category, use this shortcode: [products limit="3" category="electronics"].

Available product category attributes

You can use the following attributes in conjunction with the product categories’ shortcodes:

  • ids – This attribute displays specific categories by their ids. To be used in product_categories. For example – [products _categories ids="1,2"].
  • category – This can be either the category name, id, or slug. To be used in [product_category].
  • limit – This controls the number of categories that will be displayed. For example – [products _categories limit="5"].
  • columns – This attribute determines the number of columns that will be displayed. The default is 4.
  • hide_empty – Use this to hide empty categories. The default value “1” will hide empty categories. If you use “0”, it will show empty categories. For example – [products _categories hide_empty="1"].
  • parent – This will display child categories of a specific parent category, which is targeted by id. For example, [[parent=”2″]] will display the child categories of the category whose id is 2. If you set parent to “0”, then only the top-level categories will be displayed. Example – [products _categories parent="0"].
  • orderby – This attribute controls the display order of categories. The default is to order by “name”. It can be set to “id”, “slug”, or “menu_order”. If you want to display categories in order by ids you specified, then you can use orderby=”include”. For example – [products _categories orderby="id"].
  • order – states whether the category order is ascending (ASC) or descending (DESC), using the method set in orderby. The default is ASC. For example – [products _categories order="ASC"].

Example of product category scenarios

Let’s say you want to show only your top-level categories to your visitors and exclude the sub-categories.

So, the shortcode will be [product_categories number="0" parent="0"].

WooCommerce categories shortcodes

You can also use additional parameters to customize the output. Here are some examples:

  • [product_categories parent="0"] // Display top-level categories only
  • [product_categories number="3"] // Display 3 categories only
  • [product_categories orderby="name" order="desc"] // Order by name in descending order

Conclusion

In summary, WooCommerce categories shortcodes can improve the user experience on your website. It makes it easier for customers to find products they are interested in. It can also save you time and effort by automating the process of creating a list of categories.

Hope this article has answered all your questions. Comment below to let us know if you have any other queries related to this topic.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.