购物车项目总计已更改,但购物车总计仍根据产品原始价格来计算

时间:2020-02-07 13:30:54

标签: php wordpress woocommerce hook

使用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;
}

此代码在购物车表格数据中显示正确的计算价格。

enter image description here

0 个答案:

没有答案