简体   繁体   English

如何仅在购物车中更改woocommerce每个产品的总数

[英]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.

相关问题 在 WooCommerce 产品页面中显示数量变化的产品总数和购物车小计 - Display product total and cart subtotal on quantity change in WooCommerce product page 如何更改 woocommerce 迷你购物车总数(基于产品名称而不是数量)? - How to change woocommerce mini cart total (based on product name instead of quantity)? 如何使用购物车总数更改 WooCommerce 中的购物车商品价格 - How to use cart total to change cart items prices in WooCommerce Woocommerce 更改购物车中每个产品的数量最小限制 - Woocommerce change quantity min limit for each product in cart 在 WooCommerce 中更改购物车总价 - Change Cart total price in WooCommerce 仅在 WooCommerce 单个产品页面上将添加到购物车文本更改为“应用” - Change Add to Cart text to “Apply” on WooCommerce single product pages only 在 WooCommerce 购物车页面中的购物车表上显示消息(每个产品上方的消息将根据数量而变化) - Showing message on cart table(above each product.message will change based on qty) in WooCommerce cart page Woocommerce:如何在购物车中只允许一种产品类型? - Woocommerce: How to allow only one product type in a cart? 当产品添加到 WooCommerce 中的购物车时,如何只运行一次脚本? - How to run script only once when a product added to the cart in WooCommerce? 在Woocommerce中将产品添加到购物车时,如何更改成功消息? - How to change message of success when adding product to cart in Woocommerce?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM