WooCommerce Add a product to the cart programmatically

At times you may want to give free gift when customer purchase specific product from your shop. Instead of user need to select the gift explicitly you would like to add it automatically to the cart, when user add given product to the cart.

Below code snippet will help you to achieve exactly that. In this PHP code you can select which product to add to the cart and quantity of that product as well.

Note: This code snippet add simple product to the cart.

Leave a Reply