What are shortcodes? You’ve probably heard the term before, but likely assumed it was just a technical concept that the average WordPress user doesn’t need to understand.
Or, maybe you’ve used a shortcode or two before, but didn’t quite grasp exactly how they worked at a deeper level.
Either way, if you want to unlock the full potential of WooCommerce, you’ll definitely want to familiarize yourself with shortcodes.
Why? Because they power much of the plugin’s functionality, including all of the public-facing pages like Checkout, Cart, and Product Categories.
Most importantly, knowing how to use WooCommerce shortcodes allows you to create highly-customized sales pages, and an incredible sales funnel to build a powerful eCommerce site for any situation.
In this post, you’ll learn the following:
- What a shortcode is
- Why you should use WooCommerce shortcodes
- How you can use them
Let’s get started!
- How To Insert Shortcodes
- List of All WooCommerce Shortcodes
- Other Useful WooCommerce Shortcodes
- Troubleshooting Shortcodes
Put simply, shortcodes are tiny pieces of code that perform specific actions on your site.
When you place this code on a WordPress page, post, or widget area, something happens. What exactly happens depends on the shortcode. Some will load post content, while others will display a contact form. There are hundreds of different use cases.
Shortcodes are a WordPress-wide feature and so they all have the same format. The structure is simple: a short piece of text is placed in between two brackets, like this:
Many different plugins and themes use shortcodes. As such, the shortcode will often be prefaced with the name of the plugin itself to differentiate it from others, like this:
However, this is not always the case. It depends on the particular plugin.
WooCommerce shortcodes are shortcodes designed for the WooCommerce plugin. There are dozens of shortcodes in WooCommerce and they are used to display most pages, so it’s important to understand how they work.
When you first install WooCommerce and go through the setup wizard, a number of pages are automatically created. If you go to edit one of these pages, you’ll notice that they contain a shortcode.
When the page is loaded, the shortcode loads the relevant content. For example, the [woocommerce_cart] shortcode will load the WooCommerce cart page.
Shortcodes are used to display the following WooCommerce pages:
- My Account
- Order Tracking
Shortcodes are an easy way to customize your WooCommerce shop. By pasting a shortcode (and modifying some minor parameters), you can easily create any type of eCommerce site you like.
You can choose which products are displayed, how they’re ordered, and how many are shown per page. Plus, you can add Add to Cart buttons in opportune places, like at the end of your posts.
You also don’t need to know how to code. You only need to copy and paste a line or text or two. Pretty easy, right?
Now that you know what a shortcode is, let’s talk about adding them to your site.
With the Gutenberg editor, adding shortcodes is easy. Just press the plus sign to add a new block, type shortcode in the search bar, and select the Shortcode block.
Save the page and view it. You’ll now see the results of your shortcode.
Simply add the shortcode, like above, making sure to include the brackets ([ and ]).
While they look simple, shortcodes are actually quite powerful! Let’s cover the different parts that make up a shortcode.
Shortcodes are a single word or set of words connected with underscores, like this:
While some shortcodes will function alone, others require some parameters.
Parameters, or arguments (called args in some of WooCommerce’s documentation), are extra lines that make the action of the shortcode more specific. Most, but not all, WooCommerce shortcodes use parameters.
For example, if you add on_sale=”true” to the [products s] shortcode, the only products displayed will be the ones on sale.
Now let’s go through some of the most useful WooCommerce shortcodes.
This shortcode adds the WooCommerce cart functionality to the page. In other words, it will display all of the products that the user has added to their cart. There are no parameters to add to this shortcode.
This shortcode displays the checkout page. Since it’s a critical aspect of your business, make sure that the page is set up correctly. After all, if a customer can’t find the checkout, they can’t buy anything. Additionally, with the flexibility of modern e-commerce platforms like WooCommerce, you now have the opportunity to customize your checkout page to align with your brand identity and enhance the user experience.
As above with [woocommerce_cart], there are no extra parameters for the checkout page.
This one shows the My Account page, which contains all of the customer’s information, as well as their previous orders from your shop.
By default, the number of orders displayed is set to 15. You can change it to display all orders by making the number -1.
This shortcode creates a “order tracking” page, which allows customers to see the current status of their orders. There are no other parameters.
The [products] shortcode is one of the most powerful and widely used shortcodes in WooCommerce. As you probably guessed, it displays your products. There are a ton of parameters which allow you to customize the types and quantities of products displayed.
To add a parameter, simply write its name, followed by the equals sign and the desired value inside of quotation marks. Make sure this is inside of the [products s] shortcode.
For example, to display 3 products from the shoes category, use this shortcode:
[products limit=”3” category=”shoes”]
To make it easier to understand, we’ve included a sample product shortcode with the parameter included below each one.
The limit parameter controls the number of products displayed. By default, it will be -1, which displays all products.
The category parameter will display products that have a certain category slug. You can add more than one category by placing a comma in between them.
[products category=”shoes, hats”]
There are a few parameters that help you control the layout of your product pages.
This parameter controls the number of columns. By default, it is set to 4, although this will usually collapse into a smaller number on mobile (depending on your theme.)
This parameter will determine if your product result pages will be paginated. It only has two options: true or false. By default, it is set to false.
You will probably want to use the paginate parameter in conjunction with the limit parameter we mentioned above. Thus, the limit parameter will determine how many items are listed on each page.
This parameter has a number of options that allow you to customize how your products are ordered. By default, they will be ordered by the product’s title.
You’ll can add more than one option by separating them with a single space.
- date: This orders products by the date of the publishing (new first)
- id: This setting will order products by their Post ID
- menu_order: This will order products by the menu order (lower numbers first)
- popularity: This will order the products by the number of purchases (most first)
- rand: This displays products in a random order. There might be issues with sites that use caching plugins.
- rating: This will order products by their average rating, from higher to lower.
Based on the above orderby setting, this determines if the order will be ascending (ASC) or descending (DESC). By default, it is ASC.
SKU stands for Stock Keeping Unit. It is a system designed to keep track of products across different marketplaces. While they aren’t required by WooCommerce, they are highly recommended, especially if you plan on selling your products wholesale. You can use this plugin to automatically generate SKUs for all of your products.
This parameter lets you add specific SKUs, which should be separated by commas.
[products skus=”tshirt-white-small, tshirt-white-medium”]
This lets you display products with a certain tag. You can add more than one tag by putting a comma in between them.
[products tag=”blue, summer”]
This adds an HTML wrapper class around the element, which allows you to modify it with CSS.
Want to display products that are marked as on sale? Use this parameter. The options are true or false. Be sure to not use it at the same time as best_selling or top_rated.
This will display the best-selling products. Options are true and false. Make sure not to use it at the same time as on_sale or top_rated.
The top_rated parameter will display the products that are the most highly-rated. The available options are true and false. Do not use it at the same time as on_sale or best_selling.
These shortcodes can be used to display products based on their attributes. Attributes are elements that are shared across multiple products. For example, size or color.
This will display products with a certain attribute.
This must be used with attribute above. It will display products with certain terms that are linked to the attribute. For example, the Attribute may be size and the Terms are small, medium, or large.
These allow you to perform simple calculations to determine which terms will be included. Likewise, they must be used with attribute and terms.
- AND: Will display products with all of the attributes listed
- IN: Will display the selected terms. This is the default.
- NOT IN: Will display items that aren’t in the selected terms (i.e. all of those other than the ones you select)
The same as the term operator above, except for tags.
- AND: Will display products with all of the tags listed
- IN: Will display items with the selected tags. This is the default
- NOT IN: Will display items that aren’t in the selected tags (i.e. all of those other than the ones you select)
This displays products depending on their visibility on your site.
- Visible: Displays products that are visible in searches and on your website. This is set by default
- Catalog: Displays products that are visible in the shop, but not in search results
- Search: Displays products that are visible in search results, but not on the shop
- Hidden: Displays products that are hidden from both search results and on the shop, but are only accessible via direct URL
- Featured: Displays products that are marked as featured
Cat stands for category. This allows you to perform simple calculations to determine which products will be included.
- AND: Displays products in all of the categories
- IN: Displays products in the selected category/categories
- NOT IN: Displays products that are not in the selected category
These two shortcodes allow you to display your product categories. As with products themselves, there are a large number customization options available.
Without any parameters, this shortcode will display all of your categories on a single page. If you want to add more than one category, you should also use this shortcode.
This is the generic shortcode for displaying a particular category. You’ll need to add a specific parameter, listed below, in order to actually display one (or more.)
Now let’s go through the parameters available for the product category shortcodes.
Display specific categories by their ids.
[products _categories ids=”1,2”]
This determines the number of categories that will be displayed.
[products _categories limit=”5”]
This parameter determines the number of columns. By default, it is set to 4.
[products _categories limit=”5”]
This will hide empty categories. There are two options: “1” and “0”. “1” will hide empty categories, while “0” will show them. By default, it is set to “1.”
[products _categories hide_empty=”1”]
This parameter will show the child categories of a specific parent category, which is targeted by id. For example, [parent=”3”] will display the child categories of the category whose id is 3.
If you set parent to “0”, only the top-level categories will be displayed.
[products _categories parent=”0”]
This controls the order in which categories are displayed. By default, it will order them by name, but you can also change it to id, slug, or menu_order.
[products _categories orderby=”id”]
Related to orderby, this parameter will either make ordering ascending (ASC) or descending (DESC.) By default, it is set to “ASC.”
[products _categories order=”ASC”]
Now let’s take a look at some other useful shortcodes!
This shortcode lets you easily create an Add to Cart button for a specific product, which is targeted by id. There are quite a few parameters. As with other shortcodes, each should be placed within two quotation marks, “like this”.
- id: Choose the product by ID
- style: Customize the CSS of the button directly
- sku: Choose the product by SKU
- show_price: Choose whether the price is displayed with the button. There are two options, “TRUE” and “FALSE”
- class: Assign an HTML class to the button, so that you can target it with CSS code
- quantity: Choose the product amount that will be added to the cart. In most cases, this will just be “1”
[add_to_cart id=”34” style=”border: 1px solid #111111;” show_price=”TRUE” quantity=”1” class=”example-cart-button”]
This shortcode will display the actual URL of a particular product. There are only two parameters:
- id: Target the product by ID
- sku: Target the product by SKU
Want to display WooCommerce messages on non-WooCommerce pages? This shortcode will allow you to display notifications like “This product has been added to your cart” on any page with it.
WooCommerce also offers a way to display available coupons on any page. However, you’ll need to purchase their Smart Coupons add-on, which you can read more about here.
In the final section, let’s briefly cover some common issues that prevent shortcodes from working.
When adding a shortcode to a page, make sure that it is not between <pre> tags, which are designed to display (and not execute) code.
Another common error is if the quotation marks (used with parameters) are angled, or “curly” (like this: “) and not straight (like this: “). Parameters won’t work with curly quotation marks.
As you probably notice, there are a lot of shortcodes in WooCommerce! Hopefully this guide has been a useful resource for you in all of your eCommerce endeavors.
Although it may seem a little technical, the power and flexibility of shortcodes allows you to create virtually any type of eCommerce page that you can dream of.
If you’re using WooCommerce, have you utilized shortcodes? If so, in what way? And if not, is it because you find the process confusing? Let us know in the comments!
Disclosure: This blog may contain affiliate links. If you make a purchase through one of these links, we may receive a small commission. Read disclosure. Rest assured that we only recommend products that we have personally used and believe will add value to our readers. Thanks for your support!