woocommerce,如何在购物车产品总价中增加额外费用?

时间:2014-11-25 19:02:46

标签: wordpress woocommerce

我想在购物车产品总价中添加额外费用,而不是产品价格或整个购物车总价。我指的是产品总价。

现在我没有尝试,我也没有任何代码。

add_action( 'woocommerce_before_calculate_totals', 'function add_additional_price' );
function add_additional_price( $cart_object ) {
    $custom_price = 10; // This will be your custome price  
}

1 个答案:

答案 0 :(得分:3)

你可以试试这个

// Change the line total price
add_filter( 'woocommerce_get_discounted_price', 'calculate_discounted_price', 10, 2 );
// Display the line total price
add_filter( 'woocommerce_cart_item_subtotal', 'display_discounted_price', 10, 2 );

function calculate_discounted_price( $price, $values ) {
    // You have all your data on $values;
    $price += 10;
    return $price;
}

// wc_price => format the price with your own currency
function display_discounted_price( $values, $item ) {
    return wc_price( $item[ 'line_total' ] );
}
相关问题