woocommerce 在下订单前检查邮政编码 [英] woocommerce check zip code before placing order

查看:25
本文介绍了woocommerce 在下订单前检查邮政编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于本地交付是唯一的选择(由于产品交付限制),我不希望客户进入结账页面并且必须填写他们的所有详细信息,然后才发现我们没有交付到他们的邮政编码.

As local delivery is the only option (due to product delivery restrictions) I do not want a customer to get to the checkout page and have to fill out all their details and only then discover we do not deliver to their postcode.

因此,我需要在结帐页面具有与本地递送邮政编码检查相同的功能,但要在结帐过程的较早阶段添加,例如在购物车页面上?或任何其他页面,就此而言.最佳位置可以在添加到购物车选项之前的产品页面中.

Therefore, I require the same functionality of the Local Delivery postcode check at the Checkout page, but to be added at an earlier stage in the checkout process, such as on the Cart page? Or any other page, for that matter. Best place can be in product page before add to cart option.

即输入您的邮政编码,看看我们是否可以送货到您所在的地区:结果 - 显示是或否消息,并附有进一步说明

i.e. Enter your postcode to see if we deliver to your area: Result - a yes or no message appears with further instructions

推荐答案

您可以使用 woocommerce_cart_coupon 挂钩向购物车添加新字段,然后可以使用 template_redirect 挂钩创建处理程序.

You can add a new field to the cart by using the woocommerce_cart_coupon hook and then you can create a handler using the template_redirect hook.

我们之前在我们的网站上使用过的类似下面的内容:

Something like the below which we have used on our sites before:

add_action( 'woocommerce_cart_coupon', array(&$this, 'new_woocommerce_cart_coupon'), 10, 0 );
add_action( 'template_redirect', array(&$this, 'new_post_code_cart_button_handler') );

public function new_woocommerce_cart_coupon() {
    ?>
        <br/><br/><p>Enter your postcode</p><label for="post_code">Post Code</label> <input type="text" name="post_code" class="input-text" id="post_code" value="" /> <input type="submit" class="button" name="apply_post_code" value="Check Post Code" />
    <?php
}

public function new_post_code_cart_button_handler() {
    if( is_cart() && isset( $_POST['post_code'] ) && $_SERVER['REQUEST_METHOD'] == "POST" && !empty( $_POST['post_code'] ) ) {
      //validate post code here
    }
}

这篇关于woocommerce 在下订单前检查邮政编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆