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

  • Resolved George



    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

    The code for clear-cart was posted on GitHub by user kloon and can be found at

    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 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


    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 ) ) );





    Thanks for your prompt response.

    Your code snippet appears to update the URL as intended, so it changes to

    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.


    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 version of your plugin. Version 2.3.7 works fine.



    OK so it appears that on version 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.