WooCommerce: Custom Add to Cart URLs – The Ultimate Guide

In WooCommerce you can add a product to the cart via a custom link. You just need to use the “add-to-cart” URL parameter followed by the product ID.

This tutorial will show you how to create custom URLs to add simple, variable and grouped products to the cart – as well as defining the add to cart quantity and an optional redirect.

You will be able to see each possible scenario, and also copy/paste the custom URLs so that you only need to replace product IDs and quantities.

I strongly recommend you read through all the post comments in case you’re not sure about something – many people have asked the same questions over and over again e.g. “Is it possible to add more than 1 product to the cart?” (to which the answer is “no”, unless you install a custom plugin) or “Why does my product get added twice?

With this guide it’s much easier to place WooCommerce add to cart buttons on custom landing pages, pricing tables, blog posts, external websites, and so on. Enjoy!

1) Custom Add to Cart URL: “Simple” Products

Simple products can easily be added to the cart via a custom URL. All you need is the product ID (hover onto the product title under WooCommerce > Products):

Find WooCommerce Product ID
How to find the WooCommerce product ID for simple products.

URL: Add Simple Product to Cart with Quantity = 1

href=”https://yourdomain.com/?add-to-cart=25&quantity=1

Note: make sure to change the domain name in the link to your own WooCommerce website URL of course. In this example, product ID = 25 will be added to the cart with quantity = 1.

User will be redirected to the same page unless you have enabled “Redirect to the cart page after successful addition” under WooCommerce –> Settings –> Products -> General – in such a case they will go to the default Cart page instead.

URL: Add Simple Product to Cart with Quantity = 3

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

In this case scenario, the same product ID = 25 will be added to the cart but with quantity = 3.

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

href=”https://yourdomain.com/cart/?add-to-cart=25&quantity=1

Note: if you’ve changed the URL of your WooCommerce Cart page, make sure to change “/cart/” with “/basket/” or whatever the custom slug. 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 Simple Product to Cart & Redirect to Checkout Afterwards

href=”https://yourdomain.com/checkout/?add-to-cart=25&quantity=1

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 upon add to cart.

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

href=”https://yourdomain.com/page_slug/?add-to-cart=25&quantity=1

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“. Then, just replace “/page_slug/” with the slug of your page e.g. “/success/”.

2) Custom Add to Cart URL: “Variable” Products

Here things were originally complicated, but now it’s much easier! All you need is the specific variation ID that you want to add to the cart. Here’s where you can find it:

WooCommerce: find Variation ID
WooCommerce: where to find the Variation ID of a variable product

URL: Add Variation to Cart

href=”https://yourdomain.com/?add-to-cart=88&quantity=1

URL: Add Variation to Cart (with Quantity = 3)

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

URL: Add Variation to Cart & Redirect to Cart

href=”https://yourdomain.com/cart/?add-to-cart=88&quantity=1

URL: Add Variation to Cart & Redirect to Checkout

href=”https://yourdomain.com/checkout/?add-to-cart=88&quantity=1

URL: Add Variation to Cart & Redirect to Any Page

href=”https://yourdomain.com/page-slug/?add-to-cart=88&quantity=1

3) Custom Add to Cart URL: “Grouped” Products

A grouped product is a combination of two or more sub-products, and each one can be added with a custom quantity to cart with a custom URL which has a slightly different format from what we’ve seen so far..

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

WooCommerce Grouped Products
A WooCommerce grouped product.

URL: Add Grouped Product to Cart

href=”https://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 of its subproduct ID = 1803 and 2x of its subproduct 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

4) Mini-Plugin: Business Bloomer Add Multiple Products To Cart Via URL

You don’t feel confident with coding? You don’t want to purchase yet another bloated, expensive plugin? Great!

Business Bloomer WooCommerce Add Multiple Products To Cart Via URL is a mini WooCommerce plugin, without the usual hassles. One feature. Lifetime license. No annoying subscriptions. 1 plugin file. A few lines of code. No banners. No up-sells. No WP notifications. Use it on as many websites as you like. Lifetime support. 1-page documentation. Simple settings.

Settings screenshot:

Quick demo:

As you can see the plugin requires no initial settings. Install it, create a button/link with the “add-many-to-cart” URL parameter followed by the list of products and their quantities e.g. “=123:2,456:3“, and magically see your WooCommerce Cart filled with all the products and quantities you specified in the custom URL.

You can use the settings to customize the add-many-to-cart” URL parameter, change the quantity and product separators, use SKUs instead of IDs and optionally disable the “add to cart messages”. Simple!

Credits

Thanks so much to these amazing folks:

Related content

  • WooCommerce: Hide Price & Add to Cart for Logged Out Users
    You may want to force users to login in order to see prices and add products to cart. That means you must hide add to cart buttons and prices on the Shop and Single Product pages when a user is logged out. All you need is pasting the following code in your functions.php (please note: […]
  • WooCommerce: Add Custom Field to Product Variations
    Adding and displaying custom fields on WooCommerce products is quite simple. For example, you can add a “RRP/MSRP” field to a product, or maybe use ACF and display its value on the single product page. Easy, yes. Unfortunately, the above only applies to “simple” products without variations (or the parent product if it’s a variable […]
  • WooCommerce: Remove / Edit “Added to Your Cart” Message
    A client asked me to completely remove the message that appears after you add a product to the cart from the product page. This is simply done by using a PHP snippet, so here’s the quick fix for you!
  • WooCommerce: Add to Cart Quantity Plus & Minus Buttons
    Here’s a quick snippet you can simply copy/paste or a mini-plugin you can install to show a “+” and a “-” on each side of the quantity number input on the WooCommerce single product page and Cart page. The custom code comes with a jQuery script as well, as we need to detect whether the […]
  • WooCommerce: Display “FREE” Instead of $0.00 Price
    In older versions of WooCommerce free prices used to display as “FREE!” and products with empty prices were not publishable/purchasable. Now they’ve changed this around, but I still believe “FREE” looks much better than “$0.00”. It’s much more enticing, isn’t it? Well, here’s how you restore the old WooCommerce functionality – as usual it’s as […]

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

548 thoughts on “WooCommerce: Custom Add to Cart URLs – The Ultimate Guide

  1. Thank you so much. I used it for the Memberships on my Website, that means variable subscriptions and it worked well.

  2. Hello
    Thank you for your content
    I have a question that I would appreciate if you could help me

    I added links like this to my buttons on the site:
    http://yourdomain.com/your_custom_page/?add-to-cart=25

    But now I see that when I click on the button, it opens in a new tab
    How can I do the same thing in the same tab (one tab)? (without opening in a new tab)

    1. Not possible without custom coding. You need to implement Ajax add to cart

  3. Great post. If one uses only the link – he could then prevent add-to-cart-variation.min.js from loading site-wide no?

    1. Not sure, feel free to test it

  4. This plugin is almost exactly what we are looking for but instead of having to lookup product ID’s every time, we would like to specify the SKU which we and the users are familiar with.

    So instead of: href=”https://yourdomain.com/?add-to-cart=25&quantity=1“

    It would be: href=”https://yourdomain.com/?add-to-cart=SKU123456&quantity=1“

    Is this possible please? and if not, is there a tweak to the code to identify product by SKU rather than ID?

    Thanks

    Rob

    1. Hello Rob! I already got a similar request, so the next release of the premium plugin will allow you to specify SKUs instead of IDs. Keep in touch or purchase it now, and you will get the update in a few days

  5. Thank you for this awesome code!
    i’m implementing it to make a pdf catalogue interactive.
    i wanted to know if it’s possible to resolve a small issue:

    each time i click on a product, a new page is opened in the browser.
    i would like to know if it’s possible to not open new tabs when i click on the catalogue links.

    Thank you in advance!

    1. Not 100% sure how to do that in a PDF, sorry

      1. thank you!

        i’ll try to find a solution 😀

  6. Hello, thanks for the helpful tips. I have multiple product links on one page. After adding a product and hitting refresh, when I add a second product, it adds the first one again? This continues each time I need to add another product.

    Am I missing something? I read through most of the comments.

    1. I’m pretty sure that’s because you’re using relative URLs. Try linking each product to “https://example.com/?add-to-cart=123” as opposed to “/?add-to-cart=123” and see if that does the trick

  7. Hi Rodolfo and thank you very much for this post, it has been very useful for me to understand how Woocommerce works.

    However, I have a question that maybe you can solve, I have created a simple product and create a button to add it to the cart, including the quantity and add to the product name the name of the page where the button is located.

    I have found this page that does what I am looking for.

    When you click on the floating button at the bottom right (RESERVE NOW!) a pop-up window appears with two buttons that add a single product to the cart and also add a text and a línk to the product name.

    Sorry for all this text, but I’m going crazy and I thought maybe you could help me. Thanks in advance.

    1. Not fully sure what the problem is Samuel! Could you explain it again please?

      1. Thank you for your answer and your interest, Rodolfo.

        I will try to explain better:

        I have created a simple product and, in Elementor, I have created a button with a url to direct to the checkout when clicking on it.

        What I am looking for is if there is a way to add the url of the page where the button is located (which is not the product page) to the product name in the order summary at checkout.

        For example:
        I create a product called “Booking”.
        I add the button that I have explained in all the Wodrpess pages that show flats for rent (using a plugin that is not Woocommerce).
        When you click on the button, it takes you directly to the checkout to pay the “booking”, but I need to add to the order summary the url reference to know which flat is being booked.

        I hope I have explained myself and I hope you have an answer. Thank you very much again

        1. Hey Samuel, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  8. Is there a way to create a custom URL for a bookable product using the bookings availability plugin?

    1. Hi Brian, that 100% depends on whether this third party plugin allows you to use add to cart URLs (honestly, I doubt that). You will need to contact them to find that out

  9. Was sent this by a friend in hoping it would work I am trying to add to cart and redirect to checkout on a normal page. The product is a simple subscription, however when using this code, href=”https://yourdomain.com/checkout/?add-to-cart=25&quantity=1“
    It still only adds to cart and I remain on the same page. Am I doing something wrong?

    1. Hi Mandie. What’s your checkout page URL?

  10. Hello. Thanks alot for this topic. but is it possible to not let the page refresh? just simply add the product to the cart?

    1. Hi Sheraz, that’s possible but HTML is not enough to achieve that. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  11. Hellp Rodolfo, this is Peter.

    I’m currently using a AJAX searchbar on my site. I wanna know if it would be possible for me to make it so that when people click on the search result they add it straight into the cart instead of being redirected to the product page. Thanks.

    1. Hi Pedro, thanks so much for your comment! Yes, if your Ajax plugin is flexible enough this is possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  12. hi there, this is Leo from Taiwan.

    what if i want to create a sticky add to cart button at bottom of product page globally without and plug-in, just using ux-builder and css, is there a way to do with add to cart url?

    1. Hi Leo, not with pure HTML I’m afraid. A shortcode or custom PHP would do in this case

  13. Hello Rodolfo!

    I’m so glad to have found your site, there is so much helpful information to comb through and learn from. I read through these comments and couldn’t find a question about this topic yet, and I’m hoping you can help-

    Have you encountered Simple Products set up with subscriptions using the “All Products for Woocommerce Subscriptions” extension of the Woocommerce Subscriptions plug-in? It seems there is an error with the permalink when the product is set up this way.

    I use this extension because I want people to be able to buy my products outright or as a subscription, and so I am trying to use your link on the shop page to add the product as a regular (non-subscription) product to the cart. This works just fine, however if the customer then adds that SAME product to the cart from the product page, also as a regular (non-subscription) product, it adds the product to the cart as a separate product rather than just updating the quantity of the item already in the cart. This leads to weird UX for the customers.

    My theory is that, while there isn’t available variation information for me on the product page because this is a “Simple Product”, the permalink is missing some information about the product that is given by the native add-to-cart method, and so it adds the products to the cart separately/differently between these two cases instead of combining them. Not sure if this is possible to be remedied through simple html or php, but I’d love your input!

    1. Hi Amelia, thanks for your question and well done for skipping the comments queue!

      In regard to your question, I find it difficult to give you an answer. The idea I have in mind is that maybe that plugin transforms the product into a variable product, with different variations, including the original “non-subscription” product.

      So, my question is: which product ID are you using in the custom add to cart URL?

  14. Hi Rodolfo! Thank you so much for this. Even as a coding novice I got it!! I’m so grateful for people like you who can translate the ingenious that is web development into laymen’s terms.

    One question (my apologies if this is terribly naive): Is there a way to add a custom attribute, or add to the html itself to keep the page from refreshing to the top when you click this add-to-cart link?

    Currently it works great adding the product to the cart, but when someone clicks the link it brings them back to the top of the shop page. Is there an easy way to add the product to the cart, but keep the user on that same part of the page?

    Thank you soooooo much! You’re a real blessing.

    1. Great!

      You can try this:

      1) you add an HTML anchor to the product i.e. an ID = “anchor”
      2) the link would then look like: https://yourdomain.com/#anchor?add-to-cart=25

      Let me know

      1. Hello! I’m looking for the same solution. I’ve tried this but the link doesn’t work. I tested it with the same product –

        ?add-to-cart=433920

        (works, adds product to cart, but jumps to top of page)

        #targeted?add-to-cart=433920

        (where ‘tageted’ is my HTMP anchor, does nothing)

        Do you have another solution I might try?

        1. I was able to make it work:

          https://website.com/product/t-shirt/?add-to-cart=70799&wdr_coupon=wie-acad#order

          The # anchor being the last thing.

  15. Examples worked great but is there a way to add to cart using “WooCommerce TM Additional Product Options” custom fields values ?

    1. No idea, did you ask support?

  16. hi, I found that when using WPML to translate, using “https://yourdomain.com/checkout/?add-to-cart=25” is unable to redirect the translation page, but go to the original language of the website. I tried to change the checkout translation redirection url, but it failed. Does anyone have a solution?

    1. Hey Lee, is that the correct checkout URL?

  17. Hi,

    Great guide. Is it possible to send a custom product field eg. Custom text as a parameter in the url?

    Eg: ?add-to-cart=25&personalize=myname

    Thanks for the effort of putting up the guide and being patient enough to reply to comments.

    1. It is possible, but you also need a PHP function that can read that additional parameter so it can pass it to the Cart

  18. Works like a charm but on pages with multiple product URLs, as part of text, images or buttons, it adds products to cart if your cursor has passed over any of them through the process. We have turned plugins off, changed themes, no avail. Makes it unusable because people seeing stuff added to their cart are going to think we are trying to cheat them. it is not a good look.

    1. Hi Niels, that’s not possible, I’ve just tested that out of curiosity. Must be something else that you need troubleshooting

      1. This might be a link preloading javascript that preloads URL on hover.

  19. Great tip, however…

    When people add a product via the website, I want them to automatically redirect to the cart. So I need to ENABLE the tickbox “Redirect to the cart page after successful addition”.

    At the same time, when they add a product via a link< i want them to go to the checkput page immediately;

    I.e.: /checkout/?add-to-cart=25

    But this redirects them to the cart, instead of the cjeckout, because of the tickbox: “Redirect to the cart page after successful addition”.

    So how can I make this work?

    1. Hey Mike, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

      1. Hi Rodolfo do you have a solution here? I have the same problem with Mike

  20. Thanks for the URL. Does exactly what i want!

  21. Wow it’s that easy. Thanks for sharing these URL parameters.

  22. Hi Rodolfo, thank you so much for this useful article!

    One question about grouped products please: the links for these single products work perfectly:
    https://www.com/cart/?add-to-cart=54810
    https://www.com/cart/?add-to-cart=55439
    https://www.com/cart/?add-to-cart=54826

    But when I try to group them (quantity 1) as a grouped product:
    http://www.com/cart/?add-to-cart=58021&quantity%5B54810%5D=1&quantity%5B55439%5D=1&quantity%5B54826%5D=1
    it doesn’t seem to work. Do you know why?

    Thanks very much
    S

    1. Did you actually create and publish a “Grouped Product” first?

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

    Hi every time I click the button I set for purchase and I use this line it adds 2 products to my cart

    1. See previous comments please

      1. I am having the same issue but its not a grouped product

        1. I encountered the same problem – that the cart had two items added to it when it was not a grouped product.

          The problem was that if I used “https://mydomain.com/?add-to-cart=123”, it added two items to the cart;
          and after I changed it to “http://mydomain.com/?add-to-cart=123”, the problem was gone.

          Just wanted to bring it up in case anyone else meets this problem also.

          Cheers.

  24. Thank you. Thank you. Thank you!! I really wanted to save my user from having to click, click, click to get to the checkout page. You nailed it!!

  25. Hi Redolfo. Exactly what I was looking for! Thank you for the well-put together website – except, now things got a bit more complicated for me.
    I would like to run a single WP site with multiple service providers (in a single health industry)
    They all have only two products – 1) a consultation (which each may charge different amounts)
    and 2) medication (which may be charged as a single total or be separately charged for each item (ie itemised if possible and preferable)
    Non of the multi vendor/marketplace plugins allow for separate interfaces for each vendor to create separate orders
    and construct an invoice to charge for these two items.

    Is there a way of doing this with a URL? – perhaps adding a unique reference number for each vendor’s url, then go straight to checkout?

    So, is there any way of creating a URL to enter the consultation and specify an amount for it (ie, create a product called “consultation”

    1. Hey Rob, weird, did you ask all marketplace plugin providers? Other than that, there is always a way – but in this case HTML won’t be enough, you will also need to add custom PHP that should “listen” to URL parameters and change order items accordingly

  26. Not sure if I ask in the right place, and I apologies if I am wrong,.
    Here is my question:
    I have only 2 items for sale in my WP website.
    User may choose only 1 of them (it is unlikely and מnnecessary to choose both).
    Is it possible, and how, to link the “Buy Now” button of any of the items to a third party payment checkout?
    I want that no WordPress cart, WordPress shop or WordPress Billing pages will shown up – so a click on “buy now” will immediately transfer user to a third party payment gateway.
    Possible?

    1. Hey Sam, yes, that’s possible as long as the payment gateway allows you to do that

  27. This post was so helpful. I’d been researching this problem all day and finally found your post. So simple. Just one question: After the product has been added to the cart, I want to send the user to a specific section ID on a page. I’ve tried this url but it doesn’t scroll to the ID: https://cilmorwines.com/wines#shop-premium/?add-to-cart=198. In fact, it broke completely and the button did nothing. Is it even possible?

    1. Hi Ilana, the answer may be in some old comment, check it out

  28. Hi,

    Thank you for the article. This Checkout url very good:
    https:///checkout/?add-to-cart=1498&quantity=1

    May i ask:
    is that possible to add login details at the Checkout Url above?
    Because i wish that the url can help existing customer auto login when enter the Checkout Url.
    Look forward for your advice and suggestion. Thank you!

    1. I’d say you need PHP for that, HTML is not enough

  29. Hi, Is it possible to add coupon code too at add-to-cart link? I would like to use as a promo link.

    1. Yes, but you also need PHP to apply it to the Cart

      1. Or install a plugin called:”WooCommerce Extended Coupon Features FREE”, By Soft79.

        This enables you to add a coupon to the URL.

  30. Hi Rodolfo,

    Thanks for those tips !

    Any idea how I could create an add to cart button for the default attribute/variation ? (other than using css – display none to hide unwanted elements).

    Thanks

    1. I’d say you need PHP for that, HTML is not enough

  31. Hello,

    Someone knows how to add an url like ”https://yourdomain.com/?add-to-cart=25&quantity=5″
    in order to put the total quantity to eg. 5?

    if quantity is 1 => 5
    if quantity is 2 => 5
    so no + 5 but total quantity equals 5

    kind regards
    christophe

    1. it’s for in a function, so i can use php to change the number of quantity, but is it also possible using some url attribute?

    2. Hi Christophe, thanks so much for your comment! Yes, this is definitely possible with a bit of PHP, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  32. Thank you!

    1. Welcome!

  33. I have tried the:
    URL: Add One Simple Product to Cart & Redirect to Any Page Afterwards
    href=”https://yourdomain.com/your_custom_page/?add-to-cart=25″

    I inserted what was is in the parenthesis and ticked the “Enable AJAX add to cart buttons on archives” option under WooCommerce –> Settings –> Products -> General and also disabled the “Redirect to the cart page after successful addition”.

    However, when I click it, it is still taking me directly to the cart instead of redirecting me to the other page.

    What should I do?

    1. Disable the Ajax thing; also disable all plugins temporarily but Woo and see if that works

  34. Hi Rodolfo
    Thank you for your comprehensive article.
    I use this link for a single product with id=39 and it works.

    https://example.com/checkout/?login=true&page=4&add-to-cart=39

    I wonder is it possible to change the single product page add to cart link in a way that does the same for all of the products automatically?
    For example, for product id=40 when I click the add to cart button on the single product page, it would load the below link directly:

    https://example.com/checkout/?login=true&page=4&add-to-cart=40
    1. Sure, I guess you can echo it via PHP and allow for the dynamically generated product ID

  35. Congratulations! It worked perfectly for me

    Thanks ans Kind regards!

    Rodrigo

    1. Great

      1. Tested with or without ajax enabled and in wp 5.53 and woo 4.61 – hopes this helps others..

        The url format for adding a variation is as follows:
        “/cart/?add-to-cart=1137&variation_id=1144″ ( xxx Substitute your cart item id and variation id ) or

        /?add-to-cart=xxx&variation_id=xx” ( if you don’t want to enable the cart page )

        *You need to add the cart item in the string, not just the variation_id

        In order for this to work well, you need to do the following:
        To prevent page refreshing from adding another item – add the below code to your themes functions.php

        //prevent page refresh for adding item to cart using add-to-cart url
        
        add_action('add_to_cart_redirect', 'resolve_dupes_add_to_cart_redirect');
        function resolve_dupes_add_to_cart_redirect($url = false) {
          if(!empty($url)) { return $url; }
          return get_home_url() .add_query_arg(array(), remove_query_arg('add-to-cart'));
        }
        1. Correction:
          You can remove the cart_id=xxx and just use the following syntax

          /?add-to-cart=xxx. XXX ( is your variation ID )
          This prevents the URL from showing, this is ideal

          Hope this helps others too.

          1. Thanks

            1. Thanks to @Rodolfo & @Andrew–it works like a ‘new year fireworks’-Perfecto… & solve many problems.

  36. Awesome post Rodolfo!
    I have a custom text field on the product. Can it be filled in using the URL? How do I do it?

    My custom input:

    I’ve tryed:
    …/?add-to-cart=9&_custom_option=jrcode″

    But nothing it happens. Could you give me some advice?

    1. You can, but you also need PHP to “listen” to the URL parameter on the page after clicking

  37. Hi i am here just to thank you . you are a life saviour. again thank you for existing.

    1. Nice!

  38. Hi Rodolfo,

    Thank you for your input man!
    I have an issue with the woocommerce checkout page, where the URL: ”mywebsite.com/checkout/?add-to-cart=1428
    makes sure an extra unwanted product line item is added to the cart, right AFTER I checkout.
    Do you know how I can eliminate that?

    1. Uhm, no idea, doesn’t make much sense. Try disabling all plugins but Woo and switch theme – then try again

  39. Your article looked promising but I could not get it to work. I posted the following link into the Plans button but when clicked on I was not directed to the cart? And yes I did enable Ajax etc, followed your article to the point

    1. Hi Wayne, disable Ajax and disable redirect to Cart from the settings – then test again

  40. Hi, only want to say THANK YOU!

    Save my life!

    1. Thanks!

  41. how i hide link in my url bcz every time it referesh one product is added, its not what i want

    1. You shall use a different method then

  42. Really helpful.Thank you so much!

    1. Great!

  43. Thank you for the very helpful page!

    I’m trying to add a group product like your example:

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

    But this needs to go within a shortcode that my theme uses, so the brackets in your url are interfering with the brackets of the shortcode. Hope this makes sense. I tried replacing the brackets with ] or &lbrack; but that didn’t help.

    Thank you!

    1. Hi Matt, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

      1. I came up with a work around (not sure if it’s bad clunky idea or a clever idea) by sending the button to a url that is then redirected to the add-to-cart url.

        So the button goes to href=”https://yourdomain.com/temppage/″

        And I added a redirect for https://yourdomain.com/temppage/
        to
        href=”https://yourdomain.com/?add-to-cart=3111&quantity[1803]=5&quantity[1903]=2″

  44. Thank you very much for your great advice!
    I’ve solved my problem to apply URL-coupon in 2 steps:

    1 step: Add product to a cart when visiting promo-page>>>> //my_site/promopage/?add-to-cart=PRODUCT_ID
    2 step: Apply URL-coupon by pressing the button GET DISCOUNT >>>> //my_site/checkout/?coupon=COUPONE_CODE

    (URL-coupon plugin works only if the product is already in the Cart)

    1. Nice

  45. I want to dynamic this id. href=”https://yourdomain.com/?add-to-cart=25″
    Bcz i add a query on my home page products if i add newest products everytime i have to go on my code and change this id.

    1. Hi Fahim, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  46. Great article, would you mind to help me with multiple items added during checkout?

    1. Sorry, can’t help you. But next time try to read all previous comments 🙂

      1. Thanks got it!

  47. Hey guys just a tip for those of you that might be using a page builder. I’m using Brizy. I’m not sure the issue I’m getting was related to this, but I’ll share my experience in case anyone else might encounter the same issue.

    When I added any of the “add to cart codes” (didn’t matter if it was only the code that didn’t redirect the page to the cart page) It would always try to redirect me to my “cart page” the link was right, but the actual page would show the “this page doesn’t exist/page you’re looking”(I’m paraphrasing)

    It did do add the product correctly to the cart, it just didn’t redirect to the correct cart page even though the link was correct. (not sure why yet)

    I did test disabling the AJAX option just to see if it worked, it still did the same, with both option deactivated it still sent me to that erroneous page for some reason.

    So, what I did was to enable to “redirect to cart page after product added succesfully” option. Beware, this will always send the customer to the cart page, so, if you have a store with many products this might not be ideal, from a customer experience aspect, but if you have only a few, or only one, this option might work fine.

    I’m no expert, I am just sharing what I have tested, because I just realized the other day that something was wrong when someone told me they tried to buy something from my store but couldn’t.

    Also, if you sell a product that can only be added once to the cart (digital products, etc.) then you might need to add a message on your checkout page to check the quantities of before purchase, the reason behind this is that if you have that option activated, and your customer had previously added to the cart and it stayed in their cache, then it would send them to an error page.

    That’s just my grain of salt I’m sharing so that someone else doesn’t have to go through all the headache in case of a similar experience to mine.

    Cheers.

    1. Thanks!

      1. Thanks for that information Rodolfo. I’ve checked ‘redirect to cart page after product added succesfully’ and it cured the problem.

        1. Cool

  48. This is great but is there any way to add the product to the cart without refreshing the page?

    1. No sorry

  49. so, if i need to add 3 products in the single click
    product id=255
    product id=256
    product id=257
    <a href="www.domain.com/?add-to-cart=255″ and?

    1. You can’t

  50. Thanks for the detailed post. I use add to cart btns on shopify alot but never on WP, this guide is amazing.

    1. Yay!

  51. Really great guide, just what I needed.
    Thanks for taking the time to put it together.

    1. Awesome!

  52. hi
    I want to create a add-to-cart link that when user clicked,add 2 Different product to cart
    Is it possible?

    1. Not with just HTML

  53. You nailed it .
    This is the BEST article that explains about woocommerc add to cart and related. Every business looking for a specialist should read this to know all the hoops and ladders aka tons of work that’s needed.

    Kudos,
    Wan Mohd Afendi

    1. Thanks!

  54. The truth is that the page reloads me but the product does not come out in the cart.

    href = ”/?add-to-cart=1233 ″

    so I put it.

    Did I do something wrong?

    1. I clic the button and just reload the web site and cant see the item in the cart

      1. Not sure James. Product ID 1233 exists?

  55. First of all, thanks for this short tutorial, is very helpful!

    I succesfully added this to a membership pice table and it works on desktop only! Do you know how this could work for mobile devices also?
    Thanks,

    1. Uhm, makes no sense, please clear your cache/cookies

  56. Hi, first of all, thanks for this!

    Second,

    since I have a digital product, and don’t want people to double add it by mistake, is there any way to do this with this method? Because I have it set on woocommerce (to only allow 1 purchase of this product per purchase) what happens is that if a person goes back or still has the cart cached and presses on the button again, it basically just goes to a 404.

    Third, I tried using the only ATC button (without redirect) but it is still redirecting me, any idea of why this is? Does this have to do with ajax being activated? Although I wouldn’t think this should affect it, but I could be wrong.

      1. Thanks for the quick reply! I’ll look into it,

        I’ll if that changes anything, because the problem was when there was already a copy of the product in the cart, it will redirect to an error(blank) page, but when going into the cart page it will have a couple notifications of “you can’t add more than one product”.

        Would this code only allow 1 copy of the product or would it limit everything to only 1 product? Like, if a customer wants to buy 2 different things, would they have to do the whole buying process twice?

        Thanks in advance.

        1. It limits to just 1 product with quantity 1, overall

  57. Hi

    Is there a way to add multiple products to the cart at once? One add to cart button but it adds three different products.

    1. Nope

  58. Hi Rodolfo,

    With the grouped product triggering two products being added to the cart, is there a way to trigger the ATC action without reloading the page?

    When I use the WooCommerce add_to_cart shortcode for a single product for example, it allows me to add to the cart and keep shopping on that same page.

    Is it possible to use that same multiple-product add to cart in the Woo shortcode?

    Thanks,

    Eric

    1. Not with HTML alone

  59. Hello great explication.

    Now I get a request, perhaps you have the solution.

    I need a link to put in a App, an when clicking on that the product must be in cart. That’s ok. but this guys want now that we can add something to the URL a hidden data, that the shopmanager nows, ok this order is coming from the app.

    Will that be possible ?

    1. If I understand properly, google “query strings” and you should find a solution

  60. Hi Rodolfo,
    Thanks for the article!

    Btw, how to add One Simple Product to Checkout & Redirect to a Specific Page Afterwards ya?

    Actually, in the ‘specific page’, I plan to put the woocommerce_checkout shortcode beneath the page – so that the user can directly do check out process from there.

    I’ve tried to write the URL like this (https://example.com/checkout-1-unit-mens-formula/?add-to-cart=1338/) , but it failed – due to shortcode that didn’t automatically appeared.

    Is it really possible?

    Thanks for advance!

    1. Hi Hudson, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  61. Hi

    Since Days, I am trying to redirect “add to cart” button to respective single product Page.
    How that can be done?

    1. Give me a product URL and I’ll help you

  62. examples worked great but rather than “add to cart” by product ID, is there anything out there that would allow “add to cart” by sku?

    1. Not with HTML only

  63. Hi! Do you have any idea how to make it redirect on the same page?

    If I add a custom ‘add to cart button’ now, it redirects to the top of the page while I want it to stay in place.

    So I tried this with anchor text, but this didn’t work. Do you have any ideas?

    https://domain.com/services#producta/?add-to-cart=273&attribute_pa_percentages=10&amp;

    Awesome post by the way

    1. Not sure if that’s possible with HTML only

  64. hi,

    it’s great , i have tested href=”https://yourdomain.com/checkout/?add-to-cart=25″ and it work fine, i have the product on checkout page,
    but if i click on checkout button to buy i have EXPIRED SESSION eror message at the top.
    thanks

    1. Not sure, test by switching theme and deactivating all plugins but WooCommerce

  65. Thank you for this information. I want to add 2 buttons to my product page, first (add to cart) and second (buy now) which takes user directly to the checkout page. i have a product with 4 variations. could you please help me achieving the result.
    Thanks

    1. Sam, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  66. Hi Rodolfo, greet you for your great contributions … I want to add a “Buy Now” button to all my products but I can’t find how to do it. I wish you could help me. This is the code that I was using. Thank you!

    add_action('woocommerce_after_add_to_cart_button','bblomer_content_betweeen_add_cart_prod_meta');
    function bblomer_content_betweeen_add_cart_prod_meta() {
    	printf('<a class="button" href="<?php wc_get_checkout_url("/checkout/?add-to-cart=".$product_id) ?>">Buy Now</a>');
    }
    1. Hi 🙂 You need to get that $product_id first in some way

  67. Can we clear existing item in similar way before adding new items?
    e.g. Hitting: https://yourdomain.com/?empty-cart through AJAX and then hitting add-to-cart URL.

    1. Not with HTML only I’m afraid

  68. Thanks so much for this information. Very useful. I tried to use the URL with a currency code but the currency does not change. Am I doing something wrong when I do this: sitename.com/cart/?add-to-cart=123&wcmlc=GBP
    I can’t make the currency “hook” stick somehow. It is just ignored by my website. Any clue how I can fix this?

    1. Not sure, ask the currency switcher plugin dev in this case please

  69. Fantastic! Thank you very much!

    1. Welcome!

  70. I have a hardware product and a software product. The software is subscription. I have 2 variation attributes… Color of product and do you want the subscription. (Yes | No)
    All this is in the hardware page.
    I want the (Yes | No) for the subscription to work like this. If they choose Yes, that it will automatically add the subscription product to the cart at the time when they click Add to Cart for the Hardware product. Is this possible?

    1. Hi Bill, thanks so much for your comment! Yes, this is definitely possible (via PHP), but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  71. Hi Rodolfo,

    great work! You are really a woo commerce expert! Thank you!

    This is my issue:
    I am working with the add-to-cart hook in woo commerce. I am wondering if its possible to add an image as custom attribute to the cart. Now I have my image available as Base64 image and wondering if I could easily transmit this as custom attribute as such:

    https://myexampleshop.com/?add-to-cart=76981&quantity=1&image=data:image/png;base64,iVBORw0KGgoAAAANSUhEUg……

    Is this the way to go or are there any other techniques to use the add-to-cart hook in order to add images as custom attributes.

    Best regards and thank you in advance
    Martin

    1. Hi Martin, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  72. Wonderful!!! Thanks for this!!

    1. You’re welcome!

  73. Thanks for the post. I have been looking for this for some time now.
    When I implement your advice above, nothing happens. It just simply redirects back to the main page of the site WITHOUT adding a product to the cart. Any advice?

    1. Maybe your theme (or another plugin) is messing/conflicting with my snippet?

      To troubleshoot, disable all plugins but WooCommerce and also switch temporarily to “Twentyseventeen” theme (load the snippet there in functions.php) – does it work? If yes, you have a problem with your current theme or one of the plugins.

      Hope this helps!

      R

  74. I am using the following link to get people to get their subscription with me and go straight to the checkout page: https://shop.domain.com/checkout/?add-to-cart=393

    In that link I want to provide additional data that needs to be passed on to Woocommerce. Data like subscriber id so I can check the person who purchased with the subscriber id and sync the data.

    Any way how I can add that subscriber id to the checkout link above?

    Regards,

    Mark

    1. Hi Mark, did you try adding another “URL parameter”?

  75. Hi Rodolfo Melogli

    Thanks for the great post, I was wondering is it possible to set a shipping option via the url like you have added a item to the cart?

    1. Thank you Mike. Not possible with pure HTML – you’ll need custom PHP on top of that. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  76. thank you for your post
    so I want to make a little difference
    what about problems like me,
    I want if the customer adds the same product or the product is already in the basket, then the customer is immediately transferred to the basket
    thanks

    1. Can’t do that with HTML alone, sorry

  77. I love you dude. I’ve literally been trying to figure out how to add an add to cart button that possesses the design AND the functionality that I want for it for about 3 months now, and you saved me bro. I thank you for your work. I can not fathom how greatful I am that i came across your article. Like…seriously. 3 months of searching and your solution gave me EXACTLY what I’ve been looking for.

    1. Best comment ever! Thank you

  78. Hey, thanks for these great guidelines. However, I tried this on my client’s website but whenever a visitor click on a button, it will redirect to another offer product page created with Brizy Page Builder.

    We noticed there is a line of warning error on top of the page. Still figuring what is it.

    Thanks for advance.

    1. No idea, sorry!

  79. Is there a way to remove certain items from the cart when you add another certain item to the cart?

    1. Hi Alex, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  80. This is great! Is there a way to set this up to dynamically load the product id based upon the page that loaded?

    For instance, if we were to try to create a sticky add to cart button for mobile users, it would not be feasible to create a button for each product, and it would make sense to use some code to load the product ID based upon the product page you are on.

    Is there a tutorial for that?

    Thanks!

    1. Hey Jason, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  81. Additional info on my mystery here above :

    Both AJAX and Redirect to Cart are disabled in WooCommerce
    I also tried to add &rel=”nofollow” to the link, but without success.
    I also used the below code as someone suggested here, but also without success. The product is still added in double quantity.

    add_action('woocommerce_add_to_cart_redirect', 'resolve_dupes_add_to_cart_redirect');
         function resolve_dupes_add_to_cart_redirect($url = false) {
              if(!empty($url)) { return $url; }
              return 'https://dev.pmstudio.be/'.add_query_arg(array(), remove_query_arg('add-to-cart'));
         }
    
  82. What about adding the button to a page, instead of a link? I can’t figure out how to change “wrapper inline style”

    1. Not sure what you mean Kelly

  83. Thanks so much for sharing!

    1. Welcome!

  84. Hi,
    I tried ti redirect the simple product to checkout page but it says “Your Cart is Currently Emtpy”.
    Can you tell me about this.

  85. Hi Rodolfo,

    I’ve used the “?add-to-cart=ID” link using the appropriate id and the product is added. But it seems that ajax is not working even though is enabled in woocommerce-product-general. Actually, after clicking on the link I get the url mydomain.com/add-to-card=ID

    It seems and Ajax problem but if I use the normal woocommerce shop page, then ajax works, but the add-to-card code in any other page doesn’t.

    I’ve checked other comments but I don’t see the very exact problem. Most of them were solved after enabling ajax in woocommerce.

    Thanks so much.

    1. Yes, you should disable Ajax Add to Cart for this to work fully. Otherwise, HTML alone won’t help.

  86. Hello, how do i link pricing comparison plugin to woo-commerce checkout without a product ID ? it means a customer can choose the price shown on the price comparison page and checkout on woocommerce as “Purchase Order” without any product created on woocommerce, because I have several pricing plan created on the plugins that will be shared to the customer and will be paid as cash later on.

    1. You still need to create WooCommerce products, sorry

  87. Hi Rodolfo,
    Thanks a lot for the valuable info you have been posting here.
    I have a variable product (Subscriptions) with 4 attributes and 36 variations. When I go to my “store” (originally”shop”) and choose Subscriptions the product comes with 4 attributes to choose from. I choose from the attributes and press ADD TO CART button. When I look into my cart, the subscriptions product with all 4 attributes that I chose sits in the cart. The header(1st line), attribute1(2nd line), attribute2(3rd line) etc.
    Then I CONTINUE TO CHECKOUT and they are all there perfectly sitting under the header of the product. This is what I actually want.
    I also have a different SUBSCRIPTIONS page where the user chooses all the attributes by buttons. Then I have a custom CONTINUE TO CHECKOUT button where I assign the product ID through JAVA SCRIPT. this button is tied to “https://uniquacoffee.com/checkout/?add-to-cart=”+productID; Product ID is one of the 36 variations. This time the only display is the header. I cannot see the attributes. Your valuable advice will be highly appreciated.
    Thanks

    1. Please use the relevant URL for variable products

  88. cart/?add-to-cart=20&variation_id=71

    I got 500 error when use this

    1. You need a “/” in front of “cart”

  89. For those of you having quantity issues increasing when they shouldn’t I used another awesome snippet from Rodolfo. Which I found here – https://businessbloomer.com/woocommerce-redirect-checkout-add-cart/

    The only change I made was to change it from “checkout” to “cart”

    function bbloomer_redirect_checkout_add_cart( $url ) {
       $url = get_permalink( get_option( 'woocommerce_checkout_page_id' ) ); 
       return $url;
    }
     
    add_filter( 'woocommerce_add_to_cart_redirect', 'bbloomer_redirect_checkout_add_cart' );
    
    1. Nice!

      1. I tried this, it resolves the problem of the add-to-cart URL adding more quantity to the cart on refreshing the page but it does also something else: On my SHOP pages when clicking normal add-to-cart button it redirects automatically to the cart page. On my PRODUCT pages when clicking the normal add-to-cart button it does NOT redirect automatically to the cart.

        I tried with Ajax enabled/disabled and my auto-redirect is unchecked.

        I want to NOT redirect automatically to the cart page when my generic add-to-cart buttons on the site are clicked. When using this add-to-cart URL solution I want it to redirect to the cart. Anything I can tweak in this code to make the SHOP page add to cart buttons NOT redirect?

        1. You could slightly edit that function and make it run only on the non-WooCommerce pages. I suggest you take a look at “conditional logic”: https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Enjoy 🙂

  90. Always love your guides. Have been very helpful to me recently.
    I was wondering is there a way to prevent the URL from re-adding a product when someone refreshes the page.

    1. Never mind think I saw a function posted earlier, onwards and upwards.

      1. Awesome!

  91. I am trying to achieve the following:

    On the grouped product detail page a Add to Cart button for each Individual item, also for each item the Individual price must be listed. I have seen the following can be done but i need to get it working in a grouped product.

    How to do this, please?

    Thanks, Petr

    1. Petr, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  92. Hi!

    I wonder if it’s possible to create a second “add to cart” button on my product page. My product has 10 different variations and I want to add the selected variation to the cart.

    So, basically it does the same as the original “add to cart” button. Only, with this new button I want to redirect to the checkout page.

    So I’d like to have 2 “add to cart” buttons on my product page. One to just add it there, let’s say the official way. And one to redirect to checkout.

    Is this somehow possible? And how?

    Thanks a lot!

    1. This shows a way to display a second button there: https://businessbloomer.com/woocommerce-continue-shopping-button-single-product-page/ – hope this helps a little

  93. For some reason, this is not working: href=”https://yourdomain.com/checkout/?add-to-cart=25″
    I get [download_checkout] message on the next page. The simple add to cart and redirect to cart code works. But not this one.
    Please help.

    1. Hi Lynne, try disabling the automatic redirect to Cart?

  94. Hi I tried adding the single product link to a button. but its not adding on the cart.

    1. Hi, what’s the HTML you used? Is the product simple?

      1. Hi,
        Is this “WooCommerce Custom “Add to Cart” require any additional plugins or codes other than the Woocommerce plugin?
        When I go to the WooCommerce Settings> Products…I cannot find the option “Display” only the other 3(genral, inventory, downloadable).
        Thanks!

    2. Hi,
      I cannot find the “Display” in the Woocommerce settings. Is this an additional plugin?
      I only use the Woocommerce and Subscription extensions.

  95. Hello Rodolfo Melogli,

    Thank you, this article really helpful for us.
    I can customize woocommerce easily & redirect user to checkout

    1. Great!

  96. hi
    add-to-cart=id is working fine but when i click on the link i want to open a popup template. do you have any suggestions how can i triger it to a popup?

    1. Hi Ayesha, that’s not possible with HTML

  97. Rodolfo,

    It seems this post is an evergreen 🙂
    Please help—is it possible to add three simple products at once with a URL and redirect to checkout?

    Your fan,
    Peter

    1. Not possible, no. But look into “Grouped Products” maybe

  98. Hi,

    Great post. I have tried this one but it didn’t work:

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

    1. Hi, that doesn’t look like any of my examples. Sorry

      1. It’s literally your grouped product example.

        “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=”https://yourdomain.com/?add-to-cart=3111&quantity[1803]=5&quantity[1903]=2″”

        I also tried to add a group product this way. No worky.

        1. Ah, it’s a grouped product? I tried my URL, and it correctly adds to cart those products. The only “bug” is that it adds them twice (so 10 & 4 as opposed to 5 & 2). Anyway, that can be fixed. Are you saying no products get added to cart whatsoever?

          1. Hi Rodolfo,

            I’ve tested again and have successfully added the grouped product(s). I must have fat-thumbed something on my previous attempt.

            Great tutorial! Thank you for your help.

            1. Great!

  99. I’m using a simple URL to add a single product to the cart as you have in the tutorial above.

    It works perfectly except that the page that the link is on refreshes. Is there a way to not have the page refresh so that the user does not have to scroll all the way down to where they can add another product?

    1. Not with pure HTML I’m afraid.

    1. Thank you!

  100. Is possible to rename the add-to-cart URL?
    I would like to change it from:
    domain.com/?add-to-cart=1345
    to:
    domain.com/buy-1345

    1. Hello Willian, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  101. Thank you soooooo much for the great explanation Mr. Rodolf 🙂

    This is working great for me, except something weird happening, now when i click the [variant link] and go to the cart or checkout page, the problem i don’t get identification that this variant is the one i chose. <<< i got only product name without any variant like color or type. <<<< this is hilarious when customers buy items but i dunno which color or type they chosen. DID I DO SOMETHING WRONG HERE ?? << maybe if we add the previous link details you wrote with variants_ap something it trigger that ?

    Update: ( I have solved this issue using the old links which includes variation and attributes ).
    Thanks

    1. Ok cool!

  102. Hello sir, thanks for this guide.

    Already trying most time but still cant make it until saw your tips.

    Thanks for advance.

    1. Cheers!

  103. This isn’t working at all.
    It just refreshes the page. I talked with my theme developer and they’re saying the same, these codes aren’t working.

    1. Works for me and everyone else, sorry to hear that

    2. Same here. Is not working.

  104. Thank you very much for your information on the custom add cart. Keep up your awesome post.

    1. Thanks!

  105. Firstly let me thank you for this excellent tutorial. Brilliant!!

    I am using the “https://yourdomain.com/cart/?add-to-cart=25” to add a product to the cart and then redirected to the cart page.
    This is working perfectly well.

    The issue here is that any time I do a refresh to the cart page, adds one more item to the cart due to the “?add-to-cart=25” parameter.

    Note the same happens when redirected to the checkout page.

    Is there is a way to avoid this ?

    Thanks in advance,

    1. Hi Ana, please read previous comments

  106. Hello,
    Can I add multiple items to the cart with one click? I tried a couple of things but was unsuccessful.

    IE:
    https://www.demo.com/cart/?add-to-cart=99&quantity=1,add-to-cart=44&quantity=1

    1. Nope, please see previous comments

    1. Cheers!

  107. All the knowledge you share is awesome. You’re a great source of woocommerce info.

    I’m wondering if there is a way to create an url that filters the shopping page to show only products on sale, or certain category when you click it?

    Thanks,

    1. Thank you Alfonso 🙂 No, but you could create custom pages with custom URL with the products you need. Hope this helps

  108. Thanks so much for your awesome post – It got me most of the way there! However, to help user experience, I was trying to redirect them back to the section(s) they were prior to “adding to cart” with anchors. No matter what I try I can’t seem to get it to work with anchors. Is there any way to do this? I tried every combination I could think of.

    https://www.virtuouslivingcoach.com/flower-remedies-for-autism/#water-violet?add-to-cart=3100

  109. Brilliant! Thanks a lot.

    1. You’re welcome!

  110. This is great. One thing is missing if there’s a code that we can use to have a quantity and “+” “-” beside the add to cart button.

    1. Not sure I understand 🙂

  111. Hi @Rodolfo Melogli
    This is perfect, thanks. Just one question , is there a way to do the same with the “place order” button on checkout . The items in question are free items and t’c’s have been removed and only second time clients can access the product.

    1. No I’m sorry, at least not with pure HTML

  112. Thanks for the awesome resources, Rodolfo. Seriously I was looking for this solution for a very long time.

    Thanks again.

    1. Great!

  113. Hello Rodolfo,

    Thanks for the great article. I have a Affiliate system with my eCommerce website. Do you know how to redirect to checkout page in this scenario. I tried your method it works great.

    https://mywebsite.com/checkout/?add-to-cart=770

    but my affiliate members referral link looks like this
    https://mywebsite.com/?wpam_id=2

    so is there a way to combine these two. Basically what i need to when affiliate members share their link with their audience. when someone click on the affiliate link it redirect to checkout page

    Thanks
    Kumu

    1. Hi Kumu, I would add “&wpam_id=2” to the previous link and test. Let me know

  114. Hey so I think I found a simple solution for the “adding 2 qty of an item to the cart, when it’s supposed to be only adding one” issue. Within the link tag I added rel=”nofollow” and it seems to solve the issue.

    So my tag looks like this – Add To Cart

    And this solved the issue, not sure if it will for others, but thought I would add it to the mix here.

    1. Awesome 🙂

  115. Thank you, its help me a lot when I want to bring the user from page to checkout page =)

    1. Super!

  116. Hi, I’ve tried using this with Divi and when I click my button it just reloads my page and nothing is added to cart.

    1. Hi Dorothy, it might be a problem with Divi or another plugin.

      To troubleshoot, disable all plugins but WooCommerce and also switch temporarily to “Twentyseventeen” theme (load the snippet there in functions.php) – does it work? If yes, you have a problem with your current theme or one of the plugins.

      Hope this helps!

      R

    2. Try this for Divi :

      https://www.yourwebsite.com/?add-to-cart=123.

      I had same issue as you.

  117. Hello, thanks for guide.

    I tried this and when visitor click on a button, it redirect to another offer product page created with page builder (Elementor) and Astra theme.

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

    Can you help me out?

    1. Hi Zahid! What warning do you get?

  118. Hi,

    Whenever adding product to add to cart, my page got reload.
    how to solve this

    1. Hello Aniket, 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 my snippet?

      To troubleshoot, disable all plugins but WooCommerce and also switch temporarily to “Twentyseventeen” theme (load the snippet there in functions.php) – does it work? If yes, you have a problem with your current theme or one of the plugins.

      Hope this helps!

      R

  119. Hi Rodolfo,

    I have been trying to use these custom links to variations to add them to the cart,

    They are added to the cart, however the variation details (attributes) are not displayed on the cart page. If I add it from the product page itself (same option) then they are added to the cart with the variations attributes displayed underneath it…

    Any suggestions for this?

    Thanks 🙂

    1. Hi Mike! What link did you use – and did you make sure to use Variation Id and not Product ID?

  120. Hey !
    Thanks a lot for the tip ! I’ve implemented on my website and it’s working fine.
    However, I am facing an issue. Not sure if somebody can help me with this.
    When the product is added to the cart, I don’t know why but the picture which is shown is no the picture of the variation, but the picture of the main product.
    Which is not really professional as that means that the color chosen does not appear.
    Has someone experienced this issue as well ?
    Thanks!
    Guillaume

    1. Hi Guillaume, maybe you need to use the custom add to cart link for variable products?

  121. Just FYI: When using https://yourdomain.com/?add-to-cart=xx where xx points to a variation, the variation is added correctly to the cart (for example: Medium shirt of color Blue), as long as the variation & attributes are set on the product.

    1. Ah that’s brilliant – let me test it and in case I’ll revise this document 🙂

  122. Awesome. Thank you.

    I’ll be using “Add One Simple Product to Cart & Redirect to Any Page Afterwards” on my landing page to skip unnecessary steps in Cart area.
    It works, but i see a problem, because every time I click on the link, another additional item of a product is added.
    So if i for example leave checkout page and go back to the landing page and click on a link again, i now have two items of a product.
    This could be confusing for potential customers who don’t buy at first and come back later.

    Thanks.

    1. No way to fix this, it’s HTML. You’ll need a different way, see previous comments. Sorry 🙂

    2. This is what I used a while ago to stop adding duplicates. Maybe it will work.

      add_action('add_to_cart_redirect', 'resolve_dupes_add_to_cart_redirect');
           function resolve_dupes_add_to_cart_redirect($url = false) {
                if(!empty($url)) { return $url; }
                return 'https://www.example.co.nz/'.add_query_arg(array(), remove_query_arg('add- 
                to- 
                cart'));
           }
      
      1. Thanks!

  123. hello …
    thank you for this great plugin but am facing a problem when I trying to add groped products I use this link “https://myDomain.com/?add-to-cart=1031&quantity[548]=1&quantity[553]=1”
    this link add this groped twice rather than one for each product
    548 added twice and 553 added twice so do you have an idea why that happens?
    thank you

    1. Hello Asmaa, you should find an answer in the previous comments. Let me know

  124. Hello Rodolfo, awesome post – i have a question. I want to send out customized Cart URLs (incl. custom price) to my customers. I define the product with Gravity Forms (Plugin Combined with WooCommerce) and get the products in to the cart view. However i have no shareable link. Now if i do it with variable products i cannot enter the Price i want. Is there anyway that I get a customized Link when i click “Add to Cart” on my product page that includes the Gravity Form (and the customized products, price…)

    Hope you understand what i mean.

    Cheers Berni

    1. Hey Berni, thanks so much for your comment! Yes, I understand it and I’d say this is possible – unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  125. Hello Rodolfo,
    I use wordpress and woocommerce. I need to creat a funnel and do a one page sale with the checkout in the same page
    Also i need to have a list of product the custumer will select with a check box.
    Could you help me to do this in php?

    THanks a lot!
    S

    1. Hello Stephane, thanks so much for your comment! 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

  126. Excellent trick!
    One question. Is there a way to prevent it from adding to the cart and then redirecting to just /cart/

    for example, I have https://mysite.com/cart/?add-to-cart=2686 which adds the product to the cart and then redirects to https://mysite.com/cart/ is there anyway to prevent that redirect?

    1. Thank you Don! I’m not aware of that problem, it must be a plugin/theme conflict maybe

    2. Also having this issue, and it is not a plugin/theme conflict.

      It has the same behaviour with only WooCommerce active and on Storefront.

      After the product is added you always get redirected to cart

      1. Thanks for your comment Jes! Try to remove “Redirect to Cart” in your WooCommerce product settings maybe?

    3. hello, am facing the same problem is this problem will solve soon?
      or anyone solves it before?

    4. Ajax is enabled, Redirect is disabled. How to get it to simply Add to cart, without any redirect or link-to at all?

      1. make sure your link doesn’t have cart in it. so instead of https://mysite.com/cart/?add-to-cart=2686 just have https://mysite.com/?add-to-cart=2686

  127. Hi,

    Thanks a lot, as your post inspired me to come up with an idea for a shop im working on.

    I just found one issue, which is that it takes almost 3 seconds to load page after adding cart. And because of the shop im working on does not have a cart (short to speak, as it directly sends them to checkout) i find that it takes to reach the checkout around 8 seconds… is there anyway i can reduce the load time for adding the product to the cart?

    1. Hey Andres, 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 it?

      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

  128. This is a fantastic guide! I do have a question; how do I get the link to work with a Divi Theme button? The link works when using text html but when I add the link to a button destination it gives me a “page not found” error.

    1. Hello Amber, thanks for your comment. Try ask Divi support please 🙂

  129. Hi Rodolfo,

    Your ‘add to cart and go to check out page’ trick works awesome. But now I got a question with regards to using that trick; if the user hits the refresh button, it will add another item to the cart. So is there a trick to empty out the cart first when this button is being activated?

    Regards,

    Low

    1. Hey Low, thanks for your comment! No, there is no way with pure HTML. You’ll need a PHP alternative for that 🙂

  130. Great article Rodolfo and works perfect when I am logged in , however, when a customer is viewing the site, when they click they get directed to the basket and its saying its empty. I have gone through everything 3 times to be sure its all fine but still no change to the beahviour. Any guidance much appreciated.

    1. Hello Amanda 🙂 This sounds like a cache issue – try reading this: https://businessbloomer.com/woocommerce-solving-cart-empty-issue/

  131. Dear Rodolfo,

    We tried to do this, very simple url: Variable Products: Add to Cart URL.

    The problem is, it doesnt work for us with any product number.

    This is the url: https://www.yorkielove.hu/penztar/?add-to-chart=433

    The “penztar” is in hungarian the checkout, and the number 433 is one of the products.

    It redirects us to the cart page, and says: You can not go to the checkout page, until you add to the cart something.

    Did everything as you wrote it down, and btw in other sites it works. What can be the problem?

    Thanks for your answer,

    Marcell

    1. Hey Marcell – is that a variable product? If yes, you’re missing the attribute part of it 🙂

    2. Think you misspelled cart on your url .

  132. 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 🙂

  133. 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 🙂

  134. 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”

  135. Um using the Grouped Products Click url to add multiple items with different qtys to cart… (href=”https://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?

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

  136. 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?

  137. 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 🙂

      1. Hey Rodolfo, any chance of getting an update on this?? Or am I better off with hard coding it?

        1. No, sorry, that’s custom work and I won’t share it here. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  138. Great post!

    I have the same problem with the product getting added twice using https://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?

  139. 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

  140. 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.

  141. 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!

  142. 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

  143. 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?

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

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

  145. 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 🙂

    2. Were you by any chance able to figure this out? It looks like Rodolfo had a field for entering the quantity in his example screen shot, but I have no idea how to pass the variable in the URL.

  146. 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 🙂

  147. 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 🙂

  148. 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/

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

    1. Excellent 🙂

  150. OMG, thank you thank you thank you!!!

    1. 🙂

  151. 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 🙂

  152. 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 🙂

      1. Same for me, its not working on mobile or safari.

        Any idea why?

        1. Even in incognito mode?

  153. 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 🙂

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

    1. Awesome 🙂

  155. 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 🙂

  156. 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?

  157. 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.

  158. 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 🙂

  159. hey!
    can i add to my link (https://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 🙂

  160. 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 🙂

  161. 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!

  162. 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 🙂

  163. 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 🙂

  164. 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

  165. 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”

  166. 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?

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

  168. 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.

  169. 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

  170. 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).

  171. 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

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

  173. 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 🙂

  174. 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.

  175. 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

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

  177. 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

  178. 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 🙂

  179. 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 🙂

  180. 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 🙂

  181. 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

  182. 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!

  183. 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

  184. 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 🙂

  185. 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!

  186. 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

  187. 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 'https://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 🙂

  188. 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:

      https://mysite.com/my_page/?add-to-cart=1020#my_anchor
      1. 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

  189. 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.

  190. 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 🙂

  191. 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 🙂

  192. 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.

  193. 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

  194. 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?

  195. Hi, it’s possibile use the string like this
    https://yourdomain.com/?add-to-cart=25&quantity=3 and apply a valid coupon code in the url ?
    https://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) 🙂

  196. 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?

    2. David, did you ever find a way to add woocommerce add-on options to the url to add to cart?

      1. For future reference, this is actually not hard to do with the WooCommerce Product Add-ons Plugin https://woocommerce.com/products/product-add-ons/ . Simply append the query string “addon-form-element-id=addon-form-element-value-id” to the add to cart URL, substituting “addon-form-element-id” and “addon-form-element-value-id” with the values you can find by inspecting the source of the product page that contains the add-on.

        1. hi! So, I am trying to directly add to the cart a product with an addon. Is the answer you provided for this question? Because I cannot find the values you mentioned, addon-form-element-id and addon-form-element-value-id.
          How can I do it?
          Thanks in advance for the answer :)!

  197. 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?

  198. 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 🙂

  199. 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?

  200. 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?

  201. 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 🙂

  202. 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 https://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 🙂

  203. 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 🙂

  204. 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!

  205. 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 – https://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 🙂

  206. Hi Rodolfo,

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

  207. 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!

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

    1. Awesome, thanks Anthony!

  209. 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!

  210. 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

  211. 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?

  212. 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

  213. 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

  214. 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

  215. 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! 🙂

  216. 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?

      1. 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 
        1. Hey David, thanks for your comment! Are you using “global” attributes for those variations, which can be therefore be found under Products > Attributes?

          1. 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

              1. Hi Steve!
                Any ideas as to where to find exactly what the attribute frequency format should be in? 6+Weeks and 4+Weeks don’t seem to be working for me even though I have subscriptions set up on those intervals. Also, does it matter where in the string that part is?
                Cheers

                1. Hi Lauren, I’m having the same problem. Did you figure out a solution for setting the subscription attribute frequency?

  217. 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 🙂

  218. 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.

  219. 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?

      1. 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.

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

  220. 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! 🙂

  221. 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!

  222. 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!

      1. 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.

        1. 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 🙂

  223. 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

  224. 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>
      

  225. 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?

      1. My custom links are just (the site url + ?add-to-cart= + product id). So they end up looking like (https://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!

        1. 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 https://example.com/subdomain/shop/?add-to-cart=7763 to stay on the same page. Try it and let me know 🙂

  226. 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 🙂

  227. Hello I would like to use the add to cart with redirect like this: https://yourdomain.com/cart/?add-to-cart=123. It works, but the url stays https://yourdomain.com/cart/?add-to-cart=123 instead of just https://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 https://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 🙂

  228. Hi Rodolfo, I am using the:

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

    href=”https://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

      1. Hi,
        I am not a coder. I am having the same issue as Anon (July ,8 ,2016) . have no idea where to do do what Lyall (Sept 8, ,2018) says. I am having the same issue where the cart adds the product twice.

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

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

  230. 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=”https://yourdomain.com/?add-to-cart=25″

      and

      href=”https://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 🙂

      1. 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

        1. 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?

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

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

  231. 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?

Leave a Reply

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