Plugin Author
Soft79
(@josk79)
Hi Jeasy,
I managed to reproduce your issue. I’ll come back to you.
Cheers!
Plugin Author
Soft79
(@josk79)
Jeasy,
There seems to be a problem in the existing WooCommerce coupon class. The problem also exists if the coupon isn’t marked as an ‘Auto Coupon’.
I’d suggest you’d contact Woothemes about the issue, because it seems to be a bug.
I made a quick fix. As a workaround paste the following code in your functions.php, tested in WooCommerce 2.1.12:
add_filter('woocommerce_coupon_is_valid', 'woocommerce_coupon_is_valid', 10, 2 );
function woocommerce_coupon_is_valid( $valid, $coupon) {
if ( $valid && $coupon->exclude_sale_items == 'yes' ) {
$product_ids_on_sale = wc_get_product_ids_on_sale();
if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
if ( in_array( $cart_item['product_id'], $product_ids_on_sale, false ) || in_array( $cart_item['variation_id'], $product_ids_on_sale, false ) || in_array( $cart_item['data']->get_parent(), $product_ids_on_sale, false ) ) {
return false;
}
}
}
}
return $valid;
}
Let me know if this solves your problem.
Please don’t forget to rate my plugin!
Jos.
Thread Starter
Jeasy
(@jeasysehgal)
Hi Jos,
Thanks for your reply. Tried your solution and we are kind of getting there. 🙂 SO after adding the custom code to the Functions.php, when a sale item is in the cart, no coupon is applied and no description is shown which is great. How ever when there is another item in the cart as well which is a full price item, the coupon doens’t apply at all now. Technically the coupon should still apply for the full price item and not for the on sale item. Am I correct.
The coupon is set as Product % discount with a minimum spend of $250. I will open another ticket for woocommerce developers. Have been at them for ages to fix this bug, they seem to be looking past it for some reason.
Kind Regards,
Jeasy
Plugin Author
Soft79
(@josk79)
The coupon class has some more errors. If I change the woocommerce_coupon_is_valid to your needs, the discount will be applied to all products, (also to sale products). More functions in the coupon class have to be overridden to let it work the way it should.
Let me know if the Woo guys come up with a fix, if not you’ll need another workaround, but the functionality might break in future WooCommerce releases.
Plugin Author
Soft79
(@josk79)
Jeasy,
I posted the workaround on your WooCommerce thread.
Can I mark this topic as resolved?
regards,
Jos
Thread Starter
Jeasy
(@jeasysehgal)
Hi Jos,
Thanks, syill waiting to hear back from the guys at woo commerce. But will try the new workaround. I still give A+ to your plugin and the concept. If only woocommerce was to fix their internal bugs to lets users use it to its full potentials..
Kind regards,
Jeasy
Plugin Author
Soft79
(@josk79)
Yes, you’re right. I hope the fix works for you.
Please rate my plugin using the WordPress ratings system!
Have a good day.