Waseem Ahmed Tunio
Waseem Ahmed Tunio

Reputation: 11

woo_add_cart_fee not working

add_action( 'woocommerce_calculate_totals', 'woo_add_cart_fee' );

i am using this hook for add extra amount charges in cart total amount. if i give static value in this function this work properly and add extra amount charges in cart total amount but when i give extra amount in hidden field post and value in session variable then this not add extra amount charges in cart to total. i also check value is exist in session variable when i echo session variable then show value on checkout page but place order button become disable.

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

}

please help

Upvotes: 1

Views: 176

Answers (1)

Arthur  Sergheevich
Arthur Sergheevich

Reputation: 63

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

Upvotes: 1

Related Questions