繁体   English   中英

WooCommerce:根据购物车总额增加费用

[英]WooCommerce : Adding fee based on the cart total

我正在尝试根据购物车总额添加费用。 但是费用增加了woocommerce_cart_calculate_fees 但我不知道如何根据购物车总数制作它。 当更新或删除,总更改,所以我无法得到适当的总和和添加费用。

function woo_add_cart_fee() {
    $cart_total = ;
    $fee = (int)$cart_total*5/100;
    WC()->cart->add_fee( 'Credits :', $fee, false, '' );
        }
    }
}
add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );

这是我的代码。 我无法找到方法。 有人可以帮忙吗? 提前致谢。

尝试这个:

function woo_dm_add_custom_fees(){
    $cart_total = 0;
    foreach( WC()->cart->get_cart() as $item ){ 
        $cart_total += $item["line_total"];
    }
    $fee = (int)$cart_total*5/100;
    WC()->cart->add_fee( "Credits :", $fee, false, '' );
}

add_action( 'woocommerce_cart_calculate_fees' , 'woo_dm_add_custom_fees' );
add_action( 'woocommerce_after_cart_item_quantity_update', 'woo_dm_add_custom_fees' );

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM