WooCommerce: Product Category Counter Shortcode

In WooCommerce, product category counters are the small numbers you see next to category names. These numbers indicate the total number of products within that specific category. They typically appear on shop and archive pages where product categories are listed.

In the past, we’ve seen how to remove the WooCommerce product category counters from the shop page.

Today, we’re looking at a way to add them on the product category page, wherever you wish – in the title, inside the description, in a second description, in a custom block. All you need is a simple shortcode. Enjoy!

Continue reading WooCommerce: Product Category Counter Shortcode

WooCommerce: Conditionally Display Content to Customers [Shortcode]

Today’s customization will feature a custom shortcode that you can use to display content only to logged in customers: [customers-only]content for customers here e.g. video iframe[/customers-only]

This is perfect for membership sites, LMS platforms, paywalled content.

In my case, only premium Club members with a ‘CLASS’ pass can watch upcoming WooCommerce masterclasses and past recordings, so I needed the shortcode to hide the video to logged out users or logged in customers without a pass.

By wrapping the video iframe HTML inside the shortcode, I can show the video to logged in customers who purchased a given product ID, or alternatively show an error message, which you can see in action here, in the “The recording is now available!” section: https://www.businessbloomer.com/class/behind-the-scenes-how-i-run-business-bloomer/

So, how did I do it? Find out below, and hope you can use it too!

Continue reading WooCommerce: Conditionally Display Content to Customers [Shortcode]

WooCommerce: Product Title Shortcode

WordPress shortcodes allow you to save time. For example, on my WooCommerce product pages I found myself typing the product title at least three times: in the product name input field, ok, but also again in the product long description and in a custom product tab inside a text link.

So, while finding ways to save time and reduce errors and typos, I coded the shortcode below so that I could avoid writing the title 3 times (and they’re very long!).

How does it work? Simply use [post_title] in a WooCommerce product, WordPress page, WordPress post or custom post and this will magically turn into the current post title. Simple!

Continue reading WooCommerce: Product Title Shortcode

WooCommerce: Product Description in a Shortcode!

It may be helpful to show the long product description of a given product in a custom WordPress page or post, so that you can use it as a teaser or anyway as a way to save some time instead of rewriting the whole thing.

The solution is easy: let’s code a simple shortcode that accepts a product ID as a shortcode attribute, and that returns its long description, properly formatted.

You can see this in action on this same website. Here’s one of my downloadable products’ long description: https://www.businessbloomer.com/shop/plugins/woocommerce-disable-payments-by-category/#tab-description – and here’s the same exact description printed in a blog post, thanks to the shortcode snippet you find below: https://www.businessbloomer.com/woocommerce-disable-payment-method-for-specific-category/#mini-plugin-business-bloomer-woocommerce-toggle-payments-by-category

Enjoy!

Continue reading WooCommerce: Product Description in a Shortcode!

WooCommerce: Display Product Grid @ Order Emails e.g. Related Products

Bad news first – we’ve seen how to add content to any WooCommerce order email, however I did not specify that if you use the [products] shortcode that’s not going to work unfortunately. The reason behind this, in plain English, is that… it just doesn’t work, and it outputs a weird list of “Sale!” list items (see screenshot below)!

So, I want to fix this, and find a WooCommerce email-compatible way to show a grid of products based on a list of product IDs (for example, the list of related products based on the ordered items), and make sure I can actually see product images, titles, prices and a link. Enjoy!

Continue reading WooCommerce: Display Product Grid @ Order Emails e.g. Related Products

WooCommerce: Products Attributes in a Shortcode

Products attributes display on the single product page whenever attribute terms are assigned to a given WooCommerce product. This is the default behaviour.

However, what if you want to show the product attribute table somewhere else? For example, in a blog post, or in a custom pricing table?

Well, we can build a shortcode for that – simply specify a product ID and the shortcode will magically output its attributes. Enjoy!

Continue reading WooCommerce: Products Attributes in a Shortcode

WooCommerce: Display All Single Variations (Shortcode)

By default, the WooCommerce Shop page displays simple, variable, grouped, bundle and other product types. As you know, each variable product is made of one or more “single variations”, and these are only visible in the single product page.

Now, what if you want to display a grid of all “single variations” in a custom page / post? Well, a shortcode can be coded so that you can achieve just that. Enjoy!

Continue reading WooCommerce: Display All Single Variations (Shortcode)

WooCommerce: Stock Quantity in a Shortcode

It’s great that WooCommerce products clearly display their stock status and quantity on the single product page (and on the shop page, with this simple customization).

However, WooCommerce store owners often need to display the stock quantity in other sections of the website, such as the homepage, a blog post, a custom pricing table, and keep the quantity dynamic so that the text changes when there is a stock change.

We can therefore build a simple shortcode, that can automatically update the output, so that you never need to worry about changing that piece of content ever again. Enjoy!

Continue reading WooCommerce: Stock Quantity in a Shortcode

WooCommerce: In Stock Products Shortcode

We’ve already coded a solution to display WooCommerce out of stock products only via a custom shortcode – today we’ll do the opposite: how can we display in stock products only via a handy shortcode?

Once again, the solution “gets” the list of products IDs that are in stock, and then passes the result to the official [products] WooCommerce shortcode, so that we don’t reinvent the wheel.

You can then use the [in_stock_products] shortcode anywhere you wish – on a blog post, in a custom page, in a widget, and so on. You can even customize the output with the official WooCommerce [products] shortcode parameters such as columns, orderby, limit, etc. Enjoy!

Continue reading WooCommerce: In Stock Products Shortcode

WooCommerce: Display Product Up-sells @ Thank You Page

One of the most important WooCommerce pages, conversion-wise, is the Thank You page. That’s your chance to offer something special to a user that has just turned into a customer and is therefore more likely to purchase again.

We’ve seen how to include a whole WordPress page inside the Thank You page, how to redirect customers to a different Thank You page URL, how to display a custom social media share box on the Thank You page, but in this article I want to expand a little more on the topic and show a list of purchasable products via a shortcode.

The thing is that the Thank You page “does not exist” inside the WordPress pages, so you can’t just add a shortcode in a page. We must do that via a PHP action hook and the do_shortcode() WordPress function. Enjoy!

Continue reading WooCommerce: Display Product Up-sells @ Thank You Page

WooCommerce: Display Product Reviews @ Custom Page (Shortcode)

WooCommerce product reviews shows by default in the “Reviews” tab in the single product page. But what if, like me, you’re using custom sales pages and need to show such reviews elsewhere – by using a shortcode?

I’ve spent some time doing this for two Business Bloomer pages, the contact page (beside the request a quote form) and the Business Bloomer Club sales page (just above the pricing table), so I thought it would have been great sharing the snippet with you. Enjoy!

Continue reading WooCommerce: Display Product Reviews @ Custom Page (Shortcode)

WooCommerce: Recently Viewed Products (Shortcode)

Currently, you can use a widget or a block to have the user see the list of products they recently viewed.

But for now, let’s create our own shortcode… and let’s take advantage of the existing [products] shortcode and learn how we can “pass” product IDs to it without the need of reinventing the wheel.

This snippet teaches you how to store data in a custom cookie, and also how to output a core shortcode… inside a custom shortcode. Enjoy!

Continue reading WooCommerce: Recently Viewed Products (Shortcode)

WooCommerce: Count User Purchases By Product ID (Shortcode)

If you’re developing custom landing pages or sections dedicated to logged in customers, knowing the quantity purchased of a certain product ID might come useful.

We already saw how to detect whether a logged in customer has purchased a given product, as well as a snippet to return all products purchased by a specific user – but this time I want to “count” how many times a current user has purchased a product ID, and return this on the screen via a shortcode.

From this snippet you can learn lots of things, for example how to create custom shortcodes, how to get customer orders, and how to set up a foreach loop in PHP. Either way, enjoy!

Continue reading WooCommerce: Count User Purchases By Product ID (Shortcode)

WooCommerce: How to Write Shortcodes Without Outputting Content?

When I write tutorials like WooCommerce Separate Login & Registration Pages I often need to “write” on the screen the actual shortcode – but I don’t want the shortcode to output content!

For example, if I write [woocommerce_my_account] it’s guaranteed you won’t see “[woocommerce_my_account]“… you will see Business Bloomer’s My Account page content instead!

So there is a great workaround for those of you who write tutorials, snippets and WordPress articles and need to print the actual shortcode on the screen, without making it “process” its content and outputting it.

Enjoy! Continue reading WooCommerce: How to Write Shortcodes Without Outputting Content?

WooCommerce: Display Out of Stock Products (Shortcode)

A client of mine wanted to show out of stock products on a separate page – so I coded a simple shortcode for you all!

You can use this shortcode for different goals. For example, you might want to display what products you’ve sold to enhance customer trust / social proof.

So let’s see (1) how to create a shortcode and (2) how to take advantage of the existing [products] WooCommerce shortcode and its “ids” parameter to pass just those product IDs that are out of stock!

Continue reading WooCommerce: Display Out of Stock Products (Shortcode)

WooCommerce: Exclude Category from ‘products’ Shortcode

The WooCommerce [products] shortcode displays all products in your shop. There is even an attribute called “category” where you can specify comma-separated list of category slugs in order to further filter the output.

What you can’t do is define a list of unwanted categories (think of “uncategorized” for example) i.e. a list of categories you want to exclude from the products shortcode output.

So, here’s the fix, enjoy!

Continue reading WooCommerce: Exclude Category from ‘products’ Shortcode

WooCommerce: Exclude Category from ‘product_categories’ Shortcode

Sometimes solutions are very simple, and you don’t need rocket science to fix your issue!

A client of mine needed to hide a category from the Product Categories Shortcode ([product_categories]); in fact, there is no parameter that allows you to “exclude” a given product category such as “uncategorized” or whatever category you wish.

A rare issue, but once again a quick fix! Here’s how you do it.

Continue reading WooCommerce: Exclude Category from ‘product_categories’ Shortcode