WooCommerce: Add Product to Cart On Visit Programmatically

Quite an interesting functionality! A WooCommerce client wanted their Cart pre-filled with one product as soon as their customers accessed the website. I don’t remember the exact reason, but this could be useful when you want to give them a free product by default, or you want to send your visitors straight to checkout with a product already in the cart without letting them add anything first.

Adding an item to cart programmatically is the same as “automatically”. Basically, all users will have a default, non-empty Cart filled with an item of your choice. So, let’s see how this snippet works!

Continue reading WooCommerce: Add Product to Cart On Visit Programmatically

WooCommerce Visual Hook Guide: Cart Page

I’ve put together a visual (yet, you can copy/paste!) hook guide for the WooCommerce Cart Page. If you like this and it is helpful to you, let me know in the comments and I’ll create another one for the checkout, single product page and my account page.

You can find WooCommerce Cart hooks quickly and easily by seeing their actual locations. Great thing is – all you need to do in your functions.php is “add_action(‘place-hook-here’,’your-PHP-function-here’);” and you can place your custom functions anywhere on the WooCommerce Cart Page. Enjoy!

Continue reading WooCommerce Visual Hook Guide: Cart Page

WooCommerce: How to Hide Cart Table Columns

There are many reasons why you may want to remove columns (e.g. subtotal) from the Cart table. Sometimes you just want to make it easier for your customers. The less information you show the better!

Some other times,ย  you may have custom requirements. Well, hiding a Cart table column is actually very easy – and despite this can be done with PHP I believe the CSS way is way faster in this case. Here’s how it’s done!

Continue reading WooCommerce: How to Hide Cart Table Columns

WooCommerce: Only Allow 1 Product in the Cart

Here’s how to limit your WooCommerce Cart to just one product at a time.

This simple solution can be used for many applications. For example, your store may only allow to buy one subscription at a time.

On this same website, for example, customers can only purchase one product at a time so it’s easier for me to manage invoicing and payments, given that I switch PayPal and Stripe accounts based on what’s inside the cart.

Here’s the quick fix – enjoy!

Continue reading WooCommerce: Only Allow 1 Product in the Cart

WooCommerce: Apply Coupon Programmatically if Product @ Cart

Users can manually enter a coupon code, refresh the Cart and see their discount apply… or you can do that automatically (or “programmatically” as we say in the dark web) when a user adds a product to the WooCommerce Cart ๐Ÿ™‚

All you’ve got to do is creating a coupon, and then a PHP function will do the whole work. Automation is the best thing in the world!

Continue reading WooCommerce: Apply Coupon Programmatically if Product @ Cart

WooCommerce: Remove Shipping Labels @ Cart (e.g. “Flat Rate”)

WooCommerce functions add the shipping method label on the Cart totals, on the left hand side of the price. This ruins the price amounts alignment (subtotal, shipping, taxes, total) and many clients have asked me to remove it completely. Also, it could be that sometimes you don’t want to show the name of a shipping rate on the front-end. So, here’s how you do it!

Continue reading WooCommerce: Remove Shipping Labels @ Cart (e.g. “Flat Rate”)

WooCommerce: How to Fix the “Cart is Empty” Issue

For some reason, sometimes you add products to cart but the cart page stays empty (even if you can clearly see the cart widget has products in it for example).

But don’t worry – it may just be a simple cache issue (and if you don’t know what cache is that’s no problem either) or a theme / plugin “conflict”.

The WooCommerce Cart page is extremely delicate; it displays dynamic content based on cookies and PHP sessions, is coded with PHP but also JS and Ajax, requires to be excluded from cache and is subject to problems in case of out of date software.

So, here’s your “Empty Cart” troubleshooting checklist you can follow without any technical knowledge.

I also recommend you read through the (many) comments, because many developers shared what worked for them too. Good luck!

Continue reading WooCommerce: How to Fix the “Cart is Empty” Issue

WooCommerce: Hide Price & Add to Cart for Logged Out Users

You may want to force users to login in order to see prices and add products to cart. That means you must hide add to cart buttons and prices on the Shop and Single Product pages when a user is logged out.

All you need is pasting the following code in your functions.php (please note: your theme may have overwritten some default WooCommerce functions, hence the code below may not work. Contact me if you need custom code). Enjoy!

Continue reading WooCommerce: Hide Price & Add to Cart for Logged Out Users

WooCommerce: Maximize Sales with Deep Customer Data Insights

WooCommerce is far from just another ecommerce platform, it is a powerhouse that runs on WordPress, and brings with it limitless possibilities when it comes to operating a high-caliber online retail operation.

One aspect of the platform that is often ignored and underutilized is its remarkable data-harnessing capabilities. 

When combined with the magic of data, WooCommerce sites can predict what their customers need, even before they know it themselves, adding substantial value, while improving cart sizes, margins, and profitability in the process.

In this article, we take a look at what data depth is, and how to make it work with WooCommerce to enhance campaigns and profitability in the long run.

Continue reading WooCommerce: Maximize Sales with Deep Customer Data Insights

WooCommerce: Exclude Shipping Method From Specific User Role

WooCommerce offers a robust shipping system, but what if you want to tailor it based on the logged in user role?

In this blog post, we’ll show you how to exclude specific shipping methods from users with a particular role. This allows you to, for example, offer free shipping only to VIP members or restrict express delivery options to regular customers.

All you need is the user role slug (WordPress Dashboard > Users -> All Users > above the user list table you’ll see a horizontal list displaying the current user roles available on your site (e.g., Administrator, Editor, Author). Hover on one of them and see the URL, which will contain the exact slug e.g. “customer”) and the shipping rate ID you wish to disable (e.g. “flat_rate:9”. For more info you can find out how to find IDs here: https://businessbloomer.com/woocommerce-disable-free-shipping-if-cart-has-shipping-class).

Enjoy!

Continue reading WooCommerce: Exclude Shipping Method From Specific User Role

WooCommerce, Shopify, Wix: A Step-by-Step Guide to Launching Your Ecommerce Business

Almost 25% of retail sales are expected to happen online by 2026, so you should create a web store if you run a small business. With the right tools, any merchant can start selling online. 

A good ecommerce website-building platform will let you list products, process payments, and organize shipping without leaving your home or store.ย 

But with so many platforms โ€“ WooCommerce, Shopify, Wix, and more โ€“ choosing the right one can feel overwhelming.

This guide focuses more on the steps that are required to publish your first ecommerce website with any of these solutions, so you can hit the ground running and start selling today!

Continue reading WooCommerce, Shopify, Wix: A Step-by-Step Guide to Launching Your Ecommerce Business

WooCommerce: Set Default Shipping Class For All Products

Manually assigning a shipping class to each product can be tedious and time-consuming. Here’s where default product shipping classes come to the rescue!

This code tutorial will show you how to set a default shipping class for your products in WooCommerce without the need to access the “edit product” WordPress admin page to pick an option from the shipping class dropdown.

Enjoy!

Continue reading WooCommerce: Set Default Shipping Class For All Products