我想在購物車頁面中隱藏一個按鈕,如果購物車總額低于 500 美元,如果超過 500 美元則顯示。
當我更新 woocommerce 購物車時,必須動態獲取。
檢查了許多ajax代碼,根本沒有任何作用。我的代碼:
這個按鈕我想在購物車條件下隱藏/顯示:
<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;
}
uj5u.com熱心網友回復:
如果要根據購物車更新隱藏按鈕,可以使用 JQuery。嘗試以下代碼。它使用 updated_cart_totals 觸發器并比較價格值然后隱藏元素
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();
};
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/349919.html
