woo_add_cart_fee无法正常工作

问题描述 投票:1回答:1

add_action( 'woocommerce_calculate_totals', 'woo_add_cart_fee' );

我正在使用此挂钩在购物车总金额中添加额外的金额。如果我在此功能中给出静态值,这项工作正常,并在购物车总金额中添加额外的金额费用,但是当我在隐藏的字段中提供额外的金额和会话变量的值时,这不会在购物车中添加额外的金额费用总额。我也检查会话变量中存在的值当我回显会话变量然后在结帐页面上显示值但是下订单按钮变为禁用。

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

}

请帮忙

javascript php jquery wordpress-plugin
1个回答
1
投票
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 );
}
© www.soinside.com 2019 - 2024. All rights reserved.