Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
202 views
in Technique[技术] by (71.8m points)

php - 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?

question from:https://stackoverflow.com/questions/65905315/every-tenth-product-a-free-gift-in-woocommerce

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Does the code enter the modulo part?

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...