woocommerce,我如何在购物车产品总价中添加额外费用? [英] woocommerce, how can i add additional cost in cart product total price?

查看:31
本文介绍了woocommerce,我如何在购物车产品总价中添加额外费用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to add additional cost in the cart product total price, not in product price nor the whole cart total price. I am referring about the product total price.

现在我还没有尝试过,也没有任何代码.

Right now i have not not try and I don't have any code.

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  
}

推荐答案

你可以试试这个

// 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' ] );
}

这篇关于woocommerce,我如何在购物车产品总价中添加额外费用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆