[Limited Time Offer] Get 40% off MEMBERSHIP PLUS before it's gone! 👉Get This Deal
Mark Hendriksen Logo

How To Create A Custom Add To Cart Link In WooCommerce

Mark Hendriksen | April 10, 2021 | 6 Comments
Disclosure Note: Sometimes, I include links in my articles that can earn me money. It won't cost you anything, but it helps me pay for coffee ☕ so I can make more helpful content.

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.

Get product ID in WooCommerce

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.

Get ID for variable product in WooCommerce

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

Article by

Mark Hendriksen

I am the founder here at MarkHendriksen.com a blog website for Web design, WordPress, and Divi. Learn more about Mark

6 thoughts on “How To Create A Custom Add To Cart Link In WooCommerce”

  1. 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

    Reply

Leave a Comment

0 Shares
Share
Pin
Tweet