如果购物车总数小于 woocommerce 购物车页面中的特定数量,如何动态隐藏按钮

How to hide a button if the cart total is less than a specific amount in woocommerce cart page dynamically

我想在购物车页面中隐藏一个按钮,如果购物车总额低于 500 美元,如果超过 500 美元则显示。

当我更新 woocommerce 购物车时,必须动态获取。

检查了许多 ajax 代码,根本不起作用。 我的代码:

我想要这个按钮 hide/display 购物车条件:

 <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;
         }

如果你想隐藏基于购物车更新的按钮,你可以使用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();
};

});