Make Phone Field Required in WooCommerce Checkout

Beginner
✓ Tested
📅 September 13, 2025
⬇️ 0 Downloads
📋 0 Copies

This simple snippet makes the phone number field required during WooCommerce checkout. Customers won’t be able to complete their order without providing a phone number, and the snippet includes basic validation to ensure the phone number format is correct.
What does this code do?

Makes the billing phone field required (shows red asterisk *)
Validates that phone field is not empty during checkout
Validates phone number format (allows numbers, spaces, dashes, +, parentheses)
Ensures minimum 10 digits in the phone number
Shows error messages if validation fails

Perfect for:

Delivery services that need customer contact
Businesses requiring phone verification
Local stores needing customer phone numbers
Services requiring appointment scheduling
Emergency contact requirements

The validation is flexible and accepts common phone number formats like: 123-456-7890, (123) 456-7890, +1-123-456-7890, etc.

⚠️ Important Warnings

⚠️ Test thoroughly - Required fields can block legitimate customers
⚠️ International customers - Strict validation might block foreign phone formats
⚠️ Mobile vs landline - Consider which formats you want to accept
⚠️ Guest checkout - Make sure validation works for guest users
⚠️ Phone format variations - Different countries have different formats
⚠️ User experience - Too strict validation can hurt conversion rates
⚠️ Error messages - Make sure error messages are clear and helpful
⚠️ Backup first - Always backup before modifying checkout process
💻 PHP Code
/**
 * Make phone field required in WooCommerce checkout
 * Simple validation for phone number
 * Prefix: tpsc_ (TP Snippet Collection)
 */

// Make billing phone required
add_filter('woocommerce_billing_fields', 'tpsc_make_phone_required');

function tpsc_make_phone_required($fields) {
    $fields['billing_phone']['required'] = true;
    return $fields;
}

// Add validation for phone field
add_action('woocommerce_checkout_process', 'tpsc_validate_phone_field');

function tpsc_validate_phone_field() {
    if (empty($_POST['billing_phone'])) {
        wc_add_notice(__('Phone number is required.', 'woocommerce'), 'error');
    }
}

// Optional: Add phone validation (numbers and basic characters only)
add_action('woocommerce_checkout_process', 'tpsc_validate_phone_format');

function tpsc_validate_phone_format() {
    if (!empty($_POST['billing_phone'])) {
        $phone = sanitize_text_field($_POST['billing_phone']);
        
        // Allow numbers, spaces, dashes, plus sign, and parentheses
        if (!preg_match('/^[\d\s\-\+\(\)]+$/', $phone)) {
            wc_add_notice(__('Please enter a valid phone number.', 'woocommerce'), 'error');
        }
        
        // Check minimum length (at least 10 digits)
        $digits_only = preg_replace('/[^\d]/', '', $phone);
        if (strlen($digits_only) < 10) {
            wc_add_notice(__('Phone number must be at least 10 digits.', 'woocommerce'), 'error');
        }
    }
}

📝 Installation Instructions

QUICK START:

1. Copy and paste the code into your theme's functions.php file
2. Go to your checkout page
3. The phone field will now show a red asterisk (*) indicating it's required
4. Try to checkout without phone - you'll see an error message!

TO REMOVE FORMAT VALIDATION:
Remove or comment out lines 21-35:
// Comment out or delete this entire function
// add_action('woocommerce_checkout_process', 'tpsc_validate_phone_format');

TO CHANGE MINIMUM DIGITS:
Line 31: Change the number from 10 to your preference
if (strlen($digits_only) < 8) { // Change to 8 digits minimum

TO CUSTOMIZE ERROR MESSAGES:
Change the text in the error messages:
wc_add_notice(__('Phone is mandatory!', 'woocommerce'), 'error'); // Custom message

📸 Screenshots