2016-05-29 18 views
0

Ich möchte die Rechnungsadresse auf der Checkout-Seite verbergen (nicht entfernen) und die Rechnungsadresse zum ersten Mal bei der Registrierung festlegen?Rechnungsadresse von der Checkout-Seite ausblenden, aber die Informationen behalten

Um die Anzeige auf der Rechnung .pdf zu erlauben

Ich füge diesen Code:

<?php 

add_filter('woocommerce_checkout_fields' , 'custom_override_checkout_fields'); 

function custom_override_checkout_fields($fields) { 
    unset($fields['billing']['billing_first_name']); 
    unset($fields['billing']['billing_last_name']); 
    unset($fields['billing']['billing_company']); 
    unset($fields['billing']['billing_address_1']); 
    unset($fields['billing']['billing_address_2']); 
    unset($fields['billing']['billing_city']); 
    unset($fields['billing']['billing_postcode']); 
    unset($fields['billing']['billing_country']); 
    unset($fields['billing']['billing_state']); 
    unset($fields['billing']['billing_phone']); 
    unset($fields['order']['order_comments']); 
    unset($fields['billing']['billing_address_2']); 
    unset($fields['billing']['billing_postcode']); 
    unset($fields['billing']['billing_company']); 
    unset($fields['billing']['billing_last_name']); 
    unset($fields['billing']['billing_email']); 
    unset($fields['billing']['billing_city']); 
    return $fields; 
} 

Und durch diesen Code Zugabe wurde die Rechnungsadresse der pdf-Rechnung nicht hinzugefügt

So Welchen Code soll ich hinzufügen oder bearbeiten?

Vielen Dank im Voraus.

Antwort

1

Erster Schritt: Stellen Sie die Rechnungsadresse zum ersten Mal eingestellt, wenn registriert

1) Sie müssen WooCommerce für die Registrierung die Einstellung ändern.
WooCommerce Einstellungen>Konto (tab):

Registration Options

2) Billing Felder in der Benutzerregistrierung Ihr Konto Seite hinzufügen:

Basis: How to add custom fields in user registration on the "My Account" page

Der benutzerdefinierte Code (kopieren Sie diesen Code in der Datei function.php Ihr ​​aktiven Kind Thema oder Thema):

if(!is_admin()) 
{ 
    // Function to check starting char of a string 
    function startsWith($haystack, $needle) 
    { 
     return $needle === '' || strpos($haystack, $needle) === 0; 
    } 

    // Custom function to display the Billing Address form to registration page 
    function my_custom_function() 
    { 
     global $woocommerce; 
     $checkout = $woocommerce->checkout(); 

     ?> 
      <h3><?php _e('Billing Address', 'woocommerce'); ?></h3> 
     <?php 

     foreach ($checkout->checkout_fields['billing'] as $key => $field) : 
      woocommerce_form_field($key, $field, $checkout->get_value($key)); 
     endforeach; 
    } 
    add_action('register_form','my_custom_function'); 


    // Custom function to save Usermeta or Billing Address of registered user 
    function save_address($user_id) 
    { 
     global $woocommerce; 
     $address = $_POST; 

     foreach ($address as $key => $field) : 
      if(startsWith($key,'billing_')) 
      { 
       // Condition to add firstname and last name to user meta table 
       if($key == 'billing_first_name' || $key == 'billing_last_name') 
       { 
        $new_key = explode('billing_',$key); 
        update_user_meta($user_id, $new_key[1], $_POST[$key]); 
       } 
       update_user_meta($user_id, $key, $_POST[$key]); 
      } 
     endforeach; 
    } 
    add_action('woocommerce_created_customer','save_address'); 


    // Registration page billing address form Validation 
    function custom_validation() 
    { 
     global $woocommerce; 
     $address = $_POST; 

     foreach ($address as $key => $field) : 

      // Validation: Required fields 
      if(startsWith($key,'billing_')) 
      { 

       if($key == 'billing_country' && $field == '') 
       { 
        $woocommerce->add_error('' . __('ERROR', 'woocommerce') . ': ' . __('Please select a country.', 'woocommerce')); 
       } 

       if($key == 'billing_first_name' && $field == '') 
       { 
        $woocommerce->add_error('' . __('ERROR', 'woocommerce') . ': ' . __('Please enter first name.', 'woocommerce')); 
       } 

       if($key == 'billing_last_name' && $field == '') 
       { 
        $woocommerce->add_error('' . __('ERROR', 'woocommerce') . ': ' . __('Please enter last name.', 'woocommerce')); 
       } 

       if($key == 'billing_address_1' && $field == '') 
       { 
        $woocommerce->add_error('' . __('ERROR', 'woocommerce') . ': ' . __('Please enter address.', 'woocommerce')); 
       } 

       if($key == 'billing_city' && $field == '') 
       { 
        $woocommerce->add_error('' . __('ERROR', 'woocommerce') . ': ' . __('Please enter city.', 'woocommerce')); 
       } 

       if($key == 'billing_state' && $field == '') 
       { 
        $woocommerce->add_error('' . __('ERROR', 'woocommerce') . ': ' . __('Please enter state.', 'woocommerce')); 
       } 

       if($key == 'billing_postcode' && $field == '') 
       { 
        $woocommerce->add_error('' . __('ERROR', 'woocommerce') . ': ' . __('Please enter a postcode.', 'woocommerce')); 
       } 

       if($key == 'billing_email' && $field == '') 
       { 
        $woocommerce->add_error('' . __('ERROR', 'woocommerce') . ': ' . __('Please enter billing email address.', 'woocommerce')); 
       } 

       if($key == 'billing_phone' && $field == '') 
       { 
        $woocommerce->add_error('' . __('ERROR', 'woocommerce') . ': ' . __('Please enter phone number.', 'woocommerce')); 
       } 
      } 

     endforeach; 
    } 
    add_action('register_post','custom_validation'); 

} 

Zweiter Schritt: Hidding die Rechnungsadresse von der Kasse whiteout entfernt es

Sie müssen Verwenden Sie CSS, das auf die Abrechnungsblockfelder mit der Regel display: none !important; abzielt.

+0

Vielen Dank für diese klare Antwort! aber was ich will, ist nicht die Rechnungsadresse wieder auf der Checkout-Seite fragen Ich habe einige Codes hinzugefügt, um es in der Funktion.php-Datei zu entfernen, aber dann bekommt es nicht die Adresse gesetzt, wenn es leer war! –

+0

@AbdelazizMirad Möglicherweise müssen Sie das Kontrollkästchen für die Woocommerce-Einstellungen für ** Deaktivieren Sie die Kunden-Login-Erinnerung auf der "Checkout" -Seite ** deaktivieren. Könnten Sie einen Link zu Ihrer Website bereitstellen? Um Rechnungsfelder beim Auschecken zu verbergen, ist es besser, die CSS-Regel wie gesagt zu verwenden. – LoicTheAztec

+0

Ich habe alles in den Tabs "Checkout" und "Mein Konto" versucht, yeah, es gibt kein Problem Ich kann html/css verstecken Ich muss Informationen aufbewahren! –