Add cart product in cart with link (URL) in woocommerce
href=”http://yourtsite.com/?add-to-cart=3083″
href=”http://yourtsite.com/?add-to-cart=3084&quantity=3″
Add cart product in cart with link (URL) in woocommerce
How to create custom “Add to Cart” URLs in WooCommerce?
Simple Products: Add to Cart URL
One of the easiest among them. Simple products are quite easy to add to cart through a custom URL. Just search the product ID by going to product title under WooCommerce>>Products and use the given below links. You can see shown below image.
[image source file: www.businessbloomer.com]
URL: Add one simple product to cart
href=”http://yourdomain.com/?add-to-cart=25″
- Remember to change the domain name in the above link, and the button will work out of the box. 1 product with id = 25 will be added to the cart.
URL: Add one simple product to cart with quantity = 3
href=”http://yourdomain.com/?add-to-cart=25 &quantity=3″
- 1 product with ID = 25 and quantity = 3 will be added to the cart.
- Note: Remember that 2 different products cannot be added to a cart with a URL.
URL: Add one simple product to cart & redirect to cart afterwards
href=”http://yourdomain.com/cart/?add-to-cart=25″
- In case you have changed the URL for the cart, so make sure that you will have to change “/cart/” into “/basket/” – for example.
- For this, you will have tick the “Enable AJAX add to cart buttons on the archives” option under WooCommerce>>Settings>>Products>>General.
URL: Add one simple product to cart & redirect to checkout afterwards
href=”http://yourdomain.com/checkout/?add-to-cart=25″
- For this , tick the ” Enable AJAX add to cart buttons on archives” option under WooCommerce>>Settings>>Products>>General.
- And disable “Redirect to cart page after successful addition”.
URL: Add one simple product to cart & redirect to any page afterwards
href=”http://yourdomain.com/your_custom_page/?add-to-cart=25″
- For this, you have to Enable the AJAX add to cart buttons on archives” option under WooCommerce>>Settings>>Products>>General.
- And disable “Redirect to the cart page after successful addition”.
Variable Products: Add to Cart URL
Here things get quite difficult!
There are 1 or more attributes and a quantity in the variable products. And you will have to find the variation ID, attribute NAME slug and the attribute TERM SLUG along with finding the product ID.
You can see the images shown below!
As you will have a product ID, variation ID, and its specific properties, you can use the following:
URL: Add one variable product to cart (with 1 attribute only)
href=”http://yourdomain.com/?add-to-cart=47&variation_id=88&attribute_pa_colour=blue”
- Here we are adding Variable Product ID 47, and especially its variation ID = 88, where the color attribute is equal to blue.
- It’s a bit complicated but once you will do it becomes easy.
URL: Add one variable product to cart (with 2 attributes)
href=”http://yourdomain.com/?add-to-cart=47&variation_id=88&attribute_pa_colour=blue&attribute_pa_size=m”
- Here we are adding Variable Product ID 47, and especially its variation ID = 88, where the color attribute is blue and size attribute “M”.
URL: Add one variable product to cart (with 2 attributes and Quantity = 3)
href=”http://yourdomain.com/?add-to-cart=47&variation_id=88&quantity=3&attribute_pa_colour=blue&attribute_pa_size=m”
- In addition, you can also redirect to cart, checkout, and another page in the same way as we have discussed for the simple product page.
URL: Add one variable product to cart & redirect to cart
href=”http://yourdomain.com/cart/?add-to-cart=47&variation_id=88&attribute_pa_colour=blue”
URL: Add one variable product to cart & redirect to checkout
href=”http://yourdomain.com/checkout/?add-to-cart=47&variation_id=88&attribute_pa_colour=blue”
URL: Add one variable product to cart & redirect to any page
href=”http://yourdomain.com/any-page-url/?add-to-cart=47&variation_id=88&attribute_pa_colour=blue”
click here for more information