Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/cart?add-to-cart=ID adds the item to cart twice #5400

Closed
dwainm opened this issue May 1, 2014 · 25 comments

Comments

@dwainm
Copy link
Member

@dwainm dwainm commented May 1, 2014

When using "/cart?add-to-cart=ID" instead of "/cart/?add-to-cart=50" causes the item to be added twice.

The first time is just before the redirect and then again after the redirect.

@dwainm dwainm added Bug labels May 1, 2014
@mikejolley

This comment has been minimized.

Copy link
Member

@mikejolley mikejolley commented May 1, 2014

I don't think that can be worked around HOWEVER, our internal functions for generating add-to-cart urls always use the permalink. Permalinks have a trailing slash. This means the only time you'd get /cart? is if you had some code removing trailing slashes, or you had some external code creating that add to cart url.

If you have a case where WC core itself is not adding a trailing slash, add more info and reopen.

@mikejolley mikejolley closed this May 1, 2014
@noob1211

This comment has been minimized.

Copy link

@noob1211 noob1211 commented Jan 22, 2015

why the heck is this closed...this is still a persisting problem....
show the EXACT solution or reopen this issue. i cant believe this crap...

@dwainm

This comment has been minimized.

Copy link
Member Author

@dwainm dwainm commented Jan 22, 2015

@noob1211 , I opened this ticket as I had an issue on one of the sites I worked on. The problem was that the url was generated by the users theme.

If you look into WC core you wont find URLs like these being generated so this is not something that should be fixed within WooCommerce but rather the code that generates the erroneous url.

@korobochkin

This comment has been minimized.

Copy link

@korobochkin korobochkin commented Feb 2, 2015

I understand what happening with "/cart?add-to-cart" and "/cart/?add-to-cart" (slash, redirects...) but in my WooCommerce this happening with and without slash :) With slash product added twice and without slash product added 4 times (2 x 2)! But this happening only when I use /store/checkout/?add-to-cart. With /store/cart/?add-to-cart all fine. Any ideas or suggestions?

Seems like WooCommerce doing something before open checkout page (maybe look at cart page or something).

Updated: I also have absolutely identical site on local server and I have this bug only on production server. What is going wrong...

Updated 2: Find another ticket about this issue. #1611

@anuppandey

This comment has been minimized.

Copy link

@anuppandey anuppandey commented Apr 27, 2017

This is how I fixed it for www.semipreciousWholesale.com - I changed the static page selection to none.
fixed2itemstocart

@RumenGeorgieff

This comment has been minimized.

Copy link

@RumenGeorgieff RumenGeorgieff commented Dec 15, 2017

I fix this adding / (slash) before ? e.g. https://site.com/url/?add-to-cart=id not https://site.com/url?add-to-cart=id

@cuddleclones

This comment has been minimized.

Copy link

@cuddleclones cuddleclones commented Feb 7, 2018

I'm adding a variation product via ajax to "/cart/?" and still getting the item added twice as well. Any solutions out there for variations ids?

@mikebronner

This comment has been minimized.

Copy link
Contributor

@mikebronner mikebronner commented Feb 23, 2018

I've seen this problem related to WooCommerce Pricing Tables as well. If you add an item to the cart, then click the View Cart link in the confirmation message, it adds a second item.

@anuppandey

This comment has been minimized.

Copy link

@anuppandey anuppandey commented Apr 4, 2018

oh GOD, this issue keeps coming back...even in latest Wordpress update not resolved. This is becoming like Magento!

@mikejolley

This comment has been minimized.

Copy link
Member

@mikejolley mikejolley commented Apr 4, 2018

It's not something WordPress will resolve; this is a problem on your site which probably didn't get resolved before. Check .htaccess to ensure it's not removing or redirecting to pages without end-slashes. WooCommerce cannot prevent your server redirecting.

@mikebronner

This comment has been minimized.

Copy link
Contributor

@mikebronner mikebronner commented Apr 4, 2018

Many of us are not using Apache, but running nginx these days, so .htaccess would have no effect. Any suggestions for resolving this issue on nginx?

@mikejolley

This comment has been minimized.

Copy link
Member

@mikejolley mikejolley commented Apr 5, 2018

Look at the server config/nginx equivalent? Thats even if it's the same issue; you can look at the browser dev tools to see if any of the resources on the page have add-to-cart query string appended, or see if there is indeed a redirect from slash/non-slashed versions of the page.

@Jeppeskovsgaard

This comment has been minimized.

Copy link

@Jeppeskovsgaard Jeppeskovsgaard commented Aug 20, 2018

An additional redirect was indeed causing the issue for me. Thanks @mikejolley.

@ricardo21ferreira

This comment has been minimized.

Copy link

@ricardo21ferreira ricardo21ferreira commented Aug 22, 2018

@RumenGeorgieff thank you. it does work.

@codegeek1001

This comment has been minimized.

Copy link

@codegeek1001 codegeek1001 commented Aug 30, 2018

Just adding my comment if it helps anyone. The redirect can also happen if you have http redirecting to https. So make sure in that case, you start with https in the url itself so it does not need redirection.

@garrettw

This comment has been minimized.

Copy link

@garrettw garrettw commented Nov 26, 2018

I don't think that can be worked around HOWEVER, our internal functions for generating add-to-cart urls always use the permalink. Permalinks have a trailing slash. This means the only time you'd get /cart? is if you had some code removing trailing slashes, or you had some external code creating that add to cart url.

"Permalinks have a trailing slash" is an assumption that is not reliable, because WordPress allows me to use a permalink structure that omits it. I had this issue on a site I'm working on -- so I had to add a trailing slash to my permalink structure just to make WC happy so that WP would stop redirecting from /cart/?... to /cart?....

@robrousejr

This comment has been minimized.

Copy link

@robrousejr robrousejr commented Mar 20, 2019

For those of you still having issues, I have found a fix to this.
Make the link like this --> https://example.com/cart/?add-to-cart=id&quantity=1

This verifies that the cart's quantity will only be one for that item, and also redirects you to the cart. It worked for me and hopefully this helps any of you out that still have this problem.

@stevefurley

This comment has been minimized.

Copy link

@stevefurley stevefurley commented Apr 17, 2019

I tried adding the quantity and that didn't seem to have an effect, but @garrettw idea with the URL worked great.

I changed this
https://example.com/cart/?add-to-cart=id&quantity=1
to
https://example.com/cart?add-to-cart=id&quantity=1

Just removing the slash after cart did the job.

@fahadrana31

This comment has been minimized.

Copy link

@fahadrana31 fahadrana31 commented May 8, 2019

Hi,
I got this issue just now and i see this post when i was finding the solution so i thought to share the solution with you people
The problem we are facing by not adding shop or store in the url. Let me give you an example:
My url was
https://abc.com/checkout/?add-to-cart=od&quantity=1
and it was adding 2 products simultaneously but when i add "shop" in the url it started working fine
https://abc.com/shop/checkout/?add-to-cart=id&quantity=1

So try adding shop or store whatever url you are for your website.

Thanks :)

@ArnoutPullen

This comment has been minimized.

Copy link

@ArnoutPullen ArnoutPullen commented May 24, 2019

The solution for me was a little bit different, but it was also a redirect caused by a double slash '//'
Link:
https://example.com//?add-to-cart=product_id&quantity=quantity
Redirect to:
https://example.com/?add-to-cart=product_id&quantity=quantity

PS: if your using Chrome goto DevTools->Network, turn on preserve log. Then you can see if your being redirected.

@lucasmshepherd

This comment has been minimized.

Copy link

@lucasmshepherd lucasmshepherd commented Jul 10, 2019

I was able to fix this by TURNING OFF "Redirect to the cart page after successful addition" under WooCommerce > Settings > Products

Hope this helps someone else. Toodles.

@aaron843

This comment has been minimized.

Copy link

@aaron843 aaron843 commented Nov 1, 2019

5 years later, still broken.
None of the suggestions above have helped me!

@garrettw

This comment has been minimized.

Copy link

@garrettw garrettw commented Nov 1, 2019

@mikejolley could you address my comment from a year ago as well as some other since that time? and maybe reopen this?

@cesgarma

This comment has been minimized.

Copy link

@cesgarma cesgarma commented Nov 6, 2019

I am having the exact same issue. I tried all the alternatives mentioned here without success.

@marcurares

This comment has been minimized.

Copy link

@marcurares marcurares commented Nov 11, 2019

Had the same issue and read the entire post looking for an answer.
I made it work finally and came back here to announce how, in case anyone still needs it.
At first, I made the Add to cart Buttons like "
https://example.com/?add-to-cart=product_id&quantity=quantity", and it had that automated 2 product error that got me pulling my hair for a while.
The reason I was using this link was to be able to customize the product page on a woocommerce website. The problem got solved when I used the standard woocommerce product page. The quantity input worked fine and i got the exact amount of products in the cart everytime. So I simply opened the Quantity and Add to Cart element in Inspect element and copied the entire html code of that particular element. And it was something like:

		<div class="quantity">
			<label class="screen-reader-text" for="quantity_5dc9b23d9b5aa">product quantity</label>
	<input type="number" id="quantity_5dc9b23d9b5aa" class="input-text qty text" step="1" min="1" max="1000" name="quantity" value="1" title="Qty" size="4" inputmode="numeric">
		</div>

	<button type="submit" style="margin-top:20px; margin-left: 22px;" name="add-to-cart" value="1066" class="single_add_to_cart_button button alt">Add to cart</button>

		</form>

Then I used it in my customized product page and it worked fine. The thing is that every product has a different id. In this case "quantity_5dc9b23d9b5aa". So i had to do it for each product. Luckily i only had 8. :)
Hope this helps.
Anyway, wordpress is a magical place where all the impossible errors happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.