Skip to main content

How to Make Billing and Shipping Fields Optional and required in WooCommerce

Make Billing and Shipping Fields Optional and required in WooCommerce




For not required

  1. country
  2. first_name
  3. last_name
  4. company
  5. address_1
  6. address_2
  7. city
  8. state
  9. postcode


add_filter( 'woocommerce_default_address_fields' , 'optional_default_address_fields' );
 function optional_default_address_fields( $address_fields ) {
 $address_fields['company']['required'] = false;
 $address_fields['postcode']['required'] = false;
 $address_fields['city']['required'] = false;
 $address_fields['state']['required'] = false;
 return $address_fields;
 }




For required



add_filter( 'woocommerce_default_address_fields' , 'optional_default_address_fields' );
 function optional_default_address_fields( $address_fields ) {
 $address_fields['company']['required'] = true;
 $address_fields['postcode']['required'] = true;
 $address_fields['city']['required'] = true;
 $address_fields['state']['required'] = true;
 return $address_fields;
 }

Comments

Popular posts from this blog

How to check date format in PHP?

Check date format in PHP function isCorrectDateFromat($date){     if(!empty($date)){         $dateString = $date; // Replace this with your date string         $format = "Y-m-d"; // Replace this with your expected date format         $dateTime = DateTime::createFromFormat($format, $dateString);         if ($dateTime === false) { /*             echo "The date is not in the correct format."; */         } else {             $errors = DateTime::getLastErrors();             if (empty($errors)) { /*                 echo "The date is in the correct format."; */                 return true;             } else { /*                 echo "...