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

Php WooCommerce结帐-如何为特定地址提供免费送货服务,php,wordpress,plugins,woocommerce,checkout,Php,Wordpress,Plugins,Woocommerce,Checkout,以下代码将允许免费运送特定产品: 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_car

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

    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

Woocommerce已经有了航运区。对于每个特定区域,您可以设置“固定费率”或“免费配送”的配送方式。您可以在Woocommerce->Settings下进行检查。查找配送选项卡


是的,您可以将一个额外的参数传递到此hook names$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包含您输入的地址,因此您可以使用此地址为选定的邮政编码或街道申请免费送货

使用检查地址的逻辑更改
foreach(){}
<代码>返回真值表示这是免费送货。