2017-02-21 157 views
0

我有一个小问题,试图设置免费送货在最新Woocommerce(2.6.x)如果某些条件得到满足。WordPress的免费送货,如果国家和支付网关

如果选择“货到付款”,客户想要设置免费送货,价格超过X€并选择某个国家/地区。

我正在尝试很多我发现的片段,但似乎没有任何工作。我不希望使用太多的插件(已经有很多)。

我需要这样的东西:

if ($country == 'DE' && $cart_total >= 100 && $payment_gateway == 'cod') { 
    $shipping == 0; 
} 

感谢您对所有的答案提前,
法理

回答

0

我使用Table Rate Shipping for WordPress,我找到了解决我的问题。缺少付款方式检查,但这不应该很难找到。以防万一其他人发现它有用。

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

function sl_custom_shipping_rates($rates, $package) { 

    foreach($rates as $key => $value) { 

     if($value->method_id == 'table_rate_shipping' && WC()->cart->cart_contents_total >= 100 && WC()->customer->get_shipping_country() == "DE") { 
      $rates[ $key ]->cost = 100; 
     } 
    } 

    return $rates; 
}