The WooCommerce plugin has several shortcodes that the list can be used to insert content into WordPress posts and pages.
How to use WooCommerce shortcodes
WooCommerce shortcodes can be used in WordPress pages and posts. If you’re using the block editor, there’s a shortcode block that you can use to insert shortcodes into the page.
If you use the classic editor, you can copy the WooCommerce shortcode into the page or post.
Shortcodes for WooCommerce pages
To use WooCommerce, you must use three shortcodes, otherwise, WooCommerce will not work properly.
woocommerce_cartDisplay shopping cart
woocommerce_checkoutDisplay the checkout page
woocommerce_my_accountShow customer account
woocommerce_order_trackingDisplay order tracking form
Most of the time these pages are created by WooCommerce itself during installation.
The “products” shortcode is one of the most used WooCommerce shortcodes that can replace various other strings used in previous versions of WooCommerce.
This shortcode allows you to display products by ID, SKU, categories, and attributes, with support for pagination, random sorting, and product tags, instead of requiring multiple shortcodes. such as “featured_products”, “sale_products”, “best_selling_products”, “recent_products”, “product_attribute”, and “top_rated_products”
Available attributes in the shortcode of the products
- limit: number of products to display. By default, it is -1 (show all). It is used both in displaying products and in displaying categories.
- columns: number of columns to display. The default is 4.
- paginate: Show or not show pagination for products. It is used together with the limit. It is false by default, which is set to true for pagination.
- orderby: Sorts the products based on the entered option. Multiple entries can be entered with spaces to sort by all entered options.
- SKU: Display based on product SKU ID
- category: display products based on category ID (slug)
- tag: display products based on tag ID (slug)
- order: determines the display order of the products, whether they are ascending (ASC) or descending (DESC).
- class: Add HTML class
- on_sale: Used to display products that have a discount.
- best_selling: Used to display products that have sold the most.
- top_rated: Used to display products that have the highest rating.
- attribute: display products based on attribute ID (slug)
- terms: displaying products based on attribute expressions along with attribute
- terms_operator: to apply operators on terms expressions
- NOT IN
- tag_operator: operator to compare tags
- NOT IN
- visibility: display of products based on display capability
- cat_operator: to compare categorization operators
- NOT IN
- ids: Display products based on id
- SKUs: display products by SKU id
Examples of WooCommerce shortcodes for products list
Showing four random discounted products
[products limit="4" columns="4" orderby="popularity" class="quick-sale" on_sale="true" ]
[products limit="4" columns="2" visibility="featured" ]
The best-selling products
[products limit="3" columns="3" best_selling="true" ]
[products limit="4" columns="4" orderby="id" order="DESC" visibility="visible"]
[products limit="8" columns="4" category="hoodies, tshirts" cat_operator="AND"]
[products limit="8" columns="4" category="hoodies, tshirts" cat_operator="NOT IN"]
[products columns="3" attribute="season" terms="warm" orderby="date"]
[products columns="3" attribute="season" terms="warm" terms_operator="NOT IN"]
Show only products with the tag “hoodie”
Shortcodes for product categories in WooCommerce
These two shortcodes in WooCommerce will display your product categories on every page.
product_categoryDisplays the products of a specific product category.
product_categoriesDisplays all your product categories.
By adding the following features to the above two options, you can display products by category.
- id: Specify the specific category IDs to display. For use in “product_categories”
- category: can be category id, category name, and category slug id used in “product_category”.
- limit: the number of categories that can be displayed
- columns: the number of columns that can be displayed. Default 4
- hide_empty: default is “1” which hides empty categories. Set to “0” to display empty categories
- parent: Set to a specific category ID if you want all child categories to be displayed. Alternatively, set it to “0” to show only top-level categories.
- orderby: defaults to “name” but can be set to “id”, “slug” or “menu_order”. If you want to sort by the IDs you specified, you can use orderby = “include”.
- order: Specifies whether the sorting is ascending (ASC) or descending (DESC), which is the default ascending.
Examples of WooCommerce shortcodes for categories
Only show top-level categories
[product_categories number="0" parent="0"]
[product_page id="99"] or [product_page sku="FOO"]
array( 'limit' => '12', 'columns' => '4', 'orderby' => 'title' )
Add to cart
array( 'id' => '99', 'style' => 'border:4px solid #ccc; padding: 12px;', 'sku' => 'FOO' 'show_price' => 'TRUE' 'class' => 'CSS-CLASS' 'quantity' => '1'; )
Add to cart link
array( 'id' => '99', 'sku' => 'FOO' )