WooCommerce结账-如何为特定地址提供免费送货服务



以下代码将允许特定产品的免费送货:

    function wcs_my_free_shipping( $is_available ) {
    global $woocommerce;
    // set the product ids that are eligible
    $eligible = array( '360' );
    // get cart contents
    $cart_items = $woocommerce->cart->get_cart();
    // loop through the items looking for one in the eligible array
    foreach ( $cart_items as $key => $item ) {
        if( in_array( $item['product_id'], $eligible ) ) {
            return true;
        }
    }
    // nothing found return the default value
    return $is_available;
   }
   add_filter( 'woocommerce_shipping_free_shipping_is_available', 'wcs_my_free_shipping', 20 );

我想做的不是允许产品免费送货,而是允许送货地址中的特定街道和邮政编码组合免费送货。我发现了如何为登录用户检查此信息,但在结账时似乎找不到具有此信息的正确变量。如有任何帮助,我们将不胜感激。

提前感谢,-Ben

Wooccommerce中已经有可用的运输区域。对于每个特定区域,您可以设置运输方式"统一费率"或"免费运输"。您可以在Wooccommerce->设置下进行检查。查找运输标签。

运输选项卡的屏幕截图

是的,您可以,有一个额外的参数可以传递到这个hooknames$package中
例如

   add_filter( 'woocommerce_shipping_free_shipping_is_available', 'wcs_my_free_shipping', 20,2 );
function wcs_my_free_shipping( $is_available, $package){
//Your code for free shipping  for a selected address found in $package
return $is_available
}

$package包含您输入的地址,因此您可以使用该地址为选定的邮政编码或街道申请免费送货。

最新更新