Viewing 15 replies - 1 through 15 (of 16 total)
  • Thread Starter nichelead

    (@nichelead)

    I cleared the cart and cleared the browser cookies and cache, and now the link adds the product & coupon to the cart, but gives warnings on the cart page – 2 warnings that I cannot add this product again to the cart & 1 warning that the coupon code was already applied.

    It seems that using this link, it tries to add the product 3 times and the coupon 2 times…

    Here is the image of what I get on the cart page when I use the link:
    https://successgoose.com/cart-coupon/

    Thanks!

    Tom

    Plugin Author Soft79

    (@josk79)

    Hi Nichelead,

    I think it has to do with redirects. If I go to
    https://yoursite.com/cart/?add-to-cart=1264&apply_coupon=freeguide-sywtm

    it immediately redirects to the /checkout/ page, what causes this? Can you try disabling this redirect?

    Thread Starter nichelead

    (@nichelead)

    Hi,

    Thanks for getting back to me.
    Yes, there was a redirect to checkout and I disabled it.
    It is not redirecting anymore, but still give these warnings.

    Plugin Author Soft79

    (@josk79)

    Ok, I found the issue. Two things.

    If I use this url:

    https://yoursite.com/cart/?add-to-cart=1264&apply_coupon=freeguide-sywtm

    it seems fine at first call, but if I use this url instead:

    https://yoursite.com/cart?add-to-cart=1264&apply_coupon=freeguide-sywtm
    (notice the trailing slash removed after /cart)

    I get the warnings. This is because of another redirect. So, you have to use the first url.

    Ok, so far so good using the first url. But opening the cart for a second time it will shows the warning ‘coupon already applied’ on the second call. The reason seems to be the minicart, the minicart is called by ajax with &apply_coupon=… as well. This could be a quick fix:

    In includes/wjecf-autocoupon.php please find this line (line 35 if you use the latest version):

    add_action( 'wp_loaded', array( &$this, 'coupon_by_url' ), 23);

    and replace with:

    if ( ! is_ajax() ) {
    	add_action( 'wp_loaded', array( &$this, 'coupon_by_url' ), 23); //Coupon through url
    }

    This should fix it. I will patch this in a following release of my plugin.

    Thread Starter nichelead

    (@nichelead)

    Works Perfect!

    Thank you!

    Plugin Author Soft79

    (@josk79)

    Excellent!

    Thanks for rating my plugin!

    Thread Starter nichelead

    (@nichelead)

    Hi Josk79,

    So, one more little hiccup…

    After I disabled the plugin that redirected from Buy button strait to checkout (skipping the cart), I realized that my Add To Cart Button didn’t directed to the cart.

    It was a Woocommerce setting that I didn’t use while I was using that checkout redirect plugin.

    So to fix this now, I went to Woocommerce, Settings, Product Tab, Display Sub-Tab, “Add to cart behavior” and checked “Redirect to the cart page after successful addition”.

    That fixed the problem, so now the Add To Cart Button redirect to the Cart.

    But – now I get again a “You cannot add another product…” warning when using the link to add product & coupon.

    Thanks!

    Tom

    Plugin Author Soft79

    (@josk79)

    Does enabling my plugin cause the issue? Even without an apply_coupon request? Can you send me a link that causes the issue?

    Did you disable my plugin? I want to try it out but the coupon doesn’t seem to exist anymore and apply_coupon does nothing.

    Thread Starter nichelead

    (@nichelead)

    Sorry, I changed the coupon and forgot to mention. here is the new coupon:
    freeguide-syw

    Plugin Author Soft79

    (@josk79)

    I think my plugin is disabled, so I can’t test.

    Also I don’t see any issues, maybe because you disabled my plugin?

    Thread Starter nichelead

    (@nichelead)

    Your plugin is not disable.

    Try this link.
    https://successgoose.com/cart/?add-to-cart=1264&apply_coupon=freeguide-syw

    For me, it just adds the product – not the coupon.
    If after using this link once, I use it again, without empty the cart, it will now add the coupon (just with warning notice “You cannot add another product…”.
    The problem is that the first time I use the link it doesn’t add the coupon.

    Plugin Author Soft79

    (@josk79)

    I see, the redirection to the cart disables the handling of apply_coupon. I’ll have to look into that…

    I’ll get back to you later this week.

    Thread Starter nichelead

    (@nichelead)

    Thank you!

    Plugin Author Soft79

    (@josk79)

    If you have PHP >= 5.3 can you please try adding these lines in your theme’s function.php?

    Or you can place it in wjecf-autocoupon.php before the if ( ! is_ajax() ) { you added.

    add_filter('option_woocommerce_cart_redirect_after_add', function( $value ) {
    	if ( isset( $_GET['apply_coupon'] ) ) {
    		$value = 'no';
    	}
    	return $value;
    } );

    and let me know if it works then? This should disable the cart redirect if apply_coupon is passed in the url.

    Thread Starter nichelead

    (@nichelead)

    You’re the man!

    I added it to wjecf-autocoupon.php – I assume you will patch it in the plugin update so I don’t need to worry about loosing these changes

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘How to add product & coupon to cart with a link?’ is closed to new replies.