BigCommerce allows business owners to set up an online store, customize it to their liking, and then sell an unlimited number of digital, physical, or even service-based products.
For adding products to the Bigcommerce cart we can use the following endpoint.
{{domain}}/cart.phpWe have to add the following query parameters to the above endpoint.
| Type | Parameter | Description | Example |
| string | action= | add or buy; buy goes directly to checkoutadd will add the product to cart | /cart.php?action=add&product_id=123 |
| int | product_id= | product id to add to the cart | /cart.php?action=add&product_id=123 |
| int | qty= | quantity to add to the cart | /cart.php?action=add&product_id=123&qty=3 |
| string | sku= | SKU to add to the cart (or select on product page) | /cart.php?action=add&sku=xlredtshirt |
| string | couponcode= | coupon code to apply to the cart | /cart.php?action=add&product_id=123&couponcode=10off100 |
Example URL:
https://{{domain}}/cart.php?action=add&product_id={{id}}&qty={{qty}}After adding the parameters just call the API and this will add the product to the bigcommerece cart!
<a href="https://example.com/cart.php?action=buy&product_id=123">Purchase Our New Product Now!</a>
The below sample JS code that can be used in Digioh Custom Js to add the products to Bigcommerce cart:
<button id="addToCart" type="button">Add Bundle to Cart</button><script>// when #addToCart is clicked...$("button#addToCart").click(function() { // add product id 123return $.get("/cart.php?action=add&product_id=123").done(function(data, status, xhr) {console.log('first item complete with status ' + status);}).then(function() {// add product id 456return $.get("/cart.php?action=add&product_id=456");}).done(function(data, status, xhr) {console.log('second item complete with status ' + status);})// chain more async GET requests using .then & .done.fail(function(xhr, status, error) {console.log('oh noes, error with status ' + status + ' and error: ');console.error(error);return xhr.done();}).always(function() {// go to cartreturn window.location = "/cart.php";});});</script>
Reference URL:
https://developer.bigcommerce.com/docs/09888af34c0e8-add-to-cart-ur-ls
Want to get more from Digioh?
Get the playbooks leading brands use to convert more visitors into revenue.
Browse the Playbooks