![](/img/trans.png)
[英]WooCommerce: change the add to cart text when the product is already in cart
[英]WooCommerce - Product already in cart, change “add to cart” text ajax
我從這個網站上找到了這個很棒的片段
我已啟用“啟用存檔上的AJAX添加到購物車按鈕”,並且僅在刷新頁面后才更新文本。
如何使用ajax將文本“添加到購物車”更新為“已經在購物車中”?
謝謝。
您可以添加這樣的內容。
阿賈克斯
$('.accounts-content').on('click','.accounts-details-save-btn' ,function(e){
e.preventDefault();
var $btn = $(this);
$.ajax({
method: "POST",
url: url,
data: sendjson,
dataType: "json",
contentType: "application/json",
headers : headers,
success:function(response){
$btn.text('already in cart');
},
error: function(){
$btn.text('add to cart');
}
});
});
與您的代碼相同,帶有按鈕等的類名。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.