首页 > 解决方案 > 如何在 woocommerce 中隐藏特定州的 billing_city 字段

问题描述

我需要一些帮助,拜托。我需要隐藏特定选定州的 billing_city 字段。首先,我只需要 1 个州。我一直在探索互联网并找到了该片段,并将其用于我的目的。结果,它工作正常。但现在我需要隐藏超过 1 个州的 billing_city 字段。如果有人可以帮助解决我的问题,我将不胜感激。谢谢!

//隐藏 77state 的 billing_city 字段

 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
}

标签: woocommerce

解决方案


推荐阅读