Adding products to cart automatically when a visitor is on your site is something that can be very useful when you use WooCommerce. It could what ever you want: an insurance, a sale product etc… And guess what? This is is pretty easy to do. All you need is a little snippet to add to functions.php, in your theme folder. To choose the product to add to the cart, simply find its ID, and then replace the default value in the snippet below.
You probably saw this commercial method on many websites, and i have to say that it’s pretty powerful, but be careful when using it because it annoy a bunch of people. If you think like a visitor, you add a product to your cart and when you arrive on the cart page, there are … two products in it. Well, there are pros and cons but depending on your business it can good or bad. Let’s say you sell mobile phones, then your customers would may be interested in purchasing an insurance for their mobiles.
But if you sell hoodies, and you automatically add socks, shoes or whatever that isn’t really related to the first product, then i’m not sure your had the best idea to add this product to the cart automatically. Hopefully, clients can remove the product from the cart, but it’s an extra action that you ask them to do, and the more actions you ask you visitors to do, the less they will be keen on finishing the checkout process.
So, here is the snippet. Place it in functions.php in your theme folder:
Then, what i would do is probably to check products already in cart and then automatically add a related product to the cart, that would make things a bit more efficient. And finally, i would totally avoid adding a random product to cart.