When it’s about controlling hundreds of articles, product pages for web shops, or user profiles in social networks, all
Continue reading
Ac haca ullamcorper donec ante habi tasse donec imperdiet eturpis varius per a augue magna hac. Nec hac et vestibulum du...
Continue reading
add_filter('woocommerce_checkout_fields', function($fields) {
$required_fields = [
'billing_first_name',
'billing_phone',
'billing_address_1',
'billing_city',
'billing_state',
'billing_postcode'
];
foreach ($required_fields as $field) {
if (isset($fields['billing'][$field])) {
$fields['billing'][$field]['required'] = true;
}
}
$fields['billing']['billing_address_1']['label'] = 'Complete Address';
$fields['billing']['billing_address_1']['placeholder'] = 'House no, street, area, landmark';
$fields['billing']['billing_address_2']['label'] = 'Area / Locality / Landmark';
$fields['billing']['billing_address_2']['placeholder'] = 'Nearby landmark or locality';
$fields['billing']['billing_address_2']['required'] = true;
return $fields;
});
add_action('woocommerce_after_checkout_validation', function($data, $errors) {
$address1 = trim($data['billing_address_1'] ?? '');
$address2 = trim($data['billing_address_2'] ?? '');
$city = trim($data['billing_city'] ?? '');
$postcode = trim($data['billing_postcode'] ?? '');
$phone = trim($data['billing_phone'] ?? '');
$bad_values = ['na', 'n/a', 'no', 'none', '.', '-', 'same', 'ok', 'test'];
if (strlen($address1) < 15 || in_array(strtolower($address1), $bad_values)) {
$errors->add('address_error', 'Please enter your complete address with house number, street and area.');
}
if (strlen($address2) < 4 || in_array(strtolower($address2), $bad_values)) {
$errors->add('locality_error', 'Please enter area/locality or landmark.');
}
if (strlen($city) < 3 || in_array(strtolower($city), $bad_values)) {
$errors->add('city_error', 'Please enter a valid city name.');
}
if (!preg_match('/^[1-9][0-9]{5}$/', $postcode)) {
$errors->add('postcode_error', 'Please enter a valid 6 digit pincode.');
}
if (!preg_match('/^[6-9][0-9]{9}$/', $phone)) {
$errors->add('phone_error', 'Please enter a valid 10 digit Indian mobile number.');
}
}, 10, 2);