2016-06-02 2 views
1

Ich benutze woocommerce_checkout_fields Filter für die Anpassung der Platzhalter in WooCommerce Checkout-Seite.Anpassen von Platzhalter in Abrechnungs-/Versandformularen

add_filter('woocommerce_checkout_fields' , 'custom_override_checkout_fields'); 
    function custom_override_checkout_fields($fields) { 
    $fields['billing']['billing_first_name']['placeholder'] = 'Name'; 
    $fields['billing']['billing_last_name']['placeholder'] = 'Surname'; 
    $fields['billing']['billing_email']['placeholder'] = 'Email'; 
    $fields['billing']['billing_company']['placeholder'] = 'Company Name'; 
    $fields['billing']['billing_phone']['placeholder'] = 'Phone'; 
    $fields['billing']['billing_postcode']['placeholder'] = 'Zip Code'; 
    $fields['billing']['billing_city']['placeholder'] = 'City'; 

    $fields['shipping']['shipping_first_name']['placeholder'] = 'Name'; 
    $fields['shipping']['shipping_last_name']['placeholder'] = 'Surname'; 
    $fields['shipping']['shipping_city']['placeholder'] = 'City'; 
    $fields['shipping']['shipping_postcode']['placeholder'] = 'Zip Code'; 
    return $fields; 
    } 

Dies funktioniert nur für Kassenformular.

Wie können 'Platzhalter' in allen Versand- und Rechnungsformularen angepasst werden?

Danke.

Antwort

2

Wenn Sie meinen, in Mein Konto Seiten für Rechnungs- und Versandform, die nur Filterhaken (die ich kenne), die den Trick tun könnte, ist:

add_filter('woocommerce_form_field_args', 'custom_form_field_args', 10, 3); 
function custom_form_field_args($args, $key, $value) { 
    // your code 
    return $args; 
}; 

Es befindet sich in wc-template-functions.php on line 1734, ausgelöst durch woocommerce_form_field() Funktion in Woocommerce-Vorlagen unter my_account Unterordner, form-edit-address.php Datei (Anzeige der Formularfelder).


Dies sind der Standard $args Sie die Änderungen Ziel verwenden können, um Sie in Ihrer Filterfunktion zu tun:

$defaults = array(
    'type'    => 'text', 
    'label'    => '', 
    'description'  => '', 
    'placeholder'  => '', 
    'maxlength'   => false, 
    'required'   => false, 
    'autocomplete'  => false, 
    'id'    => $key, 
    'class'    => array(), 
    'label_class'  => array(), 
    'input_class'  => array(), 
    'return'   => false, 
    'options'   => array(), 
    'custom_attributes' => array(), 
    'validate'   => array(), 
    'default'   => '', 
); 

Hinweis: Bei einige von Stone Änderungen es funktioniert.(siehe den Kommentar).

ANWENDUNG:
Sie ‚Platzhalter‘ auf diese Weise verwenden könnte jedes Platzhalter Sie ändern müssen Ziel:

if ($args['id'] == 'your_slug1') { 
    $args['placeholder'] = 'your_new_placeholder1'; 
} elseif ($args['id'] == 'your_slug2') { 
    $args['placeholder'] = 'your_new_placeholder2'; 
} // elseif … and go on 

Die Platzhalter im Allgemeinen die gleichen sind für Rechnungs- und Lieferadresse ... So Ihr Code wird wie sein:

add_filter('woocommerce_form_field_args', 'custom_form_field_args', 10, 3); 
function custom_form_field_args($args, $key, $value) { 
    if ($args['id'] == 'your_slug1') { 
     $args['placeholder'] = 'your_new_placeholder1'; 
    } elseif ($args['id'] == 'your_slug2') { 
     $args['placeholder'] = 'your_new_placeholder2'; 
    } // elseif … and go on 

    return $args; 
}; 
+0

Vielen Dank! @LoicTheAztec deine Lösung ist perfekt, ich benutze das 'id' Feld wie folgt: 'if ($ args [' id '] ==' billing_first_name ') $ args [' placeholder '] =' Name '; ' – Stone