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

标签 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_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 );

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

提前致谢, -本

最佳答案

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

Screenshot for shipping tab

关于php - WooCommerce 结帐 - 如何为特定地址提供免费送货服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34407862/

相关文章:

PHP MySQL 插入不工作

php - 如何扩展异常以发送电子邮件

php - Trim 和 htmlspecialchars 安全吗?

php - 回显数组值的问题

wordpress - 通过CSS将标题放在前面

python - 代理服务器上的 WordPress 和 Python

javascript - WooCommerce 单个产品图像悬停缩放闪烁

qt - 自己的静态链接插件

javascript - 向下滚动时,粘性标题过渡变得跳跃和丑陋

github - 从 github 存储库加载时 Gradle 独立插件未知属性