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().
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:
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).
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.
For some reason this is not working for me. Here is the URL $variant->add_to_cart_url() is returning.
but it does not add that item to cart..