Home » Articles » WooCommerce » How to create add-to-cart URLs in WooCommerce

Creating custom add-to-cart URLs in WooCommerce can significantly improve your customers’ shopping experience and boost your conversion rates. These special links allow you to add products directly to a customer’s cart with just one click, making the shopping process quicker and more streamlined. This guide will walk you through everything you need to know about creating these powerful URLs for your WooCommerce store.

Setting up custom add-to-cart URLs for your WooCommerce store

Finding your product ID

Before creating any add-to-cart URLs, you’ll need to locate your product’s ID. This unique identifier is essential for the URL to work properly. You can easily find this in your WordPress admin dashboard:

  1. Go to WooCommerce > Products
  2. Hover your mouse over the product title
  3. Look for the ID number that appears beneath the product name

Once you’ve got this number, you’re ready to create your custom URLs.

Creating add-to-cart URLs for simple products

For basic products without variations, the URL structure is straightforward. Simply replace “example.com” with your website address, and insert your product ID and desired quantity:

https://example.com/?add-to-cart=PRODUCT_ID&quantity=QUANTITY

For instance, if your product ID is 123 and you want customers to add two items, your URL would look like:

https://yourstore.com/?add-to-cart=123&quantity=2

When a customer clicks this link, two units of product #123 will automatically be added to their cart.

Creating add-to-cart URLs for variable products

Variable products (those with options like size or colour) require a slightly different approach. Instead of using the main product ID, you’ll need the specific variation ID:

https://example.com/?add-to-cart=VARIATION_ID&quantity=QUANTITY

You can find the variation ID in the Variations tab when editing your product. For example, if you’re selling a t-shirt and the blue version with a logo has ID #39, your URL would be:

https://yourstore.com/?add-to-cart=39&quantity=1

Creating add-to-cart URLs for grouped products

Grouped products are a bit more complex as they contain multiple sub-products. The URL structure needs to account for each item in the group:

For one sub-product:

https://example.com/?add-to-cart=GROUPED_PRODUCT_ID&quantity[SUB_PRODUCT_ID]=QUANTITY

For multiple sub-products, simply extend the URL:

https://example.com/?add-to-cart=GROUPED_PRODUCT_ID&quantity[SUB_PRODUCT_ID]=QUANTITY&quantity[SUB_PRODUCT_ID]=QUANTITY

Redirecting customers after adding to cart

By default, when a customer uses an add-to-cart URL, they’ll stay on the same page. However, you might want to direct them to a specific page afterwards, such as the checkout or cart page.

To redirect to the checkout page:

https://example.com/checkout/?add-to-cart=PRODUCT_ID&quantity=QUANTITY

To redirect to the cart page:

https://example.com/cart/?add-to-cart=PRODUCT_ID&quantity=QUANTITY

If you’d prefer that the page doesn’t reload when items are added to the cart, you can enable AJAX in your WooCommerce settings.

Just go to WooCommerce > Settings > Products > General in your admin dashboard.

Conclusion

Custom add-to-cart URLs are a powerful yet often overlooked feature in WooCommerce. They provide a smoother shopping experience for your customers while potentially increasing your conversion rates by removing unnecessary steps in the purchase process. With the information in this guide, you can now create these useful links for all types of products in your WooCommerce store.

Wave

Enjoy our articles? Join our free list and get more.

Sign Up

Book Discovery Call