Repository Forums Support WooCommerce Extended Coupon Features PRO Redirect with apply_coupon

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #1023


    I want to be able to email customers a link that adds a product to the cart with a certain quantity, and apply a promocode, like this:

    If you click on this directly when you are not on the site, it will redirect (in my case) back to the purchase page. I would like to stay on the cart page (as defined by wc_get_cart_url()). There is also a setting in WC where you set to redirect to the cart page when a product is added to the cart.

    Here is the function within add_to_cart_action

    // If we added the product to the cart we can now optionally do a redirect.
    		if ( $was_added_to_cart && wc_notice_count( 'error' ) === 0 ) {
    			// If has custom URL redirect there
    			if ( $url = apply_filters( 'woocommerce_add_to_cart_redirect', $url ) ) {
    				wp_safe_redirect( $url );
    			} elseif ( get_option( 'woocommerce_cart_redirect_after_add' ) === 'yes' ) {
    				wp_safe_redirect( wc_get_cart_url() );

    The coupon plugin however seems to ignore this here in coupon_by_url()

    //Redirect to page without autocoupon query args
    		if ( $must_redirect ) {
    			$requested_url  = is_ssl() ? 'https://' : 'http://';
    			$requested_url .= $_SERVER['HTTP_HOST'];		   
    			$requested_url .= $_SERVER['REQUEST_URI'];
    			wp_safe_redirect( remove_query_arg( array( 'apply_coupon', 'add-to-cart' ), ( $requested_url ) ) );

    If i remove the coupon code, the link works fine, and stays on the cart page.

    Is there a way to include the apply_coupon and honor the redirection set by WC?




    There has been a lot of struggle with add-to-cart in combination with apply_coupon.

    Best option is to use this little plugin:

    and replace ?add-to-cart=35168&quantity=2 with ?fill_cart=2×35168

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.