簡體   English   中英

WooCommerce 發貨 State Select

[英]WooCommerce Shipping State Select

我需要覆蓋 WooCommerce 結帳中的所有狀態,但我只需要為運輸部分執行此操作。

所以“billing_state”在意大利所有當前的州都可以正常工作,我只需要用新州覆蓋“shipping_state”。

使用下面的代碼將覆蓋 billing_states 和運輸狀態。 如何修改代碼以覆蓋“shipping_states”

提前致謝

add_filter( 'woocommerce_states', 'custom_woocommerce_states' );

  function custom_woocommerce_states( $states ) {
  $states['IT'] = array(
    //I have to display only these 3 states in shipping Checkout
    'TV' => 'Treviso',
    'CA' => 'Carità',
    'CS' => 'Castrette',
  );

  return $states;
}

這就是你要找的。 將此添加到您的活動子主題functions.php

請參閱此WebToffee 文章

add_action( 'wp_footer', 'webtoffee_checkout_shipping_filter_it_states' );

function webtoffee_checkout_shipping_filter_it_states() {
   if ( ! is_checkout() ) {
      return;
   }
   ?>

   <script>
   jQuery(document).ready(function($) {

      $(document.body).on('country_to_state_changed', function() {

         var $shipping_country = $('#shipping_country');

         var new_shipping_state = '';

         switch($shipping_country.val()) {
            case 'IT':
               new_shipping_state =  {'TV': "Treviso", "CA": "Carità", "Cs": "Castrette"};
               break;
         }

             if( ! $.isEmptyObject(new_shipping_state)) {

                var optionsAsString = "";
                for (var key in new_shipping_state) {
                    optionsAsString += "<option value='" + key + "'>" + new_shipping_state[key] + "</option>";
                }
                $( 'select[name="shipping_state"]' ).html( optionsAsString );

             } 

      });

   });  
   </script>

   <?php
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM