Skip to content
Advertisement

Adding a promotional product when a certain cart amount is reached

I am looking for the right hook in WooCommerce because I need to add a promotional product to the cart when a certain cart amount of is reached, such as 100 conventional units.

I have also used the hook 'init' but I do not think it’s right.

Here is my code:

JavaScript

which hook I should use for that purpose?

Or could you give me a related link to to some similar problem?

Thanks

Advertisement

Answer

As you are targeting a certain cart amount to add a promotional product in the cart, you could use woocommerce_before_calculate_totals hook to achieve this with a custom built function.

You have also to remove that promo item if customer update the cart (which is embed in that custom function too).

Here is the code:

JavaScript

This code goes on function.php file of your active child theme (or theme) or in any plugin file.

This code its tested and works.

Related thread: WooCommerce – Auto add or auto remove a freebie product from cart

Code updated on (2018-10-01)

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement