使用woocommerce,我必须为每个产品添加设置价格,并将其显示在购物车和结帐页面上。因此,现在我更改了购物车页面上商品的小计,但问题是购物车总计未按商品小计进行计算,而未按原始产品价格显示。请看截图并告诉我该怎么办?
add_filter( 'woocommerce_cart_item_subtotal', 'setup_price_in_item_subtotal', 99, 3 );
function setup_price_in_item_subtotal( $subtotal, $cart_item, $cart_item_key ){
global $woocommerce;
$setup_price = get_post_meta( $cart_item['product_id'], 'setup_price', true );
$newsubtotal = wc_price( $cart_item['data']->get_price() * $cart_item['quantity'] + $setup_price);
$subtotal = sprintf( $newsubtotal );
return $subtotal;
}
此代码在购物车表格数据中显示正确的计算价格。