Home » Php » php – WooCommerce coupon code per line item

php – WooCommerce coupon code per line item

Posted by: admin July 12, 2020 Leave a comment

Questions:

Is there any way to set up a coupon code in WooCommerce so that a usage is counted for each line item in the order?

Example process:

  1. Customer has a voucher code unique to themselves with 100 use maximum
  2. Customer places an order with 10 products in it and uses the voucher code
  3. Voucher now has 90 remaining uses

And another:

  1. Customer has a voucher code unique to themselves with 100 use maximum
  2. Customer places an order with 200 products in it and uses the voucher code
  3. Voucher now has 0 remaining uses
  4. Customer pays full price on the remaining 100 products

As it is, I can’t see any core way to do this, or any third party extension that would allow it.

How to&Answers:

Agreed with Richard Green that you’ll have to do your own custom code for this unfortunately. It looks like native woocommerce doesn’t even have user specific coupons.

For that aspect of your problem there are plugins you could buy if you’re willing to spend some money. For example:

http://ignitewoo.com/woocommerce-extensions-plugins/woocommerce-gift-certificates-pro/ or a plugin from woothemes called smart coupons(I can only post 1 link)

You could then write custom code to hook into those.

Answer:

You will need to create your own custom discount type and logic:
http://docs.woothemes.com/wc-apidocs/class-WC_Coupon.html