从Woocommerce购物车页面上的购物车总额中扣除运费

时间:2017-08-17 14:32:53

标签: php wordpress woocommerce cart shipping

是否有任何woocommerce挂钩/方法,我可以通过该挂钩/方法从购物车的总数中排除运费?

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

1 个答案:

答案 0 :(得分:1)

使用隐藏在 woocommerce_calculate_totals 操作挂钩中的此自定义功能,您将从购物车总计(仅限购物车页面中的显示)中排除运费:

// 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文件中,或者放在任何插件文件中。

经过测试和工作......

相关问题