1. Documentation /
  2. Creating WooCommerce 'Add to Cart' URLs

Creating WooCommerce ‘Add to Cart’ URLs

Below, we’ll cover how you can create specific links to add products to your customers cart using custom URLs. You can add products to the cart, specify the quantity, and even redirect to another page all with a URL or link.

Finding Your Product ID

↑ Revenir en haut

These ‘Add to Cart’ URLs all require knowing the product ID from WooCommerce to work. You can find a product ID by hovering over the product title under WooCommerce > Products in your dashboard. The product ID will then appear under the product title.

Custom ‘Add to Cart’ URL for Simple Products

↑ Revenir en haut

To add a simple product to the cart, use this URL structure. Replace example.com with your site’s URL and PRODUCT_ID and QUANTITY with your specific product details:

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

Custom ‘Add to Cart’ URL for Variable Products

↑ Revenir en haut

For setting a specific variable product, use the variation ID found when editing a variable product. For example, if you wanted to use this variation for the blue color with logo it would be ID number 39.

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

Custom ‘Add to Cart’ URL for Grouped Products

↑ Revenir en haut

For grouped products, include the product ID and quantities for each sub-product.

For one sub-product:

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

Repeat for additional sub-products:

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

And so on.

Redirecting After Adding to Cart

↑ Revenir en haut

After a product is added to the cart, you can choose where the customer is redirected to. By default, they will stay on the same page unless the WooCommerce settings are configured to redirect to the cart or checkout page.

To customize the redirect location, append the URL where you want the customer to land. For example, to redirect to the checkout page after adding a product to the cart, use:

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

As another example, to redirect to the cart page after adding a product to the cart, use:

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

Enable AJAX in WooCommerce > Settings > Products > General to prevent page reloading when items are added to the cart.

Questions and Support

↑ Revenir en haut

Do you still have questions and need assistance? 

This documentation is about the free, core WooCommerce plugin for which support is provided in our community forums on WordPress.org. Searching there you’ll often find that your question has been asked and answered before.

If you haven’t created a WordPress.org account to use the forums, here’s how.

  • If you’re looking to extend the core functionality shown here, we recommend reviewing available extensions in the Woo Marketplace.
  • Need ongoing advanced support, or a customization built for WooCommerce? Hire a WooExpert agency.
  • Are you a developer building your own WooCommerce integration or extension? Check our Developer Resources.

If you weren’t able to find the information you need, please use the feedback thumbs below to let us know! 🙏