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: Get EU, EU VAT, EEA, SCA Countries

When you deal with conditional payment gateways, or conditional notifications, or conditional content, you may need to use to check the current billing country against an array of countries (in plain English, you may want to know if the customer is based in a specific World area), such as the European Union.

Thankfully, WooCommerce gives us a nice prebuilt function so that we don’t need to create the array of EU countries manually. On top of that, it’s easy to manipulate that array in order to add / remove countries for different uses, such as getting the list of EEA (European Economic Area) countries or SCA (Strong Customer Authentication) countries. In this post, I will give you some shortcuts to “calculate” these arrays, so that you don’t need to bother doing it.

Please note, EU, EEA and SCA countries are constantly changing, so these arrays are updated to the date you see on top of this post. Enjoy!

Continue reading WooCommerce: Get EU, EU VAT, EEA, SCA Countries

WooCommerce: Check If Product Is A Subscription

We’ve already found out how to check if a WooCommerce product is simple, variable, grouped… Today we add more conditional tags as we study which WooCommerce “product types” are included within the official WooCommerce Subscriptions extension.

There are two new product types in such case: “Simple Subscription” and “Variable Subscription”, with the difference being you can offer multiple billing periods within the same product page (choice between daily, monthly and yearly for example) with the latter.

So, how do we know if a given product ID is a subscription, and also whether it’s a simple or variable one? Here’s the quick solution – enjoy!

Continue reading WooCommerce: Check If Product Is A Subscription

WooCommerce: Check If Product Belongs to Category / Tag

We’ve studied “conditional logic” extensively over the previous Business Bloomer posts. In today’s spin-off, I want to clarify how you can check if a given product belongs to a category, tag or custom taxonomy because this is one of the most used conditional logic scenarios.

It’s important to know that a product can be inside the “loop” (e.g. the shop page or a list of products), alternatively you may be on the single product page or have the product unique ID, or even you can check if a product category is inside the Cart. Finally, you can even run the product category check within an Order or an Order Email.

Either way, the function is always the same. You simply need to understand how to use it. Enjoy!

Continue reading WooCommerce: Check If Product Belongs to Category / Tag

WooCommerce: Get Total Spent By Customer

Enabling WooCommerce functionalities only if a “user spent more than X” is not unusual. For example, you may want to display banners, special offers, discounted prices, conditional content to customers who have purchased more than a given dollar threshold.

While coding a function that could get the total spent by a user ID, I stumbled upon a WooCommerce function that already achieves that, out of the box: wc_get_customer_total_spent( $user_id ).

You can use it as a conditional tag and run a function only when such threshold is reached. So, let’s see how to use it. Enjoy!

Continue reading WooCommerce: Get Total Spent By Customer

WooCommerce: Conditionally Force Product Quantity 1 @ Cart

There are times when the WooCommerce product settings alone are not enough. You can already tick the “Sold individually” checkbox in the “Inventory” product data tab in the single product edit page to force quantity 1 for whatever product: “Enable this to only allow one of this item to be bought in a single order“.

Problem is, you may need to set this “programmatically” (via code), based on certain conditions. One reason is that you may not want to edit hundreds of products one by one (or in bulk) – another is that you may want to “override” whatever settings based on certain conditions (for example, you set “Sold Individually”, but if the Cart total is greater than 100 you want to allow quantities greater than 1).

As you can see, in this post we will cover, once again, the magic of “conditional logic“. Enjoy!

Continue reading WooCommerce: Conditionally Force Product Quantity 1 @ Cart

WooCommerce: Conditionally Hide Widgets

You could use a popular plugin called Widget Logic, or instead you could keep it simple with a few lines of PHP. Here’s a snippet for you in case you need to conditionally hide a certain sidebar widget given a condition e.g. if you’re on the Cart page.

Of course, you can use any of the available WooCommerce conditional tags and make this more complex, but in this example we’ll keep it simple and check if we’re looking at the Cart page (thanks to the is_cart() conditional). Enjoy!

Continue reading WooCommerce: Conditionally Hide Widgets

WooCommerce: How to Enable Catalog Mode?

One of the most common WooCommerce questions is: can I use WooCommerce to build a catalog of products (without add to cart, price… basically a product gallery)? Using WooCommerce for this case scenario is indeed very helpful – you can make the most of all the inbuilt features such as single product gallery and carousel, image zoom, product description tabs, attributes, categories, tags and related products. Basically a much better version than a standard image gallery.

Another question might be: can I disable the WooCommerce add to cart / cart / checkout functionality until the time I am able to sell my products? This is another common scenario that many WooCommerce store owners require.

Besides, certain products in your WooCommerce website might be for sale and others might not. In this case, you’d want to disable the add to cart functionality from specific categories or products.

Finally, you might want to restrict the cart / checkout functions to logged in, registered users only. This is if you run a wholesale business for example, and wish to hide your prices to the public.

Either way, when the “Add to Cart” button gets hidden, a contact form might be required – this is what I call a “Product Inquiry” form.

Good news is there are snippets and plugins that can make your life easier, your admin time more efficient and your product management simpler. And today we’re taking a look at the best options.

Continue reading WooCommerce: How to Enable Catalog Mode?

WooCommerce: Per-Product Terms & Conditions @ Checkout

A freelance client sells two distinct products on the same website: a membership and an online course. Two different audiences, different formats and… different Terms & Conditions.

The goal was therefore to display the “Terms & Conditions” checkbox on the Checkout page based on the product in the cart. Once again, we’re going to use Conditional Logic. With that, the snippet is pretty easy to code!

Continue reading WooCommerce: Per-Product Terms & Conditions @ Checkout

WooCommerce: Add Different Facebook Pixels to Different Pages

Last week a client who was about to carry a Facebook Advertising campaign asked me something pretty interesting. We already saw in the past how to add conversion tracking to the Thank-you page, however this time was slightly different.

My client’s FB consultant required a code for the whole site, another code for the Checkout page only (“user has initiated checkout”), and another one for the Thank-you page (“user has purchased”). So, here’s how I did it. Continue reading WooCommerce: Add Different Facebook Pixels to Different Pages

WooCommerce: Display Different Widgets Based On Product Category

Using Widget Logic, you can easily set what widget you want to display based on what WooCommerce product categories users are browsing.

For example, you can set what widgets users will see when he will land to the “Book” product category page. These widgets will not be visible in other pages, it will be only shown to a user when he lands to that exact category.

Continue reading WooCommerce: Display Different Widgets Based On Product Category

WooCommerce: Show Message Upon Country Selection @ Checkout

If you have country-specific shipping conditions, or you want to show a message conditionally after country selection on the checkout page, here’s a simple WooCommerce PHP snippet you can freely use. This can be slightly customized to target state selection instead.

I’ve also edited the initial code to make this work on load as well, so that the message would conditionally show even then. Enjoy!

Continue reading WooCommerce: Show Message Upon Country Selection @ Checkout