2017-02-20 6 views
1

Ich bekomme diesen Code, um ein benutzerdefiniertes Feld zum WooCommerce Billing Formular hinzuzufügen.Ein benutzerdefiniertes Feld zu WooCommerce Fakturierungsformular hinzufügen?

Das Feld wird gezeigt, aber das Problem ist, dass das Feld nicht label hat noch placeholder noch class name.

Was fehlt mir hier? Ich habe diesen Code zu functions.php in meinem Child Theme hinzugefügt.

/******************************* 
    CUSTOM BILLING FIELD 
******************************** */ 
add_filter('woocommerce_billing_fields', 'custom_woocommerce_billing_fields'); 

function custom_woocommerce_billing_fields($fields) 
{ 

    $fields['billing']['billing_options'] = array(
     'label' => __('NIF', 'woocommerce'), // Add custom field label 
     'placeholder' => _x('Your NIF here....', 'placeholder', 'woocommerce'), // Add custom field placeholder 
     'required' => false, // if field is required or not 
     'clear' => false, // add clear or not 
     'type' => 'text', // add field type 
     'class' => array('my-css') // add class name 
    ); 

    return $fields; 
} 
+0

Sie können Ihren Code für das Custombilling-Feld zu der 'get_default_address_fields()' Funktion in der 'class-wc-countries.php' Datei hinzufügen –

Antwort

2

Wenn Sie woocommerce_billing_fields verwenden, dann brauchen Sie nicht zu die Felder angeben, automatisch an die Rechnungs Felder erhalten zuweisen wird. Aber wenn Sie woocommerce_checkout_fields dann nur verwenden, müssen Sie angeben, dass Sie ein Feld für shipping oder billing möchten.

Für woocommerce_billing_fields

add_filter('woocommerce_billing_fields', 'custom_woocommerce_billing_fields'); 

function custom_woocommerce_billing_fields($fields) 
{ 

    $fields['billing_options'] = array(
     'label' => __('NIF', 'woocommerce'), // Add custom field label 
     'placeholder' => _x('Your NIF here....', 'placeholder', 'woocommerce'), // Add custom field placeholder 
     'required' => false, // if field is required or not 
     'clear' => false, // add clear or not 
     'type' => 'text', // add field type 
     'class' => array('my-css') // add class name 
    ); 

    return $fields; 
} 


Für woocommerce_checkout_fields

add_filter('woocommerce_checkout_fields', 'custom_woocommerce_billing_fields'); 

function custom_woocommerce_billing_fields($fields) 
{ 
    $fields['billing']['billing_options'] = array(
     'label' => __('NIF', 'woocommerce'), // Add custom field label 
     'placeholder' => _x('Your NIF here....', 'placeholder', 'woocommerce'), // Add custom field placeholder 
     'required' => false, // if field is required or not 
     'clear' => false, // add clear or not 
     'type' => 'text', // add field type 
     'class' => array('my-css') // add class name 
    ); 

    return $fields; 
} 

Referenz:

Hop, das hilft!

+0

Ich arbeite nicht. Alle Felder in Rechnungsformular werden entfernt. Und das neue Feld wird nicht hinzugefügt. Es wird kein Fehler angezeigt. – JPashs

+0

@JPashs: Ich habe meinen Code nicht gerade aus meinem Gehirn getestet, aber es gibt einen logischen Fehler in Ihren Hook- und Array-Parametern, den Sie verwenden "woocommerce_billing_fields" und erneut "['billing']' hinzufügen, als Ergebnis sind Sie nicht die gewünschte Ausgabe erhalten. Ersetzen Sie einfach Ihre Hook mit diesem "woocommerce_checkout_fields" und halten Sie Ihre erwähnte Funktion ist Frage, dann wird es auch funktionieren. –

+0

Ich habe das versucht: http://pastebin.com/raw/JrnHfuVT aber noch nicht funktioniert. Können Sie mir bitte sagen, was ich vermisse und den Code in Ihrer Antwort ändern? Damit ich deine Antwort annehmen kann. Vielen Dank. – JPashs

Verwandte Themen