Welcome to DiviMania.com   Click to listen highlighted text! Welcome to DiviMania.com

WooCommerce: “Add to cart” URLs

by Oct 27, 2021Projects, Tutorials, Wordpress0 comments

I use WooCommerce in many projects and often I need to modify something to obtain what I want. Sometimes I need to create custom WooCommerce Add to Cart HTML links / buttons and make them add one or more products to cart and redirect to specific website pages.

Fortunately, it is very easy.

First you have to find the ID of the product you need to join to your button (look the imagine here)

URL: Add One Simple Product to Cart

href=”https://yourdomain.com/?add-to-cart=22″

Remember to change the domain name in the link, and the button will work out of the box. 1 product with ID=22 will be added to your cart.

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

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

1 product with ID=22 and quantity = 5 will be added to your cart.

URL: Add One Variable Product to Cart

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

The Variation ID (88 in my smple) you’ll find in the “variation” page.

Skip to content Click to listen highlighted text!