[英]WooCommerce Add To Cart Button text change using jQuery if Quantity increase
WooCommerce Add To Cart Button text change using jQuery if Quantity increase. 如果数量增加,则使用jQuery更改WooCommerce的“添加到购物车”按钮文本。
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 当选择按钮时,值永不变:S
HTML FOR BUTTON AND SELECTOR 用于按钮和选择器的HTML
<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>
$(document).ready(function () { $('body').on("click",'.minus',function () { var qtyval = $('.qty').val(); if(qtyval >= 0) { var newQTY = parseInt(qtyval) - parseInt(1); if(newQTY >= 15) { $('.single_add_to_cart_button').text("Request a Quote"); } if(newQTY < 15) { $('.single_add_to_cart_button').text("Add to Cart"); } $('.qty').val(newQTY); } }); $('body').on("click",'.plus',function () { var qtyval = $('.qty').val(); var newQTY = parseInt(qtyval) + parseInt(1); if(newQTY >= 15) { $('.single_add_to_cart_button').text("Request a Quote"); } $('.qty').val(newQTY); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script> <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>
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. 唯一的问题是更改为onclick。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.