Get a fast, conversion-focused WooCommerce theme in 2020. Switch to Shoptimizer.

Home Blog – eCommerce News, tips and tutorials WooCommerce Shortcodes – Tutorial and lots of examples

WooCommerce Shortcodes – Tutorial and lots of examples

WooCommerce Shortcodes

WooCommerce shortcodes may not be familiar to everyone. Even if you have a WooCommerce store, it may be a feature you haven’t come across and don’t yet realise how useful they can be in sprinkling product references and buying call to action buttons throughout your site.

WooCommerce shortcodes are small code snippets which you can place anywhere in your site to display WooCommerce products or calls to action such as ‘Buy Now’ buttons. There are a multitude of uses for these and we wanted to incorporate some great examples directly within our Shoptimizer WooCommerce theme. They should also work within any theme with WooCommerce installed.

This is what we’ll be looking at in this tutorial so that you can quickly skip to an example.

  1. Using a WooCommerce shortcode to add products to the homepage
  2. Displaying your most popular products anywhere
  3. Creating a grid of items which are on sale
  4. How to display the WooCommerce category list shortcode
  5. How to include specific products within a blog post with a shortcode
  6. Adding just a single product to a blog post (includes custom CSS)
  7. Using the WooCommerce add to cart shortcode
  8. How to create an order tracking page with a WooCommerce shortcode
  9. What is the WooCommerce cart shortcode?

Let’s get started!


1. Using a WooCommerce shortcode to add products to the homepage

The first obvious place where WooCommerce shortcodes come in handy is on your homepage. This is an ideal space to display a dynamically updated grid of your latest products. Once the shortcode has been added, you don’t need to edit it again.

It will automatically display the most recent products, giving your homepage a fresh new feel each time you add new items to your store.

This is the WooCommerce shortcode we use on the Shoptimizer homepage to display recent additions:

To describe each attribute:

  • Limit – the number of products to display
  • Columns – the number of columns. This should be based on the number of products being displayed.
  • Orderby – you can arrange these by date, id, menu_order, popularity, rand, rating and title.
  • Order – this is either in descending order (DESC), or ascending (ASC).
  • Visibility – the products viewable within the shop and search results.

Result:

This WooCommerce shortcode results in a neat grid of 8 products, divided into 4 columns. If you want this is very each to change into a grid of say, 3. You could adjust the limit value to 6 and the columns value to 3 to keep it looking neat.

Using the latest products WooCommerce shortcode
Using the latest products WooCommerce shortcode

Just as you can show the most recent items, it is also possible to display your best selling products. This again is dynamically updated and is great to show seasonal popular gift ideas.

You can use the following WooCommerce shortcode for this:

Result:

Displaying the most popular products in your store
Displaying the most popular products in your store

3. Creating a grid of items which are on sale

Next up, we’re going to create a brand new page and call it ‘Men’s Sale Items’ – it’s going to list solely sale items with the Men category. This is what it looks like on our live theme demo. We want this page to automatically populate with every reduced price product item within the Men category in WooCommerce.

I’m using this WooCommerce shortcode to do so.

I don’t have so many products in this category, so setting the limit to be 100 is more than enough and covers any additional items added later. The key additional variables are the on_sale=”true” and the category=”men” which lists only sale items within the aforementioned category. Leaving out the specific category selector name will simply display all sale items amongst every category. This might be a better fit for your particular WooCommerce store.

Result:

Displaying Sale items
Displaying Sale items

4. How to display the WooCommerce category list shortcode

It’s also possible to not just display products via WooCommerce shortcodes. You can show categories too. If you want to create a page to list all of your product categories, it’s really easy. Just use this WooCommerce shortcode.

This will display all of your categories, and the result looks like the screenshot below, if like me, you’ve added a category thumbnail to each.

Result:

Result of using the WooCommerce category shortcode
Result of using the WooCommerce category shortcode

But what if you want to only show specific categories?

You can use a different shortcode to do this. It’s the same basic structure as the other shortcodes in WooCommerce. You list the category ids, separated by commas.

How to I know what ids my categories have?

You need to go to: Products > Categories > and Click into a category. You’ll see the ID in the url of your browser. For example tag_ID=95, so 95 is the ID of the category.

Finding the product category ID
Finding the product category ID

5. How to include specific products within a blog post with a shortcode

One aspect which is often overlooked is that WordPress is fundamentally a superb blogging platform. Many eCommerce stores make the mistake of not posting often enough or even not having a well defined content strategy in the first place. That’s not a conversation for this article but a quick and easy thing to do is add direct buying actions to products mentioned in a blog post.

If we take this article as an example – let’s say that it mentions three must-have jackets to buy this season. How would you go about adding these specific products to the article.

The first step is to find the unique ID of each product. You can do this by going to Products and hovering over the item in question.

Hover over a product to reveal the ID
Hover over a product to reveal the ID

You can see in the example above that this particular product’s ID is 677. Do the same for two more products and write down the IDs for each.

When thinking about a WooCommerce shortcode for this, we’ll simply create a new snippet based on the previous example but explicitly referencing these three product IDs.

You’ll see the three numbers are separated by commas. They’ll be displayed in the order you specify. I’m using columns=”3″ as there are three ids listed. If I were to show four items, I’d change this to columns=”4″.

It gets more tricky if wanted to display a larger number of items, if it was 9 for example, it may look best split into 3 rows of 3. That’s up to you.

Result:

Displaying specific products within a blog post
Displaying specific products within a blog post

6. Adding just a single product to a blog post (includes custom CSS)

If we want to add just a single product to a post, it’ll take up the entire width of the content – which would look a bit strange. I would like to float it to the right and let the text to flow around it.

Firstly, the WooCommerce shortcode, with just one product looks like this.

And now some custom CSS which you can add to: Appearance > Customize > Additional CSS. Note the presence of a media query, which means the style kicks in on viewports above 768px. So, on smaller screens, the product will be full width.

Result:

The result of this, looks like the screenshot below. You can also see it live on this post on the Shoptimizer demo site.

Adding a single product to a blog post - result of custom CSS
Adding a single product to a blog post – result of custom CSS

7. Using the WooCommerce add to cart shortcode

If you don’t want to display the entire product there is a way to just display the buy button. On the same post at the very bottom, you can see how it looks within the Shoptimizer WooCommerce theme.

The WooCommerce add to cart shortcode for this is simply:

You once again just swap in the ID for the product you want to display.

Result:

Displaying just the product call to action button
Displaying the WooCommerce add to cart shortcode within a blog post

In Shoptimizer, using this shortcode automatically picks up the button color set within the the customizer and adds a nice shadow. This helps lifts it off the page and provides definition compared to the other elements, making it stand out more.


8. How to create an order tracking page with a WooCommerce shortcode

One page which doesn’t get added by default in WooCommerce is the Order Tracking page. You’d need to create this yourself, by yes, using a WooCommerce Shortcode.

In Shoptimizer you can do this by creating a new page called Order Tracking, and adding a new shortcode block to the content. This is the shortcode to include:

You’d also change the Template dropdown on the right hand side to Full width. The result will look like this:

Order Tracking in WooCommerce
Order Tracking in WooCommerce

9. What is the WooCommerce cart shortcode?

When you install WooCommerce you get a couple of pages created for you automatically if you use their inbuilt wizard. These are the Cart, Checkout and My Account pages. You may be aware that these use WooCommerce shortcodes also. That’s all it takes to build these pages.

The WooCommerce cart shortcode is simply this:

Result:

This results in the cart page created for you.

WooCommerce cart shortcode result
WooCommerce cart shortcode result

Important: Make sure this has been set to be the Cart page within WooCommerce’s settings. WooCommerce > Settings > Advanced

Summary

We can see that WooCommerce shortcodes are extremely useful snippets of functionality which would benefit any store owner using this platform. So how are you using WooCommerce shortcodes? If you have any favourites include them in the comments below. Any questions are welcome also. If you’re looking for something specific, I’ll do my best to help.

About Simon: Designer, developer and pixel pusher until things are just right. Interested in modern, functional design with a focus on speed, clean typography and conversions. Enjoys whitespace and strong coffee.

Shoptimizer WooCommerce Theme

Shoptimizer is a FAST WooCommerce theme that comes with a ton of features all designed to help you convert more users to customers.

More details  →

Shoptimizer WooCommerce Theme screenshot

Latest eCommerce Guides View all Guides

Leave a Reply

Your email address will not be published. Required fields are marked *

Latest Updates

$50
Off

Do you want a whopping $50 off Shoptimizer for WooCommerce?

Click the button below to get Shoptimizer for only $49. (Regular price: $99).
This is a special launch offer for today only.
Get it before it is gone!
{"cart_token":"","hash":"","cart_data":""}