Wordpress woocommerce,如何在购物车产品总价中添加额外成本?
我想在购物车产品总价中添加额外成本,而不是在产品价格或整个购物车总价中。我指的是产品的总价 现在我还没有尝试,也没有任何代码Wordpress woocommerce,如何在购物车产品总价中添加额外成本?,wordpress,woocommerce,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
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' ] );
}
代码不工作,我认为函数没有在hook中调用。你们能再解释一下吗?是的,我忘了更改函数名了。谢谢你们的回答,它也能工作。但是从前面的答案中得到一个问题。用产品名称显示价格。这也是工作,但总价格显示与标题,我想显示实际的产品价格。请帮忙。这是前面的问题链接:如果我理解正确:您需要在标题上显示正确的价格,在价格列上显示折扣价格?不,我只想用标题显示实际产品价格。不增加额外费用。如在价格栏中显示,而不是在总价栏中显示。