[英]WooCommerce - Product already in cart, change “add to cart” text ajax
I found this great snippet from this website 我从这个网站上找到了这个很棒的片段
I have enabled "Enable AJAX add to cart buttons on archives", and the text will be updated only after the page has been refreshed. 我已启用“启用存档上的AJAX添加到购物车按钮”,并且仅在刷新页面后才更新文本。
How to update text "add to cart" to "already in cart" with ajax? 如何使用ajax将文本“添加到购物车”更新为“已经在购物车中”?
Thanks. 谢谢。
You can add something like this. 您可以添加这样的内容。
Js 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');
}
});
});
Samething with your code with class name of button etc. 与您的代码相同,带有按钮等的类名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.