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:
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:
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:
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:
In this case its a quantity of 5.
The whole URL will look like this depends if you want to redirect it.