This tutorial explains how to create a custom HTML link/button URL for your website to add that product to the cart by clicking it.
First, you need to know how to check the Product ID if you want to add that product to the cart through a custom HTML link or button.
How to check “Simple” Product ID?
Go to Products > All Products, and you can see a list of products. Hover one of them to see the ID: [the product id]
Above screenshot show the product ID is 13.
For all the scenarios below, do replace yourdomainname.com in the example below with yours, and the button/text link will be working fine.
<a href="https://yourdomainname.com/?add-to-cart=13&quantity=1">button html or text here</a>
Expected outcome: 1 product with ID=13 will be added to the cart.
<a href="https://yourdomainname.com/?add-to-cart=13&quantity=5">button/text</a>
Expected outcome: A total of 5 products with ID=13 will be added to the cart.
<a href="https://yourdomainname.com/cart/?add-to-cart=13&quantity=1">button/text</a>
Expected outcome: 1 product with ID=13 will be added to the cart and you will be redirected to the cart page afterward.
<a href="https://yourdomainname.com/checkout/?add-to-cart=13&quantity=1">button/text</a>
Expected outcome: 1 product with ID=13 will be added to the cart and you will be redirected to the checkout page afterward.
<a href="https://yourdomainname.com/customURL/?add-to-cart=13&quantity=1">button/text</a>
Expected outcome: 1 product with ID=13 will be added to the cart and you will be redirected to the checkout page afterward.
Note: Do replace customURL in the example above with your custom page URL For example https://yourdomainname.com/newsletter/?add-to-cart=13&quantity=1
First, you need to know how to check the Variable Product ID if you want to add that variable product to the cart through a custom HTML link or button.
How to check “Variable” Product ID?
Go to Products > All Products, and you can see a list of products.
Hover the Variable product to Edit or click directly the Product name.(For example: Variable Product 1)
<a href="https://yourdomainname.com/?add-to-cart=23&quantity=1">YELLOW</a>
Expected outcome: 1 variable product (color: Yellow) with ID=23 will be added to the cart.
<a href="https://yourdomainname.com/?add-to-cart=21&quantity=3">WHITE</a>
Expected outcome: A total of 3 variable products (color: White) with ID=21 will be added to the cart.
<a href="https://yourdomainname.com/cart/?add-to-cart=21&quantity=1">button/text</a>
Expected outcome: 1 product with ID=21 will be added to the cart and you will be redirected to the cart page afterward.
<a href="https://yourdomainname.com/checkout/?add-to-cart=21&quantity=1">button/text</a>
Expected outcome: 1 product with ID=21 will be added to the cart and you will be redirected to the checkout page afterward.
<a href="https://yourdomainname.com/customURL/?add-to-cart=21&quantity=1">button/text</a></pre > Expected outcome: 1 variable product with ID=21 will be added to the cart and you will be redirected to the checkout page afterward.
1. The Origin and The Meaning of Startup The word "start" refers to the beginning…
=== #1: AI Chatbot === 1. ChatGPTGet Started here: https://chat.openai.comChatGPT, one of the most significant language…
Dashicons is the official icon font since WordPress admin as of 3.8. https://developer.wordpress.org/resource/dashicons/ However, it…
Recently I had a great coffee chat with my old pal - Wei Ming, founder…
Sometimes there is a need for a custom new order status for WooCommerce orders such…
Here is a list of logo branding ideas for your next business or startup: …