Danny
Danny

Reputation: 95

Every tenth product a free gift in woocommerce

Using WooCommerce promotional discount: Buy 10 Get 1 Free answer, is exactly what I was looking for. Except I need this to work for every tenth added product. So, when someone puts in a total of 10 products from $targeted_product_ids, every tenth added product should give a free gift. For example; When someone orders 10 products = 1 free gift. When someone orders 20 products = 2 free gifts. When someone orders 30 products = 3 free gifts etc. Just can't seem to adapt the code and get it to work.

Any help?

Upvotes: 0

Views: 348

Answers (1)

Bart Klein Reesink
Bart Klein Reesink

Reputation: 122

Does the code enter the modulo part?

if ( ( $key + 1 ) % $each_n_items == 0 )

Should bring up every 10th item as true. (docs)

Upvotes: 1

Related Questions