WooCommerce Shortcodes

WooCommerce Shortcodes

Let’s look at the most commonly used and useful WooCommerce Shortcodes.

[recent_products] – displays the last added products

How many products need to be shown (default: 12).

How many columns to divide them (default: 4).

What parameter to sort by. For example, by default, it is sorted by date, and it is because of this that the shortcode displays the latest products.

Sort ascending ASC or descending DESC (default).

The parameter accepts labels of product categories, and if there are more than one of them, then you need to specify it with a comma. You can find product category labels in the admin area on the Products> Categories page.

For example, you indicated two categories of products in the previous parameter, let it be category1 and sportproducts, and now you need to decide whether you want the displayed products to be present in both AND categories, in one of the IN categories (by default), or not were present in the indicated categories NOT IN.

Usage example: [recent_products per_page=”4″ columns=”4″]
[featured_products] – to display featured products

The shortcode [featured_products] displays the products in exactly the same form as the previous [recent_products], and also has the same parameters. The only point is that the product should be marked as “recommended” in admin area. Using this shortcode, you can display any number of recommended products, as well as filter them by category.

[product] – when you need to display a specific product
You need to specify an additional parameter, for example, ID (you can see the product’s ID in the admin area in the list of all products)

Usage example: [product id = “12234”]
[products] – display of certain products by their ID or article number

You can specify separated by identifiers or product numbers

Usage example: [products ids = “423,500”] or [products skus = “product1, product2”]

This shortcode supports columns, orderby, and order parameters, as in the [recent_products] shortcode.

[product_category] – displays products from a specific category (or categories)

This is very similar to [recent_products], the only difference is that the order parameter accepts the default value of ASC, and the orderby parameter accepts the default menu_order title (sort first in order, and with the same order values – by title), and category – required parameter.

[product_categories] – lists links to product categories

Other shortcode options:

How many categories to display, default: all.

See the description of the parameter here.

Sort ascending ASC (default) or descending DESC.

How many columns to display, default: 4.

Do I need to hide those categories in which there are no products, do I need – 1 (by default), do not hide – 0.

Specify the ID of the parent category whose children you want to display. If you specify 0, then displays the category of the first level.

Here you can list the category IDs separated by commas.

[product_page] – essentially displays the entire product page

Displays a full product card with an image, button “add to cart”, etc

Usage example: [product_page id = “1573”]
[sale_products] – displays all products that are currently “on sale”

The shortcode has exactly the same parameters as [recent_products], by default, products are sorted alphabetically, and the display-template is also slightly different.

[best_selling_products] – products sorted by sales

The shortcode has the parameters per_page, columns, category and operator. Using the last two, you can display the best-selling products in any specific categories.

Sorting occurs on an arbitrary field total_sales.

[top_rated_products] – highest rated products

Here is a set of parameters, like the [recent_products] shortcode, but sorting is done by user rating.

[related_products] – displays related products for the current product in the loop – this means that we cannot use this shortcode on some random page – in this case, it simply will not output anything.

By default, 4 random items are displayed in 4 columns ([related_products per_page = “4” columns = “4” orderby = “rand”] If nothing is specified, then the shortcode will not output anything.

[product_attribute] – allows you to display all products with a specific value of an attribute

Available parameters: per_page, columns, category and operator

We also have two more parameters: attribute – the label of the attribute, and filter – the value of this attribute, and you can specify several values ​​separated by commas.

Usage example: [product_attribute attribute = “color” filter = “red, blue”]
(display products with a color attribute equal to “red” or “blue”).

More information and official documentation is available on the developer’s site