Support » Plugin: WooCommerce Extended Coupon Features FREE » clear-cart and apply_coupon

  • Resolved George

    (@subscriptiongroup)


    Hello,

    We’ve been testing your plugin for quite a while and it appears to work as described, however we’ve got some unique requirements that don’t appear to work out of the box.

    We have some cases where users have a coupon or product already applied to their cart, and we would like to first clear their carts and then do apply_coupon and add-to-cart. The URL would then look like website.com/checkout?clear-cart&apply_coupon=coupon123&add-to-cart=123

    The code for clear-cart was posted on GitHub by user kloon and can be found at https://gist.github.com/kloon/4541017

    This code hooks into init and i assume your apply_coupon code has already fired at that point. The problem appears to be with apply_coupon only, as add-to-cart works and a product is added to the cart when the URL website.com/checkout?clear-cart&apply_coupon=coupon123&add-to-cart=123 is used.

    This feature might already be present, but if it’s not, it would be a great and easy addition to your plugin.

    If you don’t plan to add this feature, could you advise of the modifications i should do to have them working together?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Soft79

    (@josk79)

    Try appending the following to the github snippet, (after $woocommerce->cart->empty_cart();):

    
    $requested_url  = is_ssl() ? 'https://' : 'http://';
    $requested_url .= $_SERVER['HTTP_HOST'];		   
    $requested_url .= $_SERVER['REQUEST_URI'];
    
    wp_safe_redirect( remove_query_arg( array( 'clear-cart' ), ( $requested_url ) ) );
    exit;
    

    untested.

    George

    (@subscriptiongroup)

    Hi,

    Thanks for your prompt response.

    Your code snippet appears to update the URL as intended, so it changes
    https://www.website.com/checkout?clear-cart&apply_coupon=my-coupon&add-to-cart=68983 to https://www.website.com/checkout?apply_coupon=my-coupon&add-to-cart=68983

    For some reason the apply_coupon feature has stopped working on our site. We are currently investigating if that’s caused by the latest version of WC (2.6.11) or something else.

    • This reply was modified 3 years, 10 months ago by George.
    George

    (@subscriptiongroup)

    Has your latest version been tested with WP 4.7?

    For some reason, apply_coupon doesn’t appear to work with WP 4.7 and 2.3.7.4 version of your plugin. Version 2.3.7 works fine.

    George

    (@subscriptiongroup)

    OK so it appears that on version 2.3.7.4 apply_coupon doesn’t work. I tested on the following setups:

    WP 4.6 & WC 2.6.9
    WP 4.7 (latest) & WC 2.6.9
    WP 4.7 (latest) & WC 2.6.11 (latest)

    Not sure if anyone else can reproduce this, or it’s limited to us?

    I downgraded to version 2.3.7 and apply_coupon works.

    Version 2.3.7 also works with the customisation you mentioned on your reply, so technically, this thread can be marked as resolved.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘clear-cart and apply_coupon’ is closed to new replies.