簡體   English   中英

Woocommerce - 將數量為 0 的商品添加到購物車?

[英]Woocommerce - Items with a quantity of 0 are added to the cart?

我在商店頁面上每件商品旁邊都有商品數量。 用戶可以輸入他們的數量並單擊添加到購物車按鈕,這將使用 ajax 將項目添加到購物車。 默認情況下,我將項目數量設置為 0; 但是,如果用戶在數量為 0 時單擊添加到購物車按鈕,則該商品將添加到購物車中,數量為 1。

我想要發生的是,如果商品數量為 0,則會出現一條消息,告訴用戶輸入他們的數量,並且商品不會添加到購物車中。

這可能嗎? 任何幫助,將不勝感激。

這應該有效,將 This 添加到您的自定義 JS 代碼中。

jQuery( document ).ready(function() {
  jQuery(".woocommerce div.product form.cart .button").click(function(){
    if(jQuery('input[name="quantity"]').val() == 0 || 'input[name="quantity"]').val() == ""){
       alert("Quantity should be at least 1. The item will not be added to cart.");
       return false;
    }
  });
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM