我使用 add_fee 方法来收取我的购物车价格。它工作正常,但是当我单击结帐按钮并转到结帐页面或刷新页面时,新价格消失并且旧价格在那里。如何将我的价格保存在购物车中?
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');