WooCommerce - 产品已经在购物车中,更改“添加到购物车”文本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.

How to update text "add to cart" to "already in cart" with 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.