Are you looking for a quick and easy way to make phone number required in WooCommerce? In this post, I will share with you an excellent solution that will quickly help you make phone number required.
I run into the same problem when I was customizing the WooCommerce checkout page, I came up with a ‘ WooCommerce make phone number required ‘ code snippet that you too can use to make the phone number required in your WooCommerce store checkout page.
WooCommerce Make Phone Number Required
To make the WooCommerce phone number at checkout required, as you can see in the image below, you need to use the code snippet below. You can add this code snippet to the functions.php file or your plugin development.
[php] /*** Make phone number required WooCommerce
*/
add_filter( ‘woocommerce_billing_fields’, ‘njengah_make_phone_number_required’, 10, 1 );
function njengah_make_phone_number_required( $address_fields ) {
$address_fields[‘billing_phone’][‘required’] = true;
return $address_fields;
}
WooCommerce Make Phone Number Not Required
If you wish to make the phone number not required you can reverse this by changing the boolean value in the callback function and the code should be as follows:
[php] /*** Make phone number not required WooCommerce
*/
add_filter( ‘woocommerce_billing_fields’, ‘njengah_make_phone_number_required’, 10, 1 );
function njengah_make_phone_number_required( $address_fields ) {
$address_fields[‘billing_phone’][‘required’] = false;
return $address_fields;
}
[/php]
Conclusion
In this post, we have looked at how make phone number required in WooCommerce, as you can see there are two steps involved in making phone number required in WooCommerce checkout.
You can easily and quickly use this solution in your WooCommerce theme or plugin development. Just in case you are stuck, I am always ready to help you implement this solution and also to further customize it to fit your specific needs.
Joe is an experienced full-stack web developer with a decade of industry experience in the LAMP & MERN stacks, WordPress, WooCommerce, and JavaScript – (diverse portfolio). He has a passion for creating elegant and user-friendly solutions and thrives in collaborative environments. In his spare time, he enjoys exploring new tech trends, tinkering with new tools, and contributing to open-source projects. You can hire me here for your next project.
Similar Articles
- How to Check If Product is Variable In WooCommerce
- How to Make WooCommerce Order Comments Required
- How to Display Username In WooCommerce
- How to Delete a Page In WordPress
- How to Get Product Image src WooCommerce
- How to Get WooCommerce Checkout Country Dropdown
- How to Check If It Is Checkout Page WooCommerce
- How to Check If Product Page In WooCommerce
- How to Get Order meta_data In WooCommerce
- How To Edit WooCommerce Checkout Page
- How to Set Up WooCommerce Terms and Conditions Checkout
- How to Change WooCommerce Checkout Error Messages
- How to Insert Default Content to WordPress Post Editor Dynamically
- WooCommerce Visual Hook Guide Checkout
- How to Add WooCommerce Registration Email Verification
- How to Get Last Order by User Id WooCommerce
- How to Add WooCommerce Shopping Cart Icon In Menu
- How to Add Checkout Phone Number Validation WooCommerce