Allow product variations to be added to cart via a query string #2126

Closed
lukemcdonald opened this Issue Jan 3, 2013 · 4 comments

Projects

None yet

4 participants

@lukemcdonald

Is it possible to add a product with a specific variation to the cart via a query string? Essentially, allow the creation of custom links for products variations.

Use Case 1:

A pricing table on the single product page where each variation has a custom "Add to cart" button.

Use Case 2:

Allow users to purchase a specific product variation from via an email link, tweet, or other marketing strategy.

I've tried various query string arguments to achieve what I'm after but in the end I can only get the product added to the cart and not with a specific variation. With that said, I can get the product and a variation added to the cart when using $woocommerce->cart->add_to_cart().

@mikejolley
WooThemes member

It's possible in 2, however, it can get complex because it requires valid options being set for the variation (which is required unless you want fraudulent attempts).

This would work:

?add-to-cart=1175&variation_id=1184&attribute_pa_size=x-large&attribute_pa_colour=white

If you didn't want to include all the variables in the querystring, a custom form handler could instead be used (letting you call the add to cart function yourself).

@mikejolley mikejolley closed this Jan 3, 2013
@lukemcdonald

Thanks, Mike, I'm glad to hear it's possible! I had been working with WC 1.6 until recently when I was told about WC 2.

@broncha

For some reason this is not working for me. Here is the URL $variant->add_to_cart_url() is returning.

http://localhost/chilli/?variation_id=3113&add-to-cart=2562&attribute_pa_size=m

but it does not add that item to cart..

@sandeepkapil

use http://localhost/chilli/?variation_id=3113&add-to-cart=2562&attribute_size=m

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment