【问题标题】:Exclude shipping costs from cart's total on Woocommerce cart page从 Woocommerce 购物车页面上的购物车总额中排除运费
【发布时间】:2017-08-17 14:32:52
【问题描述】:

是否有任何 woocommerce 挂钩/方法可以让我从购物车总额中排除运费?

我到处搜索,但似乎找不到答案。

【问题讨论】:

    标签: php wordpress woocommerce cart shipping


    【解决方案1】:

    使用挂在 woocommerce_calculate_totals 动作钩子中的自定义函数,您将从购物车总数中排除运费(仅显示在购物车页面中): p>

    // For WooCommerce versions from 2.5.x up to 3+
    add_action( 'woocommerce_calculate_totals', 'custom_cart_displayed_totals', 10, 1 );
    function custom_cart_displayed_totals( $cart_object ) {
    
        if ( is_admin() && ! defined( 'DOING_AJAX' ) )
            return;
    
        // Only on cart page
        if ( ! WC()->cart->is_empty() && is_cart() ):
    
            ## Get The shipping totals
            $shipping_tax_amount = $cart_object->shipping_total;
            $shipping_total_excl_tax = $cart_object->shipping_tax_total;
    
            ## Displayed subtotal
            // $cart_object->subtotal = 0;
    
            ## Displayed TOTAL
            // $cart_object->total = 0;
    
            ## Displayed TOTAL
            $cart_object->tax_total -= $shipping_tax_amount;
    
            ## Displayed TOTAL
            $cart_object->cart_contents_total -= $shipping_total_excl_tax;
    
        endif;
    }
    

    代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件中。

    经过测试并且可以工作……

    【讨论】:

    • 是否可以在结帐页面上做同样的事情?例如,我们显示石平价格(由插件计算)仅用于批发用户角色的信息。那么我们应该在代码中编辑什么?
    • @kh1 如果您也希望在结帐时也发生这种情况,您应该从 if 语句中删除 && is_cart()...
    • 我试过了,但没有运气。我可以对小计进行操作,但不能对总计进行操作(在结帐页面上)总体而言,我希望将总计视为小计,包括折扣和不包括运费但运费应该保持可见
    • @kh1 这是一个旧答案,自 WooCommerce 3.2 以来,WC_Cart 类的情况发生了变化……
    猜你喜欢
    • 2019-04-21
    • 2018-05-20
    • 2019-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-01
    • 1970-01-01
    • 2020-06-06
    相关资源
    最近更新 更多