【问题标题】:woocommerce shipping should include on checkout pagewoocommerce 运输应包含在结帐页面上
【发布时间】:2016-03-02 07:39:01
【问题描述】:

如何从购物车页面中排除运费?这意味着它应该只包含在结帐页面上。

我是 woocommerce 的新手,对此我知之甚少。在我的项目中,我不想在购物车页面上包含运费。我试过这个

add_filter('woocommerce_cart_needs_shipping', '__return_false');

但在我删除代码之前,它会隐藏整个项目的运费(费用+地址)。

【问题讨论】:

  • 意思是结帐页面会包含运费,对吧?
  • 是的。运费应仅包含在结帐页面上。

标签: woocommerce


【解决方案1】:

您必须像这样在购物车页面上取消设置其他运输方式:

//functions.php

add_filter( 'woocommerce_package_rates','hide_shipping_when_free_is_available', 10, 2 );

function hide_shipping_when_free_is_available( $rates, $package ) {

    // Check if it is cart page
    if (is_cart() ) {

        // To unset a single rate/method, do the following. This example unsets flat_rate shipping
        unset( $rates['flat_rate'] );

        // To unset all methods except for free_shipping, do the following
        $free_shipping          = $rates['free_shipping'];
        $rates                  = array();
        $rates['free_shipping'] = $free_shipping;
    }

    return $rates;
}

如果您这样使用,您可以取消设置其他运输方式:

unset( $rates['flat_rate'] );

【讨论】:

    猜你喜欢
    • 2020-05-11
    • 1970-01-01
    • 2013-06-21
    • 2021-04-21
    • 2016-06-15
    • 2015-01-17
    • 2019-05-04
    • 2018-08-28
    • 1970-01-01
    相关资源
    最近更新 更多