I use add_fee method to charge my cart price. It works and it is OK but when I click the checkout button and I go to the checkout page or I refresh the page the new price disappear and old price is there . How can I save my price in cart?
function woo_add_cart_fee($cart_obj) {
global $woocommerce;
$count = $_POST['qa'];
$extra_shipping_cost = 0;
//Loop through the cart to find out the extra costs
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
//Get the product info
$_product = $values['data'];
//Adding together the extra costs
$extra_shipping_cost = $extra_shipping_cost + $_product->price;
}
$extra_shipping_cost = $extra_shipping_cost * $count;
//Lets check if we actually have a fee, then add it
if ($extra_shipping_cost) {
$woocommerce->cart->add_fee( __('count', 'woocommerce'), $extra_shipping_cost );
}
}
add_action( 'woocommerce_before_calculate_totals', 'woo_add_cart_fee');