add_action( 'woocommerce_calculate_totals', 'woo_add_cart_fee' );
我使用这个钩子在购物车总金额中添加额外的金额费用。如果我在这个函数中给出静态值,这个工作正常,并在购物车总金额中添加额外的金额费用,但当我在隐藏字段post和会话变量中给出额外金额时,这不会将购物车中的额外金额费用添加到总额中。我还会在回显会话变量时检查会话变量中是否存在值,然后在结帐页面上显示值,但下单按钮变为禁用状态。
function woo_add_cart_fee() {
$_SESSION["extra_price2"]=$_POST["mounting_amount"];
$abcs = (int) $_SESSION["extra_price2"];
global $woocommerce;
$woocommerce->cart->add_fee( __('Ship Installer Fees', 'woocommerce'), $abcs );
}请帮帮忙
发布于 2019-03-04 21:34:38
function woo_add_cart_fee() {
if(isset($_POST['mounting_amount'] ) && $_POST['mounting_amount'] ){
WC()->session->set( 'mounting_amount' , $_POST['mounting_amount'] );
}
$abcs = WC()->session->get( 'mounting_amount' );
global $woocommerce;
$woocommerce->cart->add_fee( __('Delivery', 'woocommerce'), $abcs );
}https://stackoverflow.com/questions/36639223
复制相似问题