简体   繁体   English

WooCommerce-产品已经在购物车中,更改“添加到购物车”文本为ajax

[英]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.

相关问题 WooCommerce:当产品已在购物车中时更改添加到购物车的文本 - WooCommerce: change the add to cart text when the product is already in cart 如果产品在购物车中,则更改“添加到购物车”按钮文本,并在 WooCommerce 中满足条件时重定向到购物车页面 - Change "add to cart" button text if product is in cart and redirect to cart page when condition is met in WooCommerce 如果它已经在 WooCommerce 购物车中,请添加免费产品 - Add a free product if it is already in WooCommerce cart 如果产品已经在 WooCommerce 购物车中,则禁用添加到购物车按钮 - Disable add to cart button if product is already in WooCommerce cart 如果产品已经在购物车中,则禁用Woocommerce添加到购物车按钮 - Disable Woocommerce add to cart button if the product is already in cart WooCommerce add_to_cart简码-产品已在购物车中 - WooCommerce add_to_cart Shortcode - Product already in Cart 更改Woocommerce 3中特定产品类别的“添加到购物车”文本 - Change the add to cart text for a specific product category in Woocommerce 3 在 WooCommerce 中产品缺货时更改单个添加到购物车文本 - Change single add to cart text when product is out of stock in WooCommerce 根据Woocommerce中的父产品类别更改“添加到购物车”按钮文本 - Change Add To Cart button text based on parent product categories in Woocommerce 仅在 WooCommerce 单个产品页面上将添加到购物车文本更改为“应用” - Change Add to Cart text to “Apply” on WooCommerce single product pages only
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM