2017-11-17 5 views
0

国/都道府県のドロップダウンを検索します。私は国家の自動住人になっているが、都市はうまくいっていない。デフォルトでは国を取得することができます。自動値のドロップダウン国/州/都市woocommerce店頭

  // State-Country additions 

     /** 
     * Code goes in functions.php or a custom plugin. 
     */ 

     add_filter('woocommerce_states', 'SA_woocommerce_states'); 
     function SA_woocommerce_states($states) { 
      $states['ZA'] = array(
       'EC' => __('Eastern Cape', 'woocommerce'), 

     ); 
      return $states; 
     } 

     // Change "city" checkout billing and shipping fields to a dropdown 

     add_filter('woocommerce_checkout_fields', 'override_checkout_city_fields'); 
     function override_checkout_city_fields($fields) { 

      // Define here in the array your desired cities (Here an example of cities) 
      $option_cities = array(
       '' => __('Select your city'), 
       'a' => 'a', 

     ); 

      $fields['billing']['billing_city']['type'] = 'select'; 
      $fields['billing']['billing_city']['options'] = $option_cities; 
      $fields['shipping']['shipping_city']['type'] = 'select'; 
      $fields['shipping']['shipping_city']['options'] = $option_cities; 

      return $fields; 
     } 
+0

これは完全な例ではありませんので、我々は再現できませんあなたの問題は簡単に。あなたのコードが何をし、何を期待しているのかを詳しく教えてください。 – JHBonarius

+0

あなたが達成しようとしていることを詳しく教えてください。 –

答えて

0

実際のコードでは、「南アフリカ」(ZA)の既存の状態をすべて1つの状態に置き換えます。あなたが少しをこのようにコードを変更する必要がある必要があり、この状態を追加するには

enter image description here

:だからあなたのような何かを得ている

add_filter('woocommerce_states', 'sa_woocommerce_states'); 
add_filter('woocommerce_countries_allowed_country_states', 'sa_woocommerce_states'); 
function SA_woocommerce_states($states) { 
    $states['ZA']['EC'] = __('Eastern Cape', 'woocommerce'); 
    return $states; 
} 

コードは、あなたのfunction.phpファイルに行きますアクティブな子のテーマ(またはテーマ)、またはすべてのプラグインファイルに保存されます。

テスト済みで動作します。あなたはその代わりに、この時間を取得します。(

add_filter('woocommerce_default_address_fields', 'override_checkout_city_fields', 10, 1); 
function override_checkout_city_fields($fields) { 

    // Define here in the array your desired cities (Here an example of cities) 
    $option_cities = array(
     '' => __('Select your city'), 
     'a' => 'a', 

    ); 

    $fields['city']['type'] = 'select'; 
    $fields['city']['options'] = $option_cities; 

    return $fields; 
} 

コードは、あなたのアクティブな子テーマのfunction.phpファイルに行く:

enter image description here

は、都市の自動車は、あなたがこれを使用する必要があります読み込まれますしますまたはテーマ)または任意のプラグインファイルでも使用できます。

テスト広告が動作する...

しかし、あなたはStackOverflowの

のために、これは本当の発展であると状態によって都市を取得し、あまり広くないだろう
+0

あなたのレスポンスに感謝します。私は州を得ることができますが、例えば都市はありません。 – Ferna

+0

@Fernaはいこれはあまりにも広範で実際の開発です... WC_CountriesクラスとWC_Checkoutクラスを拡張するプラグインを作成する必要があります。開発者をネット上のどこでも無料で入手しない方がよいでしょう。プラグインが終了するかどうかを確認することができます... StackOverFlowは無料のコーディングサービスではありません。それはあなたに幸運を言った – LoicTheAztec

+0

私はここに学ぶために、その広範なnotice.Thanksにかかります。 – Ferna

関連する問題