WooCommerce结帐 - 如何为特定地址免费送货

Ben*_*ino 5 php wordpress plugins checkout 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 );
Run Code Online (Sandbox Code Playgroud)

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

提前谢谢,-Ben

小智 0

Woocommerce 中已经有可用的运输区域。对于每个特定区域,您可以将送货方式设置为“统一费率”或“免费送货”。您可以在 Woocommerce-> 设置下进行检查。找到“运输”选项卡。

运输选项卡的屏幕截图