如果数量增加,WooCommerce 添加到购物车按钮文本会使用 jQuery 更改 [英] WooCommerce Add To Cart Button text change using jQuery if Quantity increase

查看:17
本文介绍了如果数量增加,WooCommerce 添加到购物车按钮文本会使用 jQuery 更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果数量增加,WooCommerce 添加到购物车按钮文本会使用 jQuery 更改.

 jQuery(document).on("change",'.minus', function() {var productquantity = jQuery('.qty').attr('value');如果(产品数量 == 15){jQuery('.single-product').each(function() {jQuery(".single_add_to_cart_button").text("请求报价");});}})

虽然选择按钮值永远不会改变:S

按钮和选择器的 HTML

<input type="button" value="-" class="minus button is-form"><input type="number" step="1" min="1" max="9999" name="数量" value="1" title="数量" class="input-text qty text" size="4" pattern="[0-9]*" inputmode="numeric"><input type="button" value="+" class="plus button is-form"></div><button type="submit" name="add-to-cart" value="1520" class="single_add_to_cart_button button alt" style="display: block !important">加入购物车</button>

jsFiddle

解决方案

jQuery(document).on("click",'.plus, .minus', function() {var productquantity = jQuery('.qty').attr('value');如果(产品数量 == 15){jQuery('.single-product').each(function() {jQuery(".single_add_to_cart_button").text("请求报价");});}否则如果(产品数量!= 15){jQuery('.single-product').each(function() {jQuery(".single_add_to_cart_button").text("现在加入购物车");});}})

唯一的问题是更改为 onclick.

WooCommerce Add To Cart Button text change using jQuery if Quantity increase.

    jQuery(document).on("change",'.minus', function() { 
  var productquantity = jQuery('.qty').attr('value');
    if  (productquantity == 15) {
          jQuery('.single-product').each(function() {
        jQuery(".single_add_to_cart_button").text("REQUEST A QUOTE");
    });
      }
})

While selecting buttons value never changes :S

HTML FOR BUTTON AND SELECTOR

<div class="quantity buttons_added">
    <input type="button" value="-" class="minus button is-form"><input type="number" step="1" min="1" max="9999" name="quantity" value="1" title="Qty" class="input-text qty text" size="4" pattern="[0-9]*" inputmode="numeric"><input type="button" value="+" class="plus button is-form"></div>

<button type="submit" name="add-to-cart" value="1520" class="single_add_to_cart_button button alt" style="display: block !important">Add to Cart</button>

jsFiddle

解决方案

jQuery(document).on("click",'.plus, .minus', function() { 
  var productquantity = jQuery('.qty').attr('value');
    if  (productquantity == 15) {
          jQuery('.single-product').each(function() {
        jQuery(".single_add_to_cart_button").text("REQUEST A QUOTE");
    });
      }  else if(productquantity != 15) {
          jQuery('.single-product').each(function() {
        jQuery(".single_add_to_cart_button").text("ADD TO CART NOW");
    });
      }
})

Only problem was on change to onclick.

这篇关于如果数量增加,WooCommerce 添加到购物车按钮文本会使用 jQuery 更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆