Posted on

WooCommerce Custom “Add to Cart” URLs – The Ultimate Guide

Here’s how to create custom WooCommerce Add to Cart buttons – and make their link add products to cart, redirect to specific pages, include variable and grouped products and so on. You will see that with this guide it’s much easier to place Add to Cart buttons on any page you like such as custom landing pages, or even create custom buttons in your pricing tables – enjoy!

WooCommerce: Master Custom Add to Cart URLs
WooCommerce: Master Custom Add to Cart URLs

Simple Products: Add to Cart URL

The easiest of them all, simple products are super easy to add to cart via a custom URL. Simply find the product ID by hovering onto the product title under WooCommerce > Products (see image below), and then use the following links.

Find WooCommerce Product ID
Find WooCommerce Product ID

URL: Add One Simple Product to Cart

href=”http://yourdomain.com/?add-to-cart=25″

Now, make sure to change the domain name in the link, and the button will work out of the box. 1 product with ID=25 will be added to cart.

URL: Add One Simple Product to Cart with Quantity = 3

href=”http://yourdomain.com/?add-to-cart=25&quantity=3″

1 product with ID=25 and quantity = 3 will be added to cart. Note: you can’t add 2 different products to cart with a URL.

URL: Add One Simple Product to Cart & Redirect to Cart Afterwards

href=”http://yourdomain.com/cart/?add-to-cart=25″

Remember, if you’ve changed the URL for the cart, make sure to change “/cart/” into “/basket/” for example. For this to work you must also tick the “Enable AJAX add to cart buttons on archives” option under WooCommerce –> Settings –> Products -> General.

URL: Add One Simple Product to Cart & Redirect to Checkout Afterwards

href=”http://yourdomain.com/checkout/?add-to-cart=25″

Remember, for this to work you must tick the “Enable AJAX add to cart buttons on archives” option under WooCommerce –> Settings –> Products -> General and also disable “Redirect to the cart page after successful addition”:

WooCommerce: Disable Redirect to Cart
WooCommerce: Disable Redirect to Cart

URL: Add One Simple Product to Cart & Redirect to Any Page Afterwards

href=”http://yourdomain.com/your_custom_page/?add-to-cart=25″

Remember, for this to work you must tick the “Enable AJAX add to cart buttons on archives” option under WooCommerce –> Settings –> Products -> General and also disable “Redirect to the cart page after successful addition”.

Variable Products: Add to Cart URL

Here things get complicated. Variable products have 1 or more attribute, and possibly a quantity as well. Together with finding the product ID, you will also need to find the variation ID, the attribute NAME slug and the attribute TERM SLUG.

Sounds Japanese? Here are the screenshots:

WooCommerce: find Variation ID
WooCommerce: find Variation ID
WooCommerce: Find attribute Name Slug
WooCommerce: Find attribute NAME Slug
WooCommerce: find Attribute Slug
WooCommerce: find Attribute TERM Slug

Once you have the Product ID, the Variation ID and its specific attributes, you can then use the following.

URL: Add One Variable Product to Cart (with 1 attribute only)

href=”http://yourdomain.com/?add-to-cart=47&variation_id=88&attribute_pa_colour=blue”

We’re adding here Variable Product ID 47, and specifically its variation ID = 88 where the colour attribute is equal to blue. Kinda complicated but once you play with them it gets easier 🙂

URL: Add One Variable Product to Cart (with 2 attributes)

href=”http://yourdomain.com/?add-to-cart=47&variation_id=88&attribute_pa_colour=blue&attribute_pa_size=m”

We’re adding here Variable Product ID 47, and specifically its variation ID = 88 where the colour attribute is equal to blue AND the size attribute is “M”

URL: Add One Variable Product to Cart (with 2 attributes and Quantity = 3)

href=”http://yourdomain.com/?add-to-cart=47&variation_id=88&quantity=3&attribute_pa_colour=blue&attribute_pa_size=m”

You can also redirect to Cart, Checkout and another page in the same way we’ve seen for the simple product page:

URL: Add One Variable Product to Cart & Redirect to Cart

href=”http://yourdomain.com/cart/?add-to-cart=47&variation_id=88&attribute_pa_colour=blue”

URL: Add One Variable Product to Cart & Redirect to Checkout

href=”http://yourdomain.com/checkout/?add-to-cart=47&variation_id=88&attribute_pa_colour=blue”

URL: Add One Variable Product to Cart & Redirect to Any Page

href=”http://yourdomain.com/any-page-url/?add-to-cart=47&variation_id=88&attribute_pa_colour=blue”

Grouped Products: Add to Cart URL

I recently worked with Grouped Products and my task was to add it to cart via a custom URL. A grouped product is a combination of two or more sub-products, and each one can be added with a custom quantity to cart.

WooCommerce Grouped Products
WooCommerce Grouped Products

So, here are the custom links.

URL: Add a Grouped Product to Cart

You will need the Grouped Product ID, which can be found in the usual way, and also the sub-product IDs. Then, use something like:

href=”http://yourdomain.com/?add-to-cart=3111&quantity[1803]=5&quantity[1903]=2″

In this case, we’re adding Grouped Product ID = 3111, and specifically we’re adding 5x product ID = 1803 and 2x product ID=2.

Note: if you want to add “zero” for one of the sub-products, you still need to specify that i.e. &quantity[1903]=0.

Conclusion & References

Have any other custom URL to add to this blog post? Leave a comment below and I will update it 🙂

Finally, thanks so much for the inspiration to:

Where to add this code?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such delicate files - if you need more guidance, please take a look at my free WooCommerce Customization video tutorial.

Does this snippet still work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free videos, tutorials and tips!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP
  • woocommerce-customize-shop-page-PHP
  • woocommerce-advanced-customization
  • how-to-edit-woocommerce-cart
  • woocommerce-customize-checkout-page-PHP
  • woocommerce-email-customization
  • woocommerce-conditional-logic

Rodolfo Melogli

Author, WooCommerce expert, WordCamp speaker and Internet marketer, Rodolfo Melogli has worked as a WooCommerce freelancer since 2011. He helps entrepreneurs and developers overcome their WooCommerce nightmares :) Rodolfo is the organiser of WordCamp Dublin, the Dublin WooCommerce Meetup, the Dublin Ecommerce Meetup and the Dublin WordPress Meetup. He enjoys interacting with people, travelling and chasing tennis & soccer balls. Of course, he loves pizza too.

227 thoughts on “WooCommerce Custom “Add to Cart” URLs – The Ultimate Guide

  1. Wow, this is exactly what I was looking for, I can’t believe I stumbled on it so easily. I wanted to use Thrive Architect to build landing pages with “add to cart” buttons and redirecting to the checkout page. YOU gave me the answer right away, and I’ve not even really begun digging into this article. As I reached the bottom of this page in order to pen this comment I see you’ve got lots of fans and a bunch of WooCommerce videos. Consider me a fan for life, now let me get back to reading the rest of your article, I have a feeling I’m going to learn a lot more, THANK YOU!

    1. Ah, that’s awesome, thank you Andrew 🙂

  2. I entered this code and URL to my landing page built on Unbounce.com and all works well, except instead of adding one product to the cart, it adds a quantity of 2 units. I have double checked to make sure I copied the right parameters, but it’s still adding 2 to the cart.

    Also is there a way to add a drop down variation selection add to cart button?

    Thanks for your support and guides they have been extremely helpful!

    1. Hello Brit, thanks for your comment! Please check previous comments 🙂

  3. I can’t access this: “you must tick the “Enable AJAX add to cart buttons on archives” option under WooCommerce –> Settings –> Products -> Display and also disable “Redirect to the cart page after successful addition”

    The Display options are different on my theme (X theme). Is there a way around this?

    1. You’re right 🙂 They’re now under WooCommerce –> Settings –> Products -> “General”

  4. Um using the Grouped Products Click url to add multiple items with different qtys to cart… (href=”http://yourdomain.com/?add-to-cart=3111&quantity[1803]=5&quantity[1903]=2″) …and its been working great. however, I created one that has 14 different item #’s in it and its now giving me (HTTP ERROR 503) page load error but still adding to the cart. any suggestions? is 13 different item #’s the max for a URL string like this?

    1. Not sure Brandon 🙂

    2. Do you know of any other ways to do this?

    3. Maybe you could just increase your WordPress memory: https://docs.woocommerce.com/document/increasing-the-wordpress-memory-limit/#

  5. Excellent tutorial. Unfortunately, for some reason none of these snippets work on my site (and I came here because none of the standard WooCommerce shortcodes work either). I’ve tried turning off all other plugins etc, but nothing makes a difference. Could this be a problem with a theme or is there something I’m overlooking, something I have to ‘switch on’ first to make this work. In every other way my WooCommerce setup is working perfectly, just no shortcodes working and, now, none of your excellent additions either.

    Any suggestions greatly appreciated!

    1. Hey Pat, thanks for your comment! What “Add to Cart URL” are you using that is not working?

  6. What if I want to add to cart with a different price than the product has? How can achieve this?
    Thanks,

    1. Hey Alfonso – thanks so much for your comment! This is not possible with pure HTML 🙂

  7. Great post!

    I have the same problem with the product getting added twice using http://domain.localhost/my-page/?add-to-cart=750 and ajax enabled on a custom page. Actually I think WooCommerce is trying to add it 3 times, because WooCommerce prints out 2 notices in the top, telling me that I cannot add more of this product to the cart (my product only allows 1 purchase of this product because it’s a subscription product).

    I’m working in a local environment with no caching. Something is causing the product to be added twice. Could it be, that WooCommerce attempts to add it for the current page as well as the destination page when it loads, which results in 2 add to cart actions?

    1. Hey Jeppe, thanks so much for your comment! Did you try disabling Ajax and/or enabling redirect to Cart?

  8. Thank you for this post. I am calling your add_to_cart urls via ajax. The minicart does not update though. If I go to the cart, I can see that the product is added. How can I update the minicart?

    Thank you

    1. Hey Hasan, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  9. Hello Rodolfo,
    I want to place multiple variation in cart using url query string. i am trying using like : yourdomain.com/cart/?add-to-cart=110&variation_id=490&variation_id=491&quantity=1&variation_id=492&quantity=2 but it doesn’t work for me. can you please give me any suggestion for that. How can i add multiple variation in cart using url query string? thanks.

  10. You’ve said that we CAN’T add more than one product to cart using the url method.
    Here is a link to an article that shows how we can. Would however require you first add a code snippet to functions.php Cheers!

    https://dsgnwrks.pro/snippets/woocommerce-allow-adding-multiple-products-to-the-cart-via-the-add-to-cart-query-string/

    1. Hey Sam! Correct, you can’t add to cart multiple products with “pure HTML” 🙂 You will indeed need to use a PHP function similar to the one described in the article (which hasn’t been updated in 1 year, hopefully it still works?). Thanks for sharing!

  11. Hey is it possible to add to cart the same variable product twice, but with different variations? So if someone has selected left and right, to add the product twice with the different variations and quantaty.

    Thank you

    1. Hey Ivan, no that’s not possible with pure HTML

  12. Hello, thanks for this amazing tips.

    I tried this on my website. When visitor click on a button, i redirect to another offer product page created with page builder (Brizy).

    I noticed theres a line of warning error on top of the page. I dont know why.

    Thanks for advance.

    1. Hey Zul, thanks for your comment! Did you fix this? How?

  13. Excellent! You sir are a Woo Com Wizard…

    1. Thanks for the “wizard” John 🙂 Thank you!

  14. HI, thanks fot the post, is it possible to have a quantity picker beside the add to cart button to let the user select the quantity before adding to cart? I know this might not be so possible with html but if there’s a post you can point me to, i’l be glad. Thanks

    1. Hey Babatunde, thanks for your comment! No, it can be done with pure HTML, sorry 🙂

  15. Thank you so much for sharing!! this helps heaps!!!

    I have a question, its it possible to have 2 different products in one ‘add to cart link?’ So two different products (that i set) will be added to the cart whenever anyone clicks the link?

    I thought it could be something like this perhaps, but not working?
    /cart/?add-to-cart={1234}={2345}

    Thanks once again!

    1. Hey Sam, thanks so much for your comment! No, it’s not possible 🙂

  16. Sir Rodolfo Good day I would like to ask is how to add multiple individual products in woocommerce cart using the add to cart URL the products.

    1. Good day Luke! No it’s not possible 🙂

  17. Hi, great article.

    It seems though when utilizing one of these URLs the cart page that it leads to does not allow you to then remove the item from the cart. If you then refresh using the normal “domain.com/cart” you are able to, but not under the “add to cart” url. any ideas for a workaround?

    1. Hey Aaron 🙂 I tested on my end and I can correctly remove the item. Try doing some troubleshooting: https://businessbloomer.com/woocommerce-troubleshooting-mistakes-to-avoid/

  18. This was awesome and just what I needed! Thank you for the detailed guide, it works great!

    1. Excellent 🙂

  19. OMG, thank you thank you thank you!!!

    1. 🙂

  20. Great article Rodolfo however I want to add a simple product to cart together with a subscription product that has a coupon. Kindly show me how. Thank you

    1. Hey Olufemi, thanks so much for your comment! With the HTML method you can only add one product to cart, sorry 🙂

  21. This is awesome! Thank you for the great article.

    It works perfectly on desktop. However, the add to cart button does not work on my mobile web page (it leads to ‘cannot find this page’ page). Does this happen to anyone else?

    Many thanks,

    Yuan

    1. Hey Yuan, thanks so much for your comment! This should work on all devices 🙂

  22. I have added custom link as you mentioned but there is a issue. After Adding to Cart, url remains same and comes at top of page. So if i refresh then it is adding one more time.

    Means it is not working properly, What to do? Waiting for your reply.

    1. Hey Jats, thanks so much for your comment! Unfortunately there is no pure HTML solution to this – you’ll need to use PHP instead 🙂

  23. Wow, I’m so GLAD I found this article. Helped me a lot with some custom woocommerce buttons, thanks for sharing.

    1. Awesome 🙂

  24. I’m from Germany and don’t like the englisch URL: “/?add-to-card=”.
    I would like turn in into something german like “/?in-den-Warenkorb=”

    How can i manage that Rodolfo Melogli ? 🙂
    Do you got therefore a tutorial yet?

    1. Hey Tobias, thanks for your comment and very good question! The public static function “add_to_cart_action” looks for “add-to-cart” in the URL, so you will need to override this in order to make your custom URL parameter work. Hope this helps 🙂

  25. Hey Rodolfo, thanks a lot for this guide. I’m looking for a Ajax short code usable in any page of WP. Because this AddToCart URL reload the page each time. If you have some idea.. Thanks. Rémi

    1. Hey Remi, thanks for your comment! There is no Ajax shortcode, however have you tried enabling Ajax from the Woo settings and using the default shortcode?

  26. Wow, this is such a powerful and detailed post. I’m in the process of creating my own buttons and this is super supportive. Thank you.

  27. Hi there,

    I’m using woocommerce membership to sell 3 different memberships as products and I’m using price boxes on the homepage with a subscribe buttons which should take to the checkout page so I took the Id of the products that are tied to the memberships and created the link for each subscribe button. It works but after clicking the button it takes me to the checkout page but it adds the membership twice and if I go to the home page (or any other page) immediately, it adds one membership more to the cart. How can I solve this problem and get just one membership added to the cart?

    1. Hey Jonathan, thanks for your comment! I suggest to scroll through the previous comments, as if I recall well someone was having the same problem. Let me know 🙂

  28. hey!
    can i add to my link (http://www.___/?add-to-cart=33&quantity=3) more info like costumer name and address ?
    i whould love to chat with you by email if you can see my mail from the comments!
    any way this was very helpful

    1. Hey Shachar, thanks so much for your comment! Technically you can, however you will need to encrypt them as passing personal data via an URL is not good practice 🙂

  29. Hey Rodolfo,

    Great post! Is it possible with the same code structure to create an “Add to cart” URL but instead of limiting by a specific ID, use it for any product that is returned via the Page Results (from the search functionality)?

    Thanks!

    1. Hey Giuls, thanks so much for your comment! I’d say that’s impossible 🙂

  30. Thanks! This article gave me all the answers I needed to get a great redirect URL to my cart, as well as apply a coupon code! Thanks so much!

  31. Hi Rodolfo,

    The custom code worked great for simple and variant products. However it does not work for bundles. I have product bundles where 1 of the 2 products in the bundle has 2 variants. I tried using variation_id[1234]=4321 where 1234 is the product id of the product with 2 variants. This does not work. Is there a different way to handle bundles (not groups)?

    Thanks!!!

    1. Hey there, thanks so much for your comment! This 100% depends on the Bundles plugin you’re using, you’d better ask their support as I have no idea I’m afraid 🙂

  32. or is it possible.. I setup multisite network with two different domains with domain mapping.

    And user add products in cart on one website and make payment on other… while have both websites in multisite network.

    Thanks

    1. Haseeb, thanks so much for your comment! Yes that’s possible but you’ll need a plugin or custom code, HTML is not enough in that case 🙂

  33. Hi Buddy

    Is it possible … I add products to cart on one website of mine… and when clicked to check out button it redirect to other website of mine and make payment there?

    Thanks

  34. Great post, but not working for me; don’t know what I am doing wrong! 🙁

    I don’t know what I am doing wrong.. The product I wanted to be added to cart has an ID 80720. I applied this URL: url/?add-to-cart=80720; And nothing happened! I also tried the https version but it is not working at all. The page just redirected to the homepage. Can you please have a look and tell me what I am doing wrong?

    I want the customer to be able to add products to the cart by clicking the “Order” button showed on the table and eventually apply a discount automatically. Been trying many things for quite a few days but nothing works for me! 🙁

    1. Hey there, thanks for your comment! Is the product “simple” or not (“variable”, “grouped”, etc.)?

    2. For the url to work, you need to add your domain at the front, so in your case it would be
      https://www.yourdomain.com/?add-to-cart=80720

    3. Hi,

      Did you found a solution to your issue?

      I experince the same.

      The product is set as “simple”

  35. Hello,
    I have 2 sites one of which is a duplicate of the 1st site, lets say site1 & site2.
    Please can you tell me is it possible to add a simple code so that when a visitor presses add to cart button on site2 it simply adds the product to the cart on site1 whilst redirecting user from site2 to site1 also.
    I have been looking all over for a solution for this and not having much luck, I do hope you can help.
    Thank you.
    Kind regards,
    Lee

    1. Hey Lee, that’s not possible. Why 2 duplicate sites if I may ask?

  36. I need to find the right word to thank you. This is so helpful.

  37. Thanks for this great resource. I’m having similar issue where the checkout is populated with 2 items, even if I specify quantity as “1” or even “0” – I looked through the other posts, but couldn’t find a clear solution. Can you help? Thanks again for this great resource!
    – Gary

    1. Thanks for your comment Gary! Did you look through the comments?

    2. When doing this be careful with http and https or when you click add to cart 2 products will be added in the cart.

  38. Hi 🙂

    I created a page where I put into some php-code sniplets where a user type in an id and then he will see some image. Now I want to create a add to cart button.

    I create a blank product with the price of the image but without anything else.

    Now my question: is it possible to create a button to add this product to cart and to checkout. But with a custom field or something what can place into some free text? (the free text I have a shortcode, with an echo $var that place the free text I need) But this free text must be shown inside the basket and the order itself.

    Is that possible?

    1. Hey Felix, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  39. Hi, Last December I used your very helpful code to have teams pass in a team number via URL so that they didn’t type it wrong (which had been happening quite often with digits transposed) which would then be passed along with the product so that I could credit the team with paying their registration.

    Unfortunately, I went in to create a 2017 version of the product and this URL ?add-to-cart=2669&variation_id=2672&quantity=1&attribute_team_num=4619

    I had it working last year and trying to figure this out and remember how to set this all up again. I tried to create a new variable product but need to have basically a large range of team number attributes (between 1 and 100000) and then use your URL magic to get this added to cart. Is there any pointer on how to create the product side? I am struggling to figure this out and would greatly appreciate even knowing how to find the information.

    Thanks, Jill

    1. Jill, I’m not 100% sure here, more research would be needed on my side. You’d need to create all possible variations or maybe have PHP “get” the “attribute_team_num” from the URL and do something with it (probably better).

  40. Hey Rodolfo

    I’m wondering if you’ve even come across a plugin that creates buttons automatically from the product variants (in my case just two per product) and then uses ajax to add 1 per click (like the WP Pizza does)?

    If you haven’t, then can you advise how would be the best way to go about creating this?

    1. Tony, thanks so much for your comment! I haven’t come across it but yes, this is possible – unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  41. how to add two variable product at once with url

  42. Same problem here with bundled product

    ?add-to-cart=4652&attribute_pa_autorizzo_privacy_konsumer=si&variation_id=4685

    Works with the child product instead:

    ?add-to-cart=4534&attribute_pa_autorizzo_privacy_konsumer=si&variation_id=4685

    1. Awesome, thanks for that 🙂

  43. Hi sir,
    I want a custom button on custom page which I want to disable if that product is out of stock. Is it possible?

    1. Anjali, thanks so much for your comment! No that’s not possible with pure HTML.

  44. Hello,

    Very nice article extremely useful. Works like a charm. Only one small bug. It the user hits back button and then accesses the link again. The same product is present twice.
    How can we check if the cart is empty and if it is not empty all products will be deleted and only the custom product added?

    In my case I only need one product when following the link

    1. Razvan, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  45. Thanks for the great easy steps to custom add to cart

    1. You’re welcome 🙂

  46. Hello, thanks for this amazing plugin.

    My “Add to Cart” buttons are working on the shopping pages but they DONOT work when I view an item. Any idea what may be wrong?

    1. Imrana, thanks so much for your comment! Unfortunately this is custom troubleshooting work and I cannot help here via the blog comments. Thanks a lot for your understanding! ~R

  47. Hi,
    I woocommerce i have to multiple product add in to cart by click add to cart button using product id .
    How we doing multiple product add at one click?

    1. Thanks for your comment Deepak! You can’t do that I’m afraid 🙂

  48. I am stuck to get cart URL for the single product. This post really helps me a lot.

    1. Hey Darshan, thanks for your comment! Could you try explain this again, as I don’t fully understand? Thanks a million 🙂

  49. This is just what I needed, but I have some strange fluke that is happening. If you go to our initial sales page and click the yellow button it is supposed to add one item to the cart and go to the next page in the funnel. It adds 2 items.

    I have tried various product ids and even setting the quantity in the link url. The buttons on the following pages all add just 1 item (as the should).

    Any ideas on what can cause this?

    1. Hey Matt, thanks for your comment! Try reading the other comments, I remember someone had the “2 items” added to cart problem already 🙂

  50. Thanks for this great post.
    Unfortunately, this method doesn’t seem to work with the lang=en tag..
    gymperformance.ch/checkout/?add-to-cart=10331/?lang=en
    Any idea how I can solve this issue?

    1. Hey Blättler, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

    2. Multiple ? marks – try:

      —example.com—/checkout/?add-to-cart=10331&lang=en

  51. Thanks for writing this all out. I am trying to add to cart and redirect to a custom url using the url: https://_____/about-us/?add-to-cart=4951

    The problem is that it just takes me to the cart. I do have AJAX links enabled.

    1. Sorry, Still had the go to cart checkbox enabled. Works great! Thanks!

  52. Just noticed that as of today my custom add to cart buttons are not working anymore. Could this be as a result of woocommerce updates? I used to have working custom add to cart buttons. Right now, the only thing these buttons do is redirect me to the given page. They do not add the product to the shopping cart. Any ideas on how this could be fixed would be greatly appreciated. Thanks for your time!

    1. Alex, thanks for your comment! I just tested this again with Storefront theme and it works perfectly. Maybe your theme (or another plugin) is messing/conflicting with this?

      To troubleshoot, go to WP Dashboard > WooCommerce > System Status: what errors do you see in red font?

      Also, take a look at this tutorial to see how to troubleshoot: https://businessbloomer.com/woocommerce-troubleshooting-mistakes-to-avoid/

      Finally, can you try switching temporarily to “Twentyseventeen” or “Storefront” theme and let me know if it works?

      Hope this helps!

      R

  53. Hello,
    I have followed your instructions to add one Variable Product to Cart (with 1 attribute only), but after clicking the link, the user is being redirected to the site’s home page. Is there any method to update the cart without leaving the page from where the order has been made? I know I could add manually the URL of the original product page, but that would be quite a chore.
    Thanks for your help!

    1. Hey Diego, thanks so much for your comment! Using the product URL is your only choice 🙂

  54. I am relatively new to web design and finally got my client’s product “add to cart” URL to work as a button, but it is trying to add multiple quantities even though it can’t. At the top of the checkout page there’s a prompt that says “you cannot add another… to your cart” along with the “… has been added to your cart” underneath. Why is this happening and how can I fix it?

    1. Hey there, thanks for your comment! Please double check through the old comments on this page, someone else had the same problem and had to disable a specific Woo setting. Hope this helps!

  55. Hello ,
    In url I want to pass the product price and product name and product image and product description.

    Please help me

    1. Rav, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  56. Hello Rodolfo Melogli,

    i found two plugins that change the URL of the add-to-cart button link but they have a common issue, they do not redirect with ajax enabled!

    i though of exchange the add-to-cart button per product and leave the ajax handling on. Could you please release such a plugin or snippet?

    goal would be not to have extra buttons on page and use the buttons already come with WooCommerce.

    /**
     * Set a custom add to cart URL to redirect to
     * @return string
     */
    function custom_add_to_cart_redirect() { 
        return 'http://www.yourdomain.com/your-page/'; 
    }
    add_filter( 'woocommerce_add_to_cart_redirect', 'custom_add_to_cart_redirect' );
    
    1. I’ll think about it – thanks Tobias 🙂

  57. This is great, thanks! Is it possible to redirect to a specific anchor within a page as well? Adding to the cart works well, though it brings the user to the checkout and skips our 2nd step. Is it possible to add the anchor (#addons) somewhere within the URL? I think I’ve tried every location, but maybe I’m overlooking something. Thank you!

    1. Thanks for your answer Rodolfo,

      But unfortunately in Firefox 63 adding the anchor at the end of the passed variable link doesn’t add the product to the cart. It only goes to the anchor. Example:

      http://mysite.com/my_page/?add-to-cart=1020#my_anchor
    2. Dan, thanks so much for your comment! Unfortunately this looks like custom troubleshooting work and I cannot help here via the blog comments. Thanks a lot for your understanding! ~R

  58. Hi Rodolfo, thanks for this great information. It’s there a way to include a discount coupon in a url that directly goes to the cart with a specific product?
    Thanks in advance.
    Cheers!

    1. Cristian, thanks for your comment! No, not possible via HTML, you will need PHP in that case.

  59. Do you know of a way to add a class to the Add To Cart “a” element (link) if the product is out of stock? Basically, I am trying to add an “oos” class to product links, if that product is out of stock. Then I can style those links differently.

    1. Jon, thanks for your comment! You will need PHP for that I’m afraid 🙂

  60. Hi Rodolfo,
    it is always nice to read your guides and website.
    I have a question regarding the “add to cart” URL. I followed your tips and everything works nicely with one exception.
    The confirmation message that the product has been added to the cart DOES NOT appear on same page where the custom button is but elsewhere (in the cart page, or in other pages)…

    “Enable AJAX add to cart buttons on archives” is selected and “Redirect to the cart page after successful addition” not.

    I would appreciate your help!

    Thanks

    Claudio

    1. Claudio, thanks for your comment! The HTML add to cart URLs must redirect to somewhere I’m afraid. Otherwise you need custom Ajax. Sorry 🙂

  61. Hello Rodolfo,

    I am unable to setup the add to cart option on a third party plugin. The issue is that when we click on “add to cart” button it opens a new page instead of adding the product on the same page. Is there anyway to fix this issue?

    Many Thanks,
    Param

    1. Param, thanks for your comment! Unfortunately HTML can only redirect to a new page. You will need some custom Ajax work instead.

  62. Thanks for the well written article and your tutorials are always awesome, I have a question, how to clear parameters after the url is redirected to the desired page, because when people refresh in case the page does not load or its slow, every time they refresh product quantity is increased by 1, so how can i resolve this issue and is there a way to clear the parameters after the redirect happens.

    1. Not sure Ram, I don’t think this is possible. You’d have to remove this sitewide and this could mess things up

  63. Great article!

    But I have a question, what if I want to show a specific variation of a product instead of adding it to the cart?

    1. Hey Manny thanks for your comment! You want to “show” a specific variation – does that mean you want to “link to” the specific variation?

  64. Hi, it’s possibile use the string like this
    http://yourdomain.com/?add-to-cart=25&quantity=3 and apply a valid coupon code in the url ?
    http://yourdomain.com/?add-to-cart=25&quantity=3&apply_coupon=“mycoupon” not work 🙁

    1. Hi Max, I’m afraid not (or, better, it’s not as simple as that) 🙂

  65. Great info,
    do you know how to do the same with product add-ons fields?
    I want to have a query string url pointing to a product page or checkout page with data automatically populated into product personalization fields like engraving or text print on a product.
    I’m using the woocommerce product add-ons plugin to create the product personalization fields.
    Thanks,

    David

    1. Hey David, thanks for your comment! Have you tried asking the plugin’s support team?

  66. Thanks for this article!

    I am attempting to get a group product added to cart with the 3 items in it to each add only 1 item, but I cannot get it to work following your guide.

    1. Tyler, thanks for your comment! What is the add to cart URL you’re trying with?

  67. Hi, thank you for that article. It is very usefull to me and all works for me.

    I have a quastion…
    Is it posibble to send a customer details too? Like first and last name, email, address etc.

    If yes, it will be amazing!
    Thanks (=

    1. Hey David, thanks for your comment! You can’t do that with just HTML – also, it doesn’t seem to me like the safest thing to pass sensitive information via a link 🙂

  68. Hi Rodolfo,

    Great article, if you don’t mind asking you a question?

    I’m having issues in Variable Subscription Product (WooCommerce Subscription) it’s not adding more than 1 product in the cart at the same time. Though in local environment it seems to work fine but not on our server? Any idea why?

    What’s happening is when as a customer we try to add multiple products then the recent product gets replaced by the previous product which was added into the cart.

    Would appreciate your help.

    1. Hey Patrick, thanks for your comment! It might be you can only have 1 subscription in your cart maybe?

  69. Thanks for the guide, very useful – Just thought I’d share a solution to a problem I noticed a few people are having in the comments in that the /cart/?add-to-cart=XX url results in items being added to the cart should the page be refreshed or through reloading due to alterations on the page.

    My solution was to create a blank ‘adding-to-cart’ page which I point my links to and then on that page use the ‘Page Links To’ wordpress plugin to then redirect to the cart – this eliminates the instruction to add to cart from the url.

    1. Hi Andrew! Thanks for your advice. I’m a bit puzzled how this helps – the URL for the new page uses the same as the original link and so if I go back and forth it still adds a new product each time…. I’m probably using it wrong though so would appreciate your advice 🙂 Thanks!

    2. This works really well. Here’s the step by step.
      1. Install the “Page Links To” plugin. After activating it, you’ll see the controls for it at the very bottom of your page or post creation page.

      2. Create a blank page with the slug “adding-to-cart”. Using the “Page Links To” controls, redirect that page to your cart page. http://www.yourdomain.com/cart/

      3. Set up your product link to look like: http://www.yourdomain.com/adding-to-cart/?add-to-cart=XXX

      That will add the item to the cart, send the user to the “adding-to-cart” page and automatically redirecting them to the regular cart page. Strips off the add to cart command and everything is clean.

      Really good fix, Andrew!

    3. Thanks Phil =)

    4. Hi Andrew and Phil,

      THANKS this looks like it works perfect if you simply want to go straight to the cart.

      I would like to go to a DIFFERENT page – i.e an upsell page.

      When I put the upsell page URL in the “a custom url”

      i.e “https://site_url/page_slug/”

      The folloiwng happens:

      1 – The item is added to the cart, but the page that is shown displays an error saying

      ” Sorry, but the page you were trying to view does not exist.
      It looks like this was the result of either a mistyped address or an out-of-date link”

      I have checked several times, but the page url and link are both correct.

      Do you have any ideas that might be of help?

  70. Very good tutorial. I’m just getting into WP and Woocommerce out of necessity. The necessity is that I can’t afford a proper web designer. I appreciate all the information you give and found the do’s and don’ts in your video to be invaluable.

    I do have a question. Is it possible to make woo php function call that adds a single product to the cart to the cart and returns a boolean (success/fail)? I want to add items from a schematic using mapped areas on the image and just allow the user to add a part to the cart and get a simple confirmation without invoking the product image and other stuff you get when using the woo shortcodes. The url method on this page works great but it navigates away from the current page which is not desirable. Any tips as which functions may be available would be appreciated.

    Tom

    1. Hey Tom, thanks for your comment! I’m afraid I can’t give premium support, but at least I can tell you you should look into the “Ajax add to cart” that already works on the shop/cat pages. In that case, a product is added to cart without a redirect – you could try to repurpose that coding in your special mapping tool 🙂

  71. Hello, Thanks for the content.

    But I have a question. Cause for me its is not working correctly. Here is what I am trying to do:

    I have a pricing table with one free test product and one paid product. For the free product they only need to klick on the Sign Up Button and thats it. Under the paid product Iwant the customer to add the product to the cart and go directly to the checkout. I enabled Ajax and disabled the redirection option to specify the URL for the Button I used http://my-url/checkout/?add-to-cart=1447

    When I cklick on the Button now I receive “This site can’t be reached” Error message from the browser. I am not really sure what I am doing wrong.

    1. Manuel, thanks for your comment! I have no idea I’m afraid, maybe re-check the syntax 🙂

  72. Hi Rodolfo

    I’ve noticed the following behaviour when using custom links:

    1/ Click a custom add to cart link. Product is successfully added to the cart.
    2/ Navigate to another page.
    3/ Go back (clicking your browser’s back button for instance)
    4/ Product is added to the cart again, because the URL includes the custom link query string.
    5/ Similarly, refreshing the page triggers the add to cart again

    This is really undesirable behaviour unfortunately. Any ideas how to strip the query string after Woo has successfully added the products to the cart?

    1. Anthony, thanks for this 🙂 I’m not entirely sure and cannot test this I’m afraid. My fix in this case is a simple HTML link so maybe PHP would be better in your case 🙂

  73. Excellent article. I am adding this function to my parent site. I have tested it with one product and it seamlessly goes to the cart page. Thanks for such a great article.

    1. Thanks for your feedback Waqass!

  74. Hello,
    First of all, thank you very much it was very helpful.

    But I have issue with quantity of pruducts in the cart. Quantity of product increasing by +1 every time the user applies the link – http://mydomain.com/checkout/?add-to-cart=722

    Can I some how restrict the quantity of products in the cart and no matter if he applies it couple of times? And every time that user applies link of product #1 or product #2 – the new product just will replace the last product that was in the cart?

    Thanks.

    1. Thanks for your comment Andrew! Someone had your same problem, take a look through the comments and you should find the fix 🙂

  75. Hi Rodolfo,

    thanks for such a helpful post ! Simply works on our store.

  76. Hi,
    First let me say this post was useful and just what i was looking for…

    I have 2 questions/issues im trying to solve, but cant get it right.

    #1. When i let say use this url to add to cart and jump to cart page afterwards, it all looks fine, but then when i click “go to checkout” button, on checkout page it adds aditional item quantity. Is there any way this can be fixed so no matter if client keeps refreshing page, going back and forth on checkout and cart page it wont add up if customer didnt do it on its own?

    #2. How could this URL thing be set to add let say 2 or more different products to cart with single link? I tried different options, but none of them works…

    thanks in advance

    1. Hey Dexter thanks for your comment! For #2, you can’t do that via pure HTML – you will need a PHP snippet to add multiple products. For #1, I’m not sure, some troubleshooting is required and cannot help here in the blog comments 🙂 Thanks!

  77. This is a great tutorial, thanks for taking the time to put this together 🙂

    1. Awesome, thanks Anthony!

  78. Hello Rodolfo,
    Thanks for your article!
    I add products on my website — https://actipulse.com/products/ , but after adding the product, it displays “quantity 2”. Do you know how to fix it? Many thanks in advance!

    1. Hey Maksym, thanks for your comment! I recommend to check previous comments, as someone else had the same problem last year. Let me know if you find the fix!

  79. Hello. very usefull tutorial indee.

    i’m trying to put in my shop page the custom add to cart buttom, i want to Add One Variable Product to Cart directly from the shop page, but those product have variations. my qyuestion is how i call at least one of these attributes or the default one to use it in the link and add the product to the cart directly from the shop page? can you help me with this?

    1. Hey Ramses, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here on the blog. Thanks a lot for your understanding! ~R

  80. Hello,

    i’m very new to WordPress and WooCommerce. Unfortunately, google can’t answer my question. I have created a few products. With the shortcode [add_to_cart id=”123″] one can insert a button on a individual page.

    Problem: If the product is out of stock, the button displays “read more” and links to the product page. I do not wanna use the product page or the shop page, because I just have a few products.
    What I need: If the product is out of stock, the button should change the color and text “sold out” and should not link to a further page.

    Do you have any suggestions?

  81. Hi,
    When i am trying to ad add to car short code for variables product with quantity so it does not consider quantity.
    [add_to_cart id=721 & quantity=150]

    1. Hey Om, thanks for your comment. You can’t add a variable product to cart with a shortcode. Try using my tutorial to create a URL, quantity will work then. R

  82. Hi,
    Is it possible to work without “id” ?
    I mean like this:
    BUY NOW

    Because i need to add that code above on my notification bar on EVERY Woocomerce products, so when visitor click that link they will redirect to Cart Page depending on the product they clicked. Is it possible?

    I don’t really know how to explain this.
    Sorry for my bad English, i hope you understand.
    🙁

    1. Hello Taufan, thanks so much for your comment! Yes, this would be possible with PHP (and not HTML), as you can “get the product ID” of the product you’re looking at and generate the HTML required. Unfortunately this is custom work and I cannot provide a complementary solution here on the blog. Thanks a lot for your understanding! ~R

  83. I am new with Woocommerce but i have to do this task for my client.
    I can add one item each time with ‘add-to-cart=34’ via ajax;
    But can i remove one item from cart without loading page?
    I know product can be deleted but i just want to delete single instance of one product with ajax. I could not get any help from google but i am expecting help from you.
    I will appreciate your answer.
    Thanks!!

    1. Hey Bilal, thanks for your comment! You can’t remove a product from Cart with a static HTML url – for that you will need a PHP function. Unfortunately this is custom work and I cannot provide a complementary solution here on the blog. Thanks a lot for your understanding! ~R

  84. Hi, first I want to thank you for your great article! I’ve on additional question: Is there a way to add client data via url parameters? I’ve a custom form which redirect an existing product to the cart. Now I also want to add the inputs of the name and e-mail field to the cart too 😉

    1. Hey there, thanks for your message! Yes, I’m sure there is a way (JQuery), but unfortunately I can’t code it here in the comments. Let me know if you find the solution! 🙂

  85. Hey,

    This works fine with a simple product but I can not get anything to work with a Variable Subscription (WooCommerce Subscription plugin) product.

    Any ideas?

    1. Hey Trent, thanks for your comment! Uhm, variable subscriptions should behave like variable products, no? Have you tried to use the special URLs for variable products already?

    2. Hello Rodolfo,

      Thank you for putting together this list as it has proven very useful. There does seem to be a difference for variable products vs variable subscription products. At least I have not been able to get the correct coding based off your tutorial. I identified the product, created the variable, created the attribute, and inserted the code as you showcased, but when the link is clicked it just reverts to the home page. How did you identify variable_pa_ in your search as perhaps this is changed? Here is the code that I created so far.

       https://www.thecybergarage.com/?add-to-cart=7403&variation_id=8234&attribute_pa_membership=one 
    3. Hey David, thanks for your comment! Are you using “global” attributes for those variations, which can be therefore be found under Products > Attributes?

    4. Straight to cart link format for variable subscriptions:

      domain.com/cart/?add-to-cart=24098&variation_id=24101&attribute_frequency=6+Weeks

      or

      Straight to checkout link format:

      domain.com/checkout/?add-to-cart=24098&variation_id=24099&attribute_frequency=2+Weeks

      Note: There is a setting for only one active subscription per user, which can help keep the cart in order should only one sub status be available to a user.

      Note 2: Capitalisation of the attibute value needs to match what you have set as the value

  86. Hi, thanks for the tips! Any idea what might be causing me to get this error (blue is a required field) on the Cart page where “blue” is my variant slug. This is my href:

    /cart/?add-to-cart=6033&variation_id=6068

    I have disabled all plugins except WooCommerce (Version 2.6.11) and have set the Regular price on each variant. I am certain that my product and variant IDs are correct.

    If I make it a Simple Product without variants and just use /cart/?add-to-cart=6033 it works great. Alternatively, if I can’t get the above to work I could use /cart/?add-to-cart=6033&attribute_pa_color=blue but that doesn’t seem to show the attribute name (blue) on the cart page… Any help would be appreciated.

    Best,

    Kevin

    1. Hey Kevin, thanks for your comment! If you read again the tutorial you’ll see that you need both variation ID and attribute name, this is the only way it will work. Let me know 🙂

  87. Was there an answer given how to fix a product being added twice? I disabled all plugins except WordPress and used Twenty Sixteen as the theme, but it still continued to add two.

  88. Hi Rodolfo,
    This was really helpful, thank you.
    An additional step though, is it possible to redirect to a linked website? So I have as a ‘page’, a link to an external site. I am setting up these add to cart buttons on this external website, and want to remain on it once added to the cart, despite the cart being on my main website.
    Is that possible?

    Thanks in advance.

    1. Hey Rebecca thanks for your comment! I’m not entirely sure here – is the external site a WooCommerce site as well?

    2. Sorry, I hadn’t noticed your reply.

      The external site is salon.io, a simple website builder.
      I am wanting to create a playable space, but which allows the user to buy individual products from there and keeps them playing (so they do not lose their arrangement of fragments).

      Currently, after an individual piece has been added to the cart, the user is directed to the home page of the official website, and has to find their way back to the play space to add more pieces.

    3. Hey Rebecca, no problem 🙂 You’ll need to ask this question to Salon, as in my opinion this is not possible to do. Sorry!

  89. Hello Rodolfo,

    Thanks a lot for this. Is there a way to programmatically add a variation product only using Product ID and value for the attribute? In our case, we have a page with known product IDs and whether the size is small or large (from user’s input). This needs to add product which is small or large programmtically – so we can reuse the same link (for the given product ID) and just updating the size attribute in the code.

    Many thanks in advance

    1. Hey Gee, thanks a lot for your comment. So, if I understood well, you would like to omit the “variation_id=” bit, is that right? Well, probably you can’t (have you tried?) and therefore this is not possible with plain HTML. Of course, this could be done via PHP instead, which can echo an add_to_cart link by looping through the variation_ids and finding the correct one. Hope this helps a little! 🙂

  90. Hi… How to add to cart a bookable product by url? (i’m using Woocommerce booking plugin)

    1. Hey Dave, thanks so much for your comment! I’m afraid I don’t own that plugin so I can’t help in this case 🙂 If you figure something out get back to me with the solution and I will add it to the post. Thanks for your understanding!

  91. Awesome article. Thank you!

    I have a situation where people may click on the link a couple of times before they buy. They may consider buying over a couple of days.

    In this case, the “add to cart” param adds additional quantity of the product each time they click. Or, if I limit to 1 per cart (with a Woocommerce product setting), then the user gets an error message saying they can only add 1. Neither are desirable.

    Is there a way to clear the cart if people click on a link containing add-to-cart? That would alleviate my issue.

    Also, is there a complete list of Woocommerce URL Parameters somewhere? I can’t seem to find one.

    Thanks a million!

    1. Hey Justin – you could try limiting only “1 item per cart”: https://businessbloomer.com/woocommerce-allow-1-product-cart/. Or control this at the single product level, where you can set the “sold individually” option.

      In regard to URL parameters, not sure what you mean 🙂 Let me know!

    2. Thank you. I do in fact limit to 1 item per cart already. The problem is when the user clicks the URL again, they get an error message that says something like “Only 1 of xx product can be added to cart.” It’s just not a great experience. Conversions drop when people see errors and warnings.

      As for URL Parameters, I’m referring to things like “?add-to-cart”

      I’m curious what other fancy functionality and variables you can pass with the URL. I assume there are more than just “?add-to-cart” but I can’t seem to find a list anywhere.

      Curious if you or others have seen one.

    3. Hey Justin, thanks for your follow up! The snippet https://businessbloomer.com/woocommerce-allow-1-product-cart/ will actually substitute the item in the cart without giving you error.

      As per the URL paramaters, uhm, that’s a very nice idea! I will do some research 🙂

  92. How to force the quantity of product to 1? The scenario is whenever user click the link that contain add-to-cart, it will add the order to the cart by 1. But I want user always get 1 product everytime they click the link regardless the number the click the link.

    1. Hey Tanakorn, thanks for your comment! Take a look at this other comment, it should help: https://businessbloomer.com/woocommerce-custom-add-cart-urls-ultimate-guide/#comment-15606

  93. Hi,

    May be a naive question, but where am I suppose to put the url/code? Does it go in the wordpress editor or functions.php or some other file?
    Thanks in advance.

    1. No problem whatsoever Ree, thanks for asking! These URLs can be used in your HTML (so, yes, in the WordPress editor usually), inside the tag, such as:

      <a href="your_add_to_cart_URL_here">Add to Cart!</a>
      

  94. Hi, I am using your technique and it works great. Now I have another obstacle. I am not using a shop (archive) page, I have just used custom links throughout my site to add products to the cart. But when the buttons are clicked, they reload the page and change the URL. I don’t want this to happen. I know about the “Enable AJAX add to cart buttons on archives” checkbox on the WooCommerce backend, but I don’t think it’s right for my problem as I’m not using the archive page. Any suggestions? Thanks!

    1. Hey Austin, thanks for your comment! What do your custom links look like? And what page do they send you to after reload?

    2. My custom links are just (the site url + ?add-to-cart= + product id). So they end up looking like (http://example.com/subdomain/?add-to-cart=7763). My goal is to not have the page reload at all, and add the item to the cart. Eventually I’ll add a some text that pops up saying something like “has been added to your cart” with a “view cart” button, but my main goal right now is adding the item to the cart without reloading the page or changing the url. Also, in case it matters, I am adding these custom links with jQuery .wrap functions.

      Thanks!

    3. Austin, thanks for that. If you used the same URL of the page where the add to cart buttons are, the add to cart shouldn’t redirect. If you are on the “shop” page, you’d want to use something like http://example.com/subdomain/shop/?add-to-cart=7763 to stay on the same page. Try it and let me know 🙂

  95. Hi there, great resource! I’m having the same issue as anon. using the link below, it somehow adds two items to cart every time I click on the link. This happens even if I specify the quantity. I tried both enabling and disabling the AJAX button and clearing caching history. i am using godaddy managed wordpress plan though and it does have caching on the site. Any suggestions?

     <a href="/product/mastery-series-1/checkout/?add-to-cart=6796">Register for Series</a>
    
    1. Hey there, thanks for your message! Well, I would temporarily disable the cache on the server side and also disable all plugins/themes but WooCommerce – in that way you’d be 100% sure there is something wrong with the URL in the link. Let me know 🙂

  96. Hello I would like to use the add to cart with redirect like this: http://yourdomain.com/cart/?add-to-cart=123. It works, but the url stays http://yourdomain.com/cart/?add-to-cart=123 instead of just http://yourdomain.com/cart/. This presents a problem, because you can’t reduce the quantity to 0, and every time the page is refreshed the quantity is incremented by 1. Is there a way for the destination url to be just http://yourdomain.com/cart/

    1. Hey Will, thanks for your comment! I just tested the /cart/?add-to-cart version and the URL is /cart after redirection – I can’t replicate your issue. Try disabling all plugins but WooCommerce and switch theme temporarily to see if there is anything wrong with them. Let me know 🙂

  97. Hi Rodolfo, I am using the:

    URL: Add One Simple Product to Cart & Redirect to Checkout Afterwards

    href=”http://yourdomain.com/checkout/?add-to-cart=25″

    and in Firefox and Chrome it always wants to add 2 products to the cart instead of just 1 (even if I specify the &quantity=1).

    I have enabled the AJAX and disabled the redirect to cart. Any ideas on what I should try?

    Thanks!

    1. Hey Anon, thanks for your comment! this is pretty weird behaviour… what if you disable the AJAX add to cart? Also, check your browser’s cookies (clear the cache) and make sure you don’t have a WordPress cache plugin enabled while testing. Let me know!

    2. I removed

       do_action( 'woocommerce_before_checkout_form', $checkout ); 

      from /wp-content/plugins/woocommerce/templates/checkout/form-checkout.php and now when using the link to the checkout page it only adds it once.

      The fix for the cart page is to remove

       do_action( 'woocommerce_before_cart' ); 

      from /wp-content/plugins/woocommerce/templates/cart/cart.php

  98. Rodolfo this is an awesome resource. Thanks a lot!

    1. Great! Thank you so much Gonçalo 🙂

  99. Hello Rodolfo,

    Thanks for this great information. We are trying to this but with Product Bundles and Subscribe to All Things. We can get the Product Bundle Parent product into the cart and the correct price but the Child Products will not display.

    We have tried these combinations…

    https://www.staging5.website.com/?post_type=product&add-to-cart=4089&variation_id=1979&quantity=1&&variation_id=148&quantity=2

    https://www.staging5.website.com/?post_type=product&add-to-cart=4089&bundled_items=1979,148&quantity=2,3

    https://www.staging5.website.com/?add-to-cart=4089&quantity%5B1979%5D=2&quantity%5B148%5D=2&quantity%5B2229%5D=2

    Any ideas?

    Thanks

    Netivity

    1. Hey there, thanks for your comment! I’m afraid I didn’t cover third party plugins in this post but as I own WooThemes Product Bundles plugin I can confirm that bundle products are “seen” by WooCommerce as single products. Both

      href=”http://yourdomain.com/?add-to-cart=25″

      and

      href=”http://yourdomain.com/?add-to-cart=25&quantity=3″

      will work with the parent bundle product, without the need of specifying its children.

      Let me know 🙂

    2. Hello Rodolfo,

      Sorry I was not notified that you replied. This does not work. We are using a Product Bundle where the Child Products can have different values. We are told that it is possible with the existing Product Bundle plugin code, but nobody knows the format of the url. Any help would be greatly appreciated.

      Netivity

    3. Hey Paul – no problem! As I said, I don’t own a Product Bundle plugin and therefore I could not add this to the blog post. Are you using the official WooThemes plugin?

    4. @Netivity any luck w/the URL you’re trying to create? I’m in a similar situtation.

    5. I’m trying to do this as well. Anyone have any luck figuring out the URL format.

  100. Hello I am suing a Add to Cart URL on a button but for some reason, it only works on FireFox but not Chrome and IE. Do you do why could this happen and how to solve it? Thank you so much!

    1. Hey Liam, thanks for your comment! This is indeed pretty strange… would you be able to paste the button link in a new comment and I’ll test it for you?

Questions? Feedback? Support? Leave your Comment Now!
If you're writing code, please wrap it between: [php] code_here [/php]

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.