In this tutorial, I will be covering how you can create a custom add to cart link from any button or link and how you can redirect to the cart or checkout page. This is quite easy to do and does not require any plugin.
You will be able to create custom add to cart links on any page of your website.
Step 1: Find the product ID
Every product has its unique ID number and we will be needing this to create a custom add to cart link. Where to find the product ID depends on the type of product you have.
ID for simple products
In your WordPress dashboard navigate to Products and hover over the product you want to create a link from.

ID for variable products
To get the ID for a variable product go to Products and open your product. In the variations tab, you can find the variation ID. Adding the links is the same as for simple products.

Step 2: Create a custom add to cart link
You need to place this ?add-to-cart=694 after your URL. You need to replace the ID number with yours. It will look something like this:
https://mydomain.com/?add-to-cart=694
Now you need to change the domain and ID number to yours.
Redirect to cart page
To redirect the link to the cart page after adding the product you can use this:
https://mydomain.com/cart/?add-to-cart=694
By default, the cart page should be https://mydomain/cart if you changed that URL then you need to adjust it.
Redirect to the checkout page
To redirect the link to the checkout page after adding the product you can use this:
https://mydomain.com/checkout/?add-to-cart=694
If your checkout page has a different URL then you need to change that in the link.
Change the quantity
If you want to increase the product quantity you can add this after the URL:
&quantity=5
In this case its a quantity of 5.
The whole URL will look like this depends if you want to redirect it.
https://mydomain.com/?add-to-cart=694&quantity=5
Bro you are too good! nice article and its real worked.
Thanks you
Thank You So Much!
Really helpful!!
Hi, in last when case quantity is 5 and we want to give a discount on 5 quantities how can we achieve this without third party plugin
Hi Ajay,
From my knowledge that is not possible without a plugin.
is there any free plugin to achieve this?
You can check out this one:https://wordpress.org/plugins/url-coupons-for-woocommerce-by-algoritmika/
I have never used it myself but perhaps this is a solution for you.