0
votes

I'm working on a WooCommerce project and my client wants Billing Email Optional not Mandatory in checkout page. I've did this following steps but did not get any result.

class-wc-countries.php (did not work)

$address_fields['billing_email'] = array(
                'label'        => __( 'Email address', 'woocommerce' ),
                'required'     => false, //default was TRUE
                'type'         => 'email',
                'class'        => array( 'form-row-wide' ),
                'validate'     => false, // default was array( 'email' )
                'autocomplete' => 'no' === get_option( 'woocommerce_registration_generate_username' ) ? 'email' : 'email username',
                'priority'     => 110,
            );

also add this line of code in my child theme function.php (did not work)

add_filter( 'woocommerce_checkout_fields', 'misha_no_email_validation' );
 
function misha_no_email_validation( $fields ){
 
    $fields['billing']['billing_email']['required'] = false;
    unset( $fields['billing']['billing_email']['validate'] );
    
    return $fields;
 
}

then use 2 plugin Checkout Field Editor for WooCommerce and Flexible Checkout Fields but did not get any result.

enter image description here

Please help!!

Thanks.

1
Everything in WooCommerce works with email. Why removing it? You will not receive any mail about your order status or even the invoice, legals..Mr. Jo
instead of email we are going to use mobile number, also we are going to use mobile api for order notification, order details etc. shop.shajgoj.com they are using email as optional.Maruf Ahmed
Your code should be work try to change a priority.Bhautik
@Bhautik I did but nothing happedMaruf Ahmed
Try deactivating all plugins except woocommerce and check.Bhautik

1 Answers

0
votes

I'd add priority of 20 to the filter hook. This works on my end! It'll make it optional with no validation.

add_filter('woocommerce_checkout_fields', 'misha_no_email_validation', 20);

function misha_no_email_validation($fields){

  $fields['billing']['billing_email']['required'] = false;

  return $fields;

}