如何在woocommerce中隐藏特定州的billing_city字段

时间:2020-06-16 21:16:23

标签: woocommerce

请给我一些帮助。我需要为特定选定的州隐藏billing_city字段。 首先,我只需要1个状态。 我一直在探索Internet,并找到了摘要,将其用于我的目的。结果,它工作正常。但是现在我需要隐藏1个以上州的billing_city字段。如果有人可以帮助解决我的问题,我将不胜感激。 谢谢!

// hide billing_city字段为77个州

 add_action( 'woocommerce_after_checkout_form', 'hide_show_billing_city', 5);

 function hide_show_billing_city() {

     ?>
       <script type="text/javascript">

          jQuery('select#billing_state').live('change', function(){


             var state = jQuery('select#billing_state').val();

             var check_state = new Array(<?php echo '"77"'; ?>);

             if (state && jQuery.inArray( state, check_state ) >= 0) {
               jQuery('#billing_city_field').fadeOut();
             } else {
               jQuery('#billing_city_field').fadeIn();
               jQuery('#billing_city_field input').val('');
              }       
            });
    </script>
 <?php
}

0 个答案:

没有答案