[Limited Time Offer] Get 40% off ALL ACCESS MEMBERSHIP before it’s gone!👉
mark Hendriksen logo

How To Create A Custom Add To Cart Link In WooCommerce

by Mark Hendriksen | Apr 10, 2021 | WooCommerce Tutorials | 6 comments

Home › WooCommerce Tutorials › How To Create A Custom Add To Cart Link In WooCommerce

Mark Hendriksen

I am the founder here at MarkHendriksen.com a blog website for Web design, WordPress, and popular page builders.

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

6 Comments

  1. Manoranjan singh

    Bro you are too good! nice article and its real worked.
    Thanks you

    Reply
  2. YOUNES BENARBI

    Thank You So Much!
    Really helpful!!

    Reply
  3. Ajay Rathod

    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
    • Mark Hendriksen

      Hi Ajay,

      From my knowledge that is not possible without a plugin.

      Reply

Submit a Comment

Your email address will not be published. Required fields are marked *