Add to Cart URLs
Query string parameters can be appended to BigCommerce product and /cart.php urls in order to pre-select an SKU or add a product to cart. These parameters make it possible to build custom add to cart links and forms for use on BigCommerce storefronts and remote sites (such as WordPress, blog posts, and social media).
URLs constructed with these parameters allow you to:
- Pre-select a specific SKU on a product detail page
- Add a specific product or SKU to the cart
- Add a specific SKU to the cart and go directly to checkout.
- Apply a coupon code to the shopper’s cart, with or without adding a product.
Parameters
Common usage
Below is a table of common scenarios and example URLs.
You can append couponcode to any storefront URL, including the home page; product_id and sku aren’t required. BigCommerce saves the coupon code to the shopper’s session and applies it once the cart contains products that meet the coupon promotion’s conditions.
Once constructed, a URL can be inserted directly as text or as an HTML link:
Adding multiple products
The sku and product_id parameters accept a single value; you can only use the first value of a comma-separated list of values. In other words, only one product can be added for each request made to an add to cart URL. However, it’s possible to combine several HTTP requests into a single button click using front-end JavaScript, as long as your code waits to receive the response of your first request before it makes a second.
The following gives a very basic example using jQuery. You can also use async/await syntax to make a series of calls from within a for loop.
Due to CORS (Cross Origin Resource Sharing), using JavaScript to make multiple carting requests only works in the BigCommerce storefront and only on the storefront with the domain the request is being made to.
Alternatively, the Storefront Cart APIs /api/storefront/cart endpoint accepts an array of lineItems — depending on the complexities and specifics of the use case, using Storefront Cart APIs may be a better solution than adding to cart URLs.