This blog simply lists down the WooCommerce categories shortcodes for products.
These shortcodes can be useful for displaying a list of product categories on a page or post. This can be helpful for providing an overview of the product categories available on your website, making it easier for customers to navigate to the products they are interested in.
Using the shortcodes can also save you time and effort by automatically generating the list of categories, rather than manually creating a list yourself. It’s also flexible and customizable, allowing you to specify which categories to display and how they should be ordered.
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:
[product_category]– displays products in a specified product category.
[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 books category, use this shortcode: [products limit="3" category="books"].
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 the 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 the 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 the 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 users and exclude the sub-categories.
So the shortcode will be [product_categories number="0" parent="0"].
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
In summary, using the WooCommerce categories shortcodes can improve the user experience on your website by making it easier for customers to find the products they are interested in, and it can save you time and effort by automating the process of creating a list of categories.