• Resolved Jeasy

    (@jeasysehgal)


    Hi There,

    Love the idea of this plugin however have run into a little road block.

    My website is http://www.ImperialSwords.com and what I want to do is that if a customer spends $250 or more on Non-Sale items then they receive an automatic 10% discount however, if they add an item over $250 in the cart which happens to be On Sale, the coupon shouldn’t show or give a discount. Presently the way it is working is, if I have Products a on sale and Product B regular price added to the cart and the coupon set at product % discount and should not apply to sale items, it works alright, but if I remove the regular priced item or product B from the cart and now product A which is an On sale product remains in the cart, the coupon description still shows in the cart totals however no discount amount is taken off.

    SO in a nut shell, When the cart has an item on sale with the above settings, the discount description and discount should not be applied or shown in the cart at all. Any clues how we can achieve this…

    Your help would be greatly appreciated.

    Kind Regards,

    Jeasy

    https://wordpress.org/plugins/woocommerce-auto-added-coupons/

Viewing 7 replies - 1 through 7 (of 7 total)
  • 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.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘The auto coupon shows up for sale items’ is closed to new replies.