简体   繁体   中英

Using Custom Links to Add a Product to the Cart without being direct to cart.php

Big Commerce doesn't have native integration to allow a flat fee added to a total, so in place of that I wanted to add an extra button to my product page that would add the flat rate product to the cart using the product id. I found that I could do this ( https://support.bigcommerce.com/s/article/How-can-I-add-a-product-to-the-cart-with-a-link?language=en_US#add-to-cart ), I used this link: <a href="/cart.php?action=add&sku=5016" class="button button--green coa-btn">Add Certificate of Analysis (+$25)</a> to add the product to the cart, however ideally I would like to stay on that product page, not be redirected to the cart page. Any suggestions on how to fix/work around this?

To answer your question, you can add products using the Storefront Cart API, or a fetch request to the Add to cart URL. See https://developer.bigcommerce.com/api-docs/storefront/add-to-cart-urls#adding-multiple-products https://developer.bigcommerce.com/api-reference/storefront/carts

The other option is to use the stencil-utils itemAdd function (utils.api.cart.itemAdd) https://developer.bigcommerce.com/stencil-docs/reference-docs/stencil-utils-api-reference#cart-api

However, in your case, it may be simpler to add the certificate as a product option. Or does this route not work for you?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM