woocommerce shortcodes

WooCommerce Shortcodes in WordPress

Used before category names. Blog WordPress

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.

woocommerce shortcodes

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_cart Display shopping cart
  • woocommerce_checkout Display the checkout page
  • woocommerce_my_account Show customer account
  • woocommerce_order_tracking Display order tracking form

Most of the time these pages are created by WooCommerce itself during installation.

Products shortcodes

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.
    • date
    • id
    • menu_order
    • popularity
    • rand
    • rating
    • title
  • 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
    • AND
    • IN
    • terms_operator
    • NOT IN
  • tag_operator: operator to compare tags
    • AND
    • IN
    • tag_operator
    • NOT IN
  • visibility: display of products based on display capability
    • visible
    • catalog
    • search
    • hidden
    • featured
  • cat_operator: to compare categorization operators
    • AND
    • IN
    • cat_operator
    • 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" ]

special products

[products limit="4" columns="2" visibility="featured" ]
woocommerce shortcodes

The best-selling products

[products limit="3" columns="3" best_selling="true" ]

Latest Products

[products limit="4" columns="4" orderby="id" order="DESC" visibility="visible"]
woocommerce shortcodes

Special categories

[products limit="8" columns="4" category="hoodies, tshirts" cat_operator="AND"]
[products limit="8" columns="4" category="hoodies, tshirts" cat_operator="NOT IN"]

Attribute display

[products columns="3" attribute="season" terms="warm" orderby="date"]
woocommerce shortcodes
[products columns="3" attribute="season" terms="warm" terms_operator="NOT IN"]

Show only products with the tag “hoodie”

[products tag="hoodie"]

Shortcodes for product categories in WooCommerce

These two shortcodes in WooCommerce will display your product categories on every page.

  • product_category Displays the products of a specific product category.
  • product_categories Displays 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"]
woocommerce shortcodes

Product page

[product_page id="99"]

or

[product_page sku="FOO"]

Related products

array(
     'limit' => '12',
     'columns' => '4',
     'orderby' => 'title'
 )
[related_products limit="12"]

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 id="99"]

Add to cart link

array(
      'id' => '99',
      'sku' => 'FOO'
 )
[add_to_cart_url id="99"]

You may like