2017-02-06 2 views
3

WooCommerceのチェックアウトフィールドで、チェックアウトフォームのbilling_address_1の上にbilling_address_2を作成しようとしています。チェックアウトフィールド - billing_address_1をbilling_address_1より上にする

ので、代わりのそれがあること:

Street Address 
Apartment 

私が持っているしたいと思います:

Apartment 
Street Address 

も、私はAvadaと呼ばれるテーマを使用していますのでご注意ください。

どうすればこの問題を解決できますか?

ありがとうございました。

+0

チェック[この回答](http://wordpress.stackexchange.com/questions/78339/how-to-reorder-billing- fields-in-woocommerce-checkout-template) –

答えて

3

を更新(あなたのコメントに関連した)...ここで

あなたもその場を作り、アドレス1フィールドから「アドレス」テキストラベルを削除し、アドレス2のフィールドに設定し追加を持っている(オプション)が必要と変更ちょっとしたプレースホルダー...もう一つの解決策もあります(コードの後ろを見てください)。ここで

コードです:あなたはフィールドの順序を変更する必要はありませんので、

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

    // 1. Customizing address_1 and address_2 fields 
    $fields['billing']['billing_address_1']['label'] = ''; // Removing the label from Adress1 
    $fields['billing']['billing_address_2']['label'] = __('Address', 'theme_domain'); 
    $fields['billing']['billing_address_2']['required'] = true; // Making Address 2 field required 
    $fields['billing']['billing_address_2']['placeholder'] = __('Apartment, suite, unit etc...', 'woocommerce'); 

    // 2. Custom ordering the billing fields array (toggling address_1 with address_2) 
    $custom_fields_order = array(
     'billing_first_name', 'billing_last_name', 
     'billing_company', 
     'billing_email',  'billing_phone', 
     'billing_country', 
     'billing_address_2', 'billing_address_1', ## <== HERE, changed order 
     'billing_postcode', 'billing_city' 
    ); 

    foreach($custom_fields_order as $field) 
     $new_ordered_fields[$field] = $fields['billing'][$field]; 

    // Replacing original fields order by the custom one 
    $fields['billing'] = $new_ordered_fields; 


    // Returning Checkout customized billing fields order 
    return $fields; 
} 

代わりの2つのフィールドは、あなたがフィールドのプレースホルダを反転し、メイクを追加することができることをトグル(オプション)、アドレス2フィールドを必要としていました。あなたは、このようにそれを行うことができます。

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

    // 1. Customizing address_1 and address_2 fields 
    $fields['billing']['billing_address_1']['placeholder'] = __('Apartment, suite, unit etc...', 'woocommerce'); 
    $fields['billing']['billing_address_2']['required'] = true; // Making Address 2 field required 
    $fields['billing']['billing_address_2']['placeholder'] = __('Street address', 'woocommerce'); 

    // Returning Checkout customized billing fields 
    return $fields; 
} 

コードは、任意のプラグインファイルでも、あなたのアクティブな子テーマ(またはテーマ)のfunction.phpファイルになりますか。

コードがテストされ、動作します。


関連の答え:Checkout fields: Hiding and showing existing fields

公式ドキュメント:Customizing checkout fields using actions and filters

+0

私はそれを以前に試みましたが、それは私の最初の本能でしたが、これはちょうど起こります。 http://i.imgur.com/XiInJG3.png –

+0

@BarryHanburyこれについて少し更新する必要があります。準備ができたらお知らせします。 – LoicTheAztec

+0

@BarryHanbury私は自分の答えを更新しました...そして期待通りに働いています... – LoicTheAztec

関連する問題