Support » Plugin: WooCommerce » No REQUIRED FIELDS on checkout, how to turn all fields to OPTIONAL ?

  • Hello,

    I tried this code to make ALL fields optional, but there is still nothing optional, can you tell me why ?
    I do not like to stop customers on the way to payment, I prefer to contact them later if anything is missing, so I want to allow them to proceed without error message.

    Thank you for your help.

    
    /**
    * xxxxxx FUNCTION TO MAKE CHECKOUT FIELDS OPTIONAL
    */
    add_filter( ‘woocommerce_billing_fields’, ‘wc_optional_billing_fields’, 10, 1 );
    function wc_optional_billing_fields( $address_fields ) {
    $address_fields[‘billing_first_name’][‘required’] = false;
    $address_fields[‘billing_last_name’][‘required’] = false;
    $address_fields[‘billing_company’][‘required’] = false;
    $address_fields[‘billing_address_1’][‘required’] = false;
    $address_fields[‘billing_address_2’][‘required’] = false;
    $address_fields[‘billing_city’][‘required’] = false;
    $address_fields[‘billing_postcode’][‘required’] = false;
    $address_fields[‘billing_country’][‘required’] = false;
    $address_fields[‘billing_state’][‘required’] = false;
    return $address_fields;
    }
    add_filter( ‘woocommerce_shipping_fields’, ‘wc_optional_shipping_fields’, 10, 1 );
    function wc_optional_shipping_fields( $address_fields ) {
    $address_fields[‘shipping_first_name’][‘required’] = false;
    $address_fields[‘shipping_last_name’][‘required’] = false;
    $address_fields[‘shipping_company’][‘required’] = false;
    $address_fields[‘shipping_address_1’][‘required’] = false;
    $address_fields[‘shipping_address_2’][‘required’] = false;
    $address_fields[‘shipping_city’][‘required’] = false;
    $address_fields[‘shipping_postcode’][‘required’] = false;
    $address_fields[‘shipping_country’][‘required’] = false;
    $address_fields[‘shipping_state’][‘required’] = false;
    return $address_fields;
    }
    
Viewing 8 replies - 1 through 8 (of 8 total)
  • Those single quotes look like smart quotes – they must be straight quotes. With that change, it worked for me.

    Sorry, have you tried the code or you just think that it should work ? Thank you.

    I tried it and it did work. Had to add phone and email to be able to place an order with no details at all. Not everyone has an phone or an email. Where you send the item to might be a problem.

    <?php
      // FUNCTIONS TO MAKE CHECKOUT FIELDS OPTIONAL
      add_filter( 'woocommerce_billing_fields', 'wc_optional_billing_fields', 10, 1 );
      function wc_optional_billing_fields( $address_fields ) {
        $address_fields['billing_first_name']['required'] = false;
        $address_fields['billing_last_name']['required'] = false;
        $address_fields['billing_company']['required'] = false;
        $address_fields['billing_address_1']['required'] = false;
        $address_fields['billing_address_2']['required'] = false;
        $address_fields['billing_city']['required'] = false;
        $address_fields['billing_postcode']['required'] = false;
        $address_fields['billing_country']['required'] = false;
        $address_fields['billing_state']['required'] = false;
        $address_fields['billing_phone']['required'] = false;
        $address_fields['billing_email']['required'] = false;
        return $address_fields;
      }
      add_filter( 'woocommerce_shipping_fields', 'wc_optional_shipping_fields', 10, 1 );
      function wc_optional_shipping_fields( $address_fields ) {
        $address_fields['shipping_first_name']['required'] = false;
        $address_fields['shipping_last_name']['required'] = false;
        $address_fields['shipping_company']['required'] = false;
        $address_fields['shipping_address_1']['required'] = false;
        $address_fields['shipping_address_2']['required'] = false;
        $address_fields['shipping_city']['required'] = false;
        $address_fields['shipping_postcode']['required'] = false;
        $address_fields['shipping_country']['required'] = false;
        $address_fields['shipping_state']['required'] = false;
        $address_fields['shipping_phone']['required'] = false;
        $address_fields['shipping_email']['required'] = false;
        return $address_fields;
      }

    Oh thank you so much !

    Sorry but I do not understand this:
    Had to add phone and email to be able to place an order with no details at all.

    Without this code people do not have to add a phone and email ?

    Thanks again.

    If you include the phone and email lines, customers won’t have to enter a phone or email.

    But that’s probably not a good idea. Ultimately someone will leave no contact details at all.

    Thank you again, your code works, but I still have the same problem as with all the codes that I tried:

    4 fields are still not optional:

    Street address *
    Town / City *
    State / County *
    Postcode / ZIP *

    On both shipping and billing form.

    Actually the only field that I want to keep as required is Email, to be able to contact the people who paid without letting any other info 🙂

    I wonder why all the codes cannot turn these 4 fields as optional.

    Waiting for a genius to help me 🙂

    Thanks.

    Those fields still have the * ( a red one in my theme) to indicate they are required but when I tested they were not required. Did you try without data in those fields? To get rid of the red star you would need a bit of custom css, but perhaps best to encourage users to fill them in.

    I am so sorry, you are right and it works even without filling these fields !

    So now only the Email address is required ! Thank you so so so much !

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘No REQUIRED FIELDS on checkout, how to turn all fields to OPTIONAL ?’ is closed to new replies.