I want to hide a button in the cart page, if the cart total is less than $500,and display if it is more than $500.
Which must be get dynamically,when i update woocommerce cart.
Checked with many ajax codes,nothing works at all. my code:
This button i want get hide/display with cart conditions:
<button id="add_cart_button_style_rg_id" onclick="onclick_pay_button()" class="add_cart_button_style_rg"></button>'
//refresh cart page
add_filter('add_to_cart_custom_fragments',
'woocommerce_header_add_to_cart_custom_fragment');
function woocommerce_header_add_to_cart_custom_fragment( $cart_fragments ) {
global $woocommerce;
ob_start();
?>
<button id="add_cart_button_style_rogue_id" class="add_to_cart_button_link" onclick="onclick_pay_button()" class="add_cart_button_style_rg"></button>
<?php
$cart_fragments['.add_to_cart_button_link'] = ob_get_clean();
return $cart_fragments;
}
CodePudding user response:
If you want to hide button based on cart update, you can use JQuery. Try following code. It uses updated_cart_totals trigger and compare the price value then hide the element
jQuery (document.body ).on( 'updated_cart_totals', function(){
<!-- get subtotal after cart updated -->
var total = jQuery('table.shop_table .cart-subtotal').html();
<!-- format the price to integer value -->
total = total.replace(/,/g, ''); // Replace comas by points
var total_val = parseInt(total);
if (total_val < 500) {
jQuery("#add_cart_button_style_rogue_id").hide();
}else {
jQuery("#add_cart_button_style_rogue_id").show();
};
});
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>