Check cart items for specific item & apply discount (WooCommerce)

I was working on a WordPress + Woocommerce store and there are special membership items, similar to a book store chain. If you buy a membership, you get a 10% discount on your purchases, including the current purchase, but only if you buy additional items.

So here is some PHP which checks your cart for the item in question, checks if there are other items in the cart, and applies the discount. If the special item is removed from the cart, the discount is removed as well.

Here is a modified version, using an array for the special items, in case you have different membership levels:

There are no comments

Your email address will not be published. Required fields are marked *