WooCommerce: Calculate Sales by Product ID (Shortcode)

Let’s say you’re developing a custom sales page or a landing page. A great way to increase your conversion rate is by showing the number of purchases close to the “add to cart” button.

We’ve already seen how to do this on the single product page, but what if you need to show this on a custom page, and therefore you need a shortcode?

Well, this is super easy and I’m currently using the snippet below on my own website, and specifically in the pricing table of my #CustomizeWoo online course sales page. So, here you go – enjoy!

Continue reading WooCommerce: Calculate Sales by Product ID (Shortcode)

WooCommerce: Remove Product From Cart Programmatically

We already saw how to add a product to cart automatically, for example if you visit a specific page or if there are no products in the cart – but today we want to find out how to do the opposite: if a certain condition is met, we want to remove a product ID from the cart.

This becomes a little complex – while adding an item to cart requires just its product ID, removing it from the cart forces you to know the “cart item key”. Japanese, I know, but just copy the snippet and you’re done!

Continue reading WooCommerce: Remove Product From Cart Programmatically

WooCommerce: Bulk Dynamic Pricing (Without Plugins)

In today’s competitive retail landscape, offering the right price at the right time is crucial for driving sales and maximizing profits. But what if your pricing strategy could adapt automatically, rewarding customers who buy in bulk?

Enter bulk dynamic pricing, a powerful tool that allows you to create tiered discounts based on quantity.

We’re here looking to assign different product prices based on the quantity added to Cart, for example from quantity 1-100 price is $5, from 101-1000 price is $4.90 and from 1001 the price becomes $4.75.

This blog post will be your one-stop guide to setting up bulk dynamic pricing for your WooCommerce store – enjoy!

Continue reading WooCommerce: Bulk Dynamic Pricing (Without Plugins)

WooCommerce: Single Product Page Redirect for Logged In Customers

If you sell one-off products like online courses, lifetime memberships or unique pieces that can only be purchased once by a given customer, maybe you’d better redirecting the logged in customer who has purchased that product to a custom URL, such as the shop page, the “my courses” page for online courses or another customer-specific section.

With this easy snippet you’ll learn how to see if a user is logged in and has purchased a given product ID and then how to do a safe PHP redirect. Enjoy!

Continue reading WooCommerce: Single Product Page Redirect for Logged In Customers

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: Edit “Continue Shopping” Link Redirect

“Continue Shopping” appears on the Cart page when an item is added to Cart and you have “Redirect to the cart page after successful addition” enabled via the WooCommerce settings.

By default, “Continue Shopping” button redirects to the previously visited page – sometimes this makes no sense and you might want to send them back to the main shop page instead (or a custom page).

Here’s a quick snippet to do just that. Enjoy!

Continue reading WooCommerce: Edit “Continue Shopping” Link Redirect

WooCommerce: Allow to “Pay for Order” Without Login

Some plugins such as “deposit” and “subscription” payments send customers to the “Pay for Order” page in order to complete a pending WooCommerce order.

In certain cases, also, the customer is forced to log in and this really affect sales conversion rate – instead of the checkout form customers see this notice: “Please log in to your account below to continue to the payment form“.

On top of that, there is another notification error for guest orders: “To view this page, you must either login or verify the email address associated with the order” – we’ll fix that as well.

Here’s a quick snippet to make sure customers do not have to log in when on the “Pay for Order” page, so that they can immediately go ahead with the payment.

The WooCommerce function in question is wc_customer_has_capability, and thankfully we can override this with the user_has_cap filter. Enjoy!

Continue reading WooCommerce: Allow to “Pay for Order” Without Login

Shoptimizer Theme Visual Hook Guide

Here’s a visual hook guide for Shoptimizer Theme by CommerceGurus, a WooCommerce theme specifically developed with speed, performance, sales conversion and UX in mind.

This visual guide belongs to my “Visual Hook Guide Series“, that I’ve put together so that you can find WooCommerce hooks quickly and easily by seeing their actual locations. Also, you can copy & paste in seconds and speed up your customization time.

Let me know in the comments what you think about this resource! Enjoy!

Continue reading Shoptimizer Theme Visual Hook Guide

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: Add Upsell Area @ Checkout Page

If you want to increase your AOV (Average Order Value), you can definitely start from the WooCommerce Checkout page.

A client asked me to place a “Donation Area” close to the “Place Order” button (so at the bottom of the page, once customers are ready to pay) to drive more awareness around this add-on. All I had to do was creating hidden products with a donation value, use my own “Custom Add to Cart URL” guide to create add to cart links and print an HTML box right above the checkout button by using my WooCommerce Visual Hook Guide for the Checkout Page. Enjoy!

Continue reading WooCommerce: Add Upsell Area @ Checkout Page

WooCommerce: Scroll To Product Tab @ Single Product Page

Depending on your theme, just creating an href link anchor to a product tab might or might not work i.e. it might not scroll to it as it’s currently closed.

Here comes a way to create href links that not only scroll to the tab, but also open it in case it’s closed (this will guarantee the anchor scroll to the tab). Also, a little jQuery “animate” will provide the smooth scroll and enhance UX. Hope you enjoy!

Continue reading WooCommerce: Scroll To Product Tab @ Single Product Page

WooCommerce: Move & Customize Upsells @ Single Product

Keeping WooCommerce upsells at the very bottom of the single product page it’s kinda boring. In my view, WooCommerce users want to know there are upsells even before they scroll down (you also might want that: upsell means more profit). Amazon does that too.

In this tutorial, we will see not only how to move them to the top, right below the Add to Cart, but also how to customize the upsells output to show just 2 columns and remove default WooCommerce “loop” elements such as the Add to Cart. Enjoy!

Continue reading WooCommerce: Move & Customize Upsells @ Single Product

WooCommerce: Set Checkout Field Value @ Order Creation

This is a very specific function. Sometimes, you need to “set” a checkout field value upon order creation (because it was not required and left empty for example). In some other cases, you might want to override what the customer input if you have certain requirements.

Either way, overriding the checkout fields on order creation is super easy. Here’s how it’s done – enjoy!

Continue reading WooCommerce: Set Checkout Field Value @ Order Creation

WooCommerce: Add Custom Field to “Bulk Actions” > “Edit”

As you know, one of the product bulk edit methods comes with WooCommerce out of the box. It can be found under “WP Dashboard” > “Products” > “Bulk Actions” > “Edit”. For example, you can decrease all prices by 10%, or bulk assign a new product category.

However, if you added a custom product field such as RRP, this won’t show automatically there in the bulk edit form – you’ll therefore need to add it via code. Thankfully, WooCommerce gives us a “hook” we can use to display the input in the bulk edit form. After that, another PHP function will be used to save and store the value.

Easy as pie! Just copy & paste into your functions.php. Enjoy ๐Ÿ™‚

Continue reading WooCommerce: Add Custom Field to “Bulk Actions” > “Edit”

WooCommerce: Checkbox to Disable Related Products Conditionally

Here’s how you can display a “checkbox” in the product edit page in order to hide the Related Products section in case this is checked. This is something you can also reuse to hide other sections in the same way – for example you might need to hide product tabs or featured image in certain cases.

I’ve coded this in 15 minutes for a client so why not sharing it with you too? Here’s the full snippet, enjoy!

Continue reading WooCommerce: Checkbox to Disable Related Products Conditionally

WooCommerce: Product Add-Ons (Without a Plugin!)

WooCommerce product add-ons are custom input fields that show on the single product page. They’re called “add-ons” as you can add a product personalization or an upsell (at a cost of course).

For example, you can display a text input to print something on the product. Or radio buttons to select different kinds of product upgrades. Or a checkbox to upsell gift wrapping.

Either way, and of course, there are plugins for that. But first, I want to give you a tutorial to code this by yourself (case study: global custom input text field and no surcharge), so that you can learn something new. Enjoy!

Continue reading WooCommerce: Product Add-Ons (Without a Plugin!)

WooCommerce: Add Second Description @ Product Category Pages

In terms of SEO, if you’re trying to rank your product category pages, you really need to make the most of the default WooCommerce product category “description” and “thumbnail”. Most themes, if compatible with WooCommerce, will show this content right below the product category name and above products.

Nothing new so far. But what if you want to add another piece of content below the category products while also keeping the default description? Well, we’d need to customize the edit category page and display a new text editor field, save it, and finally display it where we want. So, here’s how they do it!

Continue reading WooCommerce: Add Second Description @ Product Category Pages

WooCommerce: Show Empty Product Categories

By default, empty WooCommerce product categories (i.e. categories which have no published products) will not display on your Shop page.

This makes a lot of sense and avoids that customers land on empty pages… BUT sometimes you might have different needs and require that users still see these categories when the shop display is set to “Show Categories”.

Thankfully there is a quick one-line fix that you can copy / paste in your functions.php to show empty categories… enjoy!

Continue reading WooCommerce: Show Empty Product Categories