允许客户只将产品添加到购物车一次?

时间:2016-07-01 10:51:12

标签: javascript bigcommerce

我需要一些帮助来定制我的BigCommerce商店。

将产品添加到购物车后,我希望该产品的“添加到购物车”按钮更改并说“已在购物车中”。

另外,我只希望用户能够将产品一次添加到他/她的购物车中。

这是按钮代码:

<div class="ProductActionAdd" style="display:%%GLOBAL_HideActionAdd%%;">
        <a href="%%GLOBAL_ProductURL%%"><input  id="btnCopy" class="btn icon-%%GLOBAL_ProductAddText%%" title="%%GLOBAL_ProductAddText%%" type="button" value="Add to cart"  onclick="return change(this);" /></a>
    </div>

您能否就如何实现这一点给我一些建议?
我的商店网址为:https://deepak-diwan-s-store.mybigcommerce.com

2 个答案:

答案 0 :(得分:0)

在您的“添加到购物车”中添加课程&#39;用户单击它时按钮,页面加载jquery查找所有类并更改其文本。

希望有所帮助。

答案 1 :(得分:0)

如果没有写出具体的代码,您可以按照这些一般步骤来实现您的目标:

  1. 加载产品页面后,请使用JS脚本执行以下操作:
    一个。从当前产品页面获取SKU。
    湾对购物车页面执行Ajax GET请求,并加载购物车内容。
    ℃。如果购物车内容:contains来自步骤A的产品SKU,则产品在购物车中。
    d。如果产品在购物车中,则更改按钮文本并将其禁用。
    即否则,如果产品尚未装入购物车,则不执行任何操作。
  2. 作为评论的后续内容,在按钮上添加一个点击处理程序,以检查客户是否应该无法再次将产品添加到购物车。

    $('#id_of_button_here').on('click', function(event) {
      event.preventDefault(); //Stop button from adding product to cart temporarily. 
      // Read the button value to see if it equals 'INCART'
      if ($(this).val() === 'INCART') {
        alert('This product has already been added to the cart. You may not add it again');
        return false;
      } else {
        $(this).click(); //Click the button to proceed with normal operations.
      }
    });
    
相关问题