Php 基于邮政编码的最低订购量

Php 基于邮政编码的最低订购量,php,woocommerce,hook-woocommerce,Php,Woocommerce,Hook Woocommerce,我试图根据用户在woocommerce结账页面上输入的邮政编码/pin码实现最低订单。 我在theme的functions.php中尝试了以下代码,但仍然没有得到任何想要的输出 当我点击PlaceOrder按钮时,控制台中出现checkout.min.js错误。 当我重新加载结帐页面时,我能够看到所需的错误(“您没有达到最低订单总数”) 我相信我在function.php中犯了一些错误 我们高度赞赏整改工作 功能检查\u最小顺序($order\u id){ 全球商业; $order=新WC\U

我试图根据用户在woocommerce结账页面上输入的邮政编码/pin码实现最低订单。 我在theme的functions.php中尝试了以下代码,但仍然没有得到任何想要的输出

当我点击PlaceOrder按钮时,控制台中出现checkout.min.js错误。 当我重新加载结帐页面时,我能够看到所需的错误(“您没有达到最低订单总数”)

我相信我在function.php中犯了一些错误

我们高度赞赏整改工作

功能检查\u最小顺序($order\u id){
全球商业;
$order=新WC\U订单($order\U id);
$address=$order->get_address();
$total=$order->calculate_totals();
$postcode=$address['postcode'];
$zipcodes1=数组('400064','400062','400067');
$zipcodes2=数组('400054','400042','400071');
$minOrderZip1=500;
$minOrderZip2=1500;

如果(在数组中($postcode,$zipcodes1)&&&$total阅读此文档:@Rahul,我有相同的问题。您找到解决方案了吗?阅读此文档:@Rahul,我有相同的问题。您找到解决方案了吗?
        function check_min_order($order_id) {
              global $woocommerce;
                 $order = new WC_Order($order_id);
                 $address = $order->get_address();
                 $total = $order->calculate_totals();
                 $postcode= $address['postcode'];
                 $zipcodes1 = array('400064' , '400062' , '400067');
                 $zipcodes2 = array('400054' , '400042' , '400071');

        $minOrderZip1 =500;
        $minOrderZip2 =1500;

        if(in_array($postcode, $zipcodes1) && $total <= $minOrderZip1 ){
                     wc_add_notice( "You did not meet the minimum order total. $minOrderZip1", 'error' );
                     exit;
                 }
                 if(in_array($postcode, $zipcodes2) && $total <= $minOrderZip2 ){
                     wc_add_notice( "You did not meet the minimum order total. $minOrderZip2", 'error' );
                     exit;
                 }
        }
        add_action( 'woocommerce_checkout_order_processed', 'check_min_order',  1, 1  );