由于本地送货是唯一的选择(由于产品送货限制),我不希望客户进入结帐页面并必须填写他们的所有详细信息,然后才发现我们没有送货到他们的邮政编码。
因此,我需要在结帐页面上进行与本地配送邮政编码检查相同的功能,但要在结帐过程的早期阶段添加,例如在购物车页面上?或任何其他页面,就此而言。最好的位置可以在添加到购物车选项之前的产品页面中。
IE。
输入您的邮政编码以查看我们是否送货到您所在的地区:
结果 - 出现是或否消息以及进一步说明
您可以使用 woocommerce_cart_coupon 挂钩向购物车添加新字段,然后可以使用 template_redirect 挂钩创建处理程序。
我们之前在我们的网站上使用过如下内容:
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
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)