【问题标题】:How to change methor free shipping follow price product in woocommerce如何在 woocommerce 中更改免费送货跟随价格产品
【发布时间】:2014-08-14 17:11:53
【问题描述】:

我在插件 woocommerce wordpress 中尝试自定义统一费率,默认统一费率任何等级 45 美元,但我希望产品价格从 11 美元起免运费。 请帮帮我!

 add_filter('woocommerce_shipping_free_shipping_is_available', 'diy_free_delivery');
 function diy_free_delivery($rates, $package){
    $product = new WC_Product();
    $price = $product->regular_price;
    if($price > 11){
        unset( $rates['flat_rate'] );

        $free_shipping = $rates['free_shipping'];
        $rates         = array();
        $rates['free_shipping'] = $free_shipping;
    }
    return $rates;
 }

【问题讨论】:

  • 运费通常是根据购物车总数计算的 - 如果客户的产品超过 11 美元将免费,您想免费送货,否则向他们收取 45 美元的运费?
  • 如果客户有超过 11 美元的产品,我想免费送货,并且不使用 45 美元的运费
  • 那么如果购物车中商品的总价值大于 11 美元,他们可以获得免费送货吗?无论是 1 件 12 美元的产品还是 2 件每件 6 美元的产品都没有关系?
  • 因为我只允许购买 1 件产品 1 次,所以我忽略了大写

标签: wordpress woocommerce


【解决方案1】:

您应该使用woocommerce_package_rates 过滤器来根据您的购物车的价值确定哪些运输选项可用。过滤器将传入 $available_methods,您可以使用 WC()->get_cart_subtotal() 在您的函数中根据购物车的值进行修改。

add_filter( 'woocommerce_package_rates', 'diy_free_delivery' );
function diy_free_delivery( $available_methods ){
    // check to see if the cart total is more than $11
    if ( WC()->get_cart_subtotal() > 11 ){
        // if it is we *only* want to show the free shipping
        return array( 'free_shipping' => $available_methods['free_shipping'] );
    } else {
        // if not we want to remove free_shipping and return the other methods
        unset( $available_methods['free_shipping'] );
        return $available_methods;
    }
}

【讨论】:

  • 糟糕,尝试使用更新的答案示例 - return array( 'free_shipping' => $available_methods['free_shipping'] );
猜你喜欢
  • 2017-03-10
  • 1970-01-01
  • 2021-05-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-01
  • 2018-10-16
  • 1970-01-01
  • 2017-04-06
相关资源
最近更新 更多