Reputation: 1
how i can disable the button.single_add_to_cart_button in other div if i have price span.amount 0,00€?
Look code below:
<form class="cart" enctype="multipart/form-data" method="post" novalidate="novalidate">
<div id="tm-extra-product-options" class="tm-extra-product-options tm-custom-prices tm-product-id-7045 tm-cart-main" data-product-id="7045" data-cart-id="main">
<div class="tm-totals-form-main" data-product-id="7045">
<input class="cpf-product-price" type="hidden" name="cpf_product_price" value="0">
<div id="tm-epo-totals" class="tm-epo-totals tm-custom-prices-total tm-cart-main" data-variations="[]" data-variations-subscription-period="[]" data-subscription-period="" data-variations-subscription-sign-up-fee="[]" data-subscription-sign-up-fee="0" data-prices-include-tax="" data-tax-display-mode="excl" data-tax-string="" data-tax-rate="22" data-taxable="1" data-force-quantity="0" data-tm-epo-dpd-suffix="" data-tm-epo-dpd-prefix="" data-fields-price-rules="0" data-product-price-rules="[]" data-price="0" data-type="simple" data-is-sold-individually="" data-is-subscription="" data-cart-id="main" data-theme-name="">
<dl class="tm-extra-product-options-totals tm-custom-price-totals">
<dt class="tm-options-totals">Options amount</dt>
<dd class="tm-options-totals">
<dt class="tm-final-totals">Prezzo Totale:</dt>
<dd class="tm-final-totals">
<span class="amount final">0,00€</span>
</dd>
</dl>
</div>
</div>
<div class="iva_esc">
<div class="quantity">
<input type="hidden" value="7045" name="add-to-cart">
<button class="single_add_to_cart_button button alt" type="submit" style="display: block;">Vai al pagamento</button>
Other user, have sended to me this code:
<script>
$(function() {
//check if all items are zero
var disable = $(".cart span.amount.final").toArray().every(function(item) {
return $(item).text() === "0,00€";
});
//disable button if necessary
$(".cart button.single_add_to_cart_button").prop("disabled", disable);
});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
This code work perfect, but now i need to active when priced is different to 0,00€
Upvotes: 0
Views: 2197
Reputation: 31
In WordPress 5.1.1 WooCommerce 3.5.5, hide the price if equals $0.00, hide the add to cart button and hide the quantity.
jQuery(document).ready(function($) {
var ptext = $(this).find('span.amount').text();
ptext = ptext.replace('$', '');
var nptext = parseInt(ptext);
if (nptext === 0) {
$('.quantity').hide();
$('.single_add_to_cart_button').hide();
$('.amount').hide();
} else {}
});
In WordPress 5.1.1 WooCommerce 3.5.5, this is the complete code that replaced the $0.00 with text, hides quantity, and replaces button with a click to call image.
jQuery(document).ready(function($) {
var ptext = $(this).find('span.amount').text();
ptext = ptext.replace('$', '');
var nptext = parseInt(ptext);
if (nptext === 0) {
$('.quantity').hide();
$('.single_add_to_cart_button').replaceWith('<a href="tel:1-877-992-3377"><img src="/wp-content/uploads/2019/03/fine-jewelry-call-button.jpg"/></a>');
$('.amount').html('<span style="color:#8160C4;font-size:18px;">Call <a href="tel:1-877-992-3377" style="color:#8160C4;font-weight:bold;font-size:22px;">877-992-3377</a> for Promotion Price</span>');
} else {}
});
Upvotes: 0
Reputation: 589
With jquery something like:
var value = $('.amount').text();
if(value === '0,00€') {
$('.single_add_to_cart_button').hide();
} else {
$('.single_add_to_cart_button').show();
}
Upvotes: 1
Reputation: 5316
Using jQuery:
<script>
var amount = parseFloat($('.amount').html().replace(",", "."));
if(amount === 0){
$('.single_add_to_cart_button').prop('disabled', true);
}else{
$('.single_add_to_cart_button').prop('disabled', false);
}
</script>
Upvotes: 0
Reputation: 1294
var price = $(span.amount).val().split( '').map(Number)
This will split anything that's not a number, therefore you could use the following condition :
if(price >= 0 )
// do smth
else
// do smth else
Upvotes: 0