[英]How to change woocommerce each product total only in cart
I have my checkout cart like this 我有这样的结帐车
product price quantity total 产品价格数量合计
apple 50 1 50 苹果50 1 50
orange 40 1 40 橙色40 1 40
I need to change the total on the right side to say 20 我需要将右侧的总数更改为20
Code I tried i will put on comment box 我尝试过的代码将放入评论框
but it changes the price.I only need to change the total.Any ideas? 但是它改变了价格。我只需要改变总数。有什么想法吗?
Try with this piece of code in the functions.php file: 尝试在functions.php文件中使用以下代码:
if(is_cart()){
add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' );
function add_custom_price( $cart_object )
{
global $woocommerce;
$custom_price = $_POST["custom_prc"];
foreach ( $cart_object->cart_contents as $key => $value )
{
$value['data']->price = $custom_price;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.