Search code examples
wordpresswoocommercewordpress-theminghook-woocommerce

Woocommerce Cannot set billing phone to "required"


I have been trying to make the billing phone number a required component, but have been unable to affect it in any way. Here's what I have tried so far

using hooks in functions.php

add_filter('woocommerce_billing_fields', 'no_billing_phone_validation' );
function no_billing_phone_validation( $fields ) {
    $fields['billing_phone']['required'] = true;
    return $fields;
}

Setting the phone to required in my theme

enter image description here

and using the plugin "Checkout Field Editor for WooCommerce" to set the phone to required

enter image description here

but despite all of this, the billing phone is still optional, and I am able to check out without adding a phone number. Is there anything that I'm missing?

enter image description here


Solution

  • I modified code in file wp-content/plugins/woocommerce/assets/client/blocks/checkout-frontend.js by changing

    "showPhoneField":{"type":"boolean","default":true},"requirePhoneField":{"type":"boolean","default":true},
    

    and

    showPhoneField: 1,requireCompanyField: !1,requirePhoneField: 1,
    

    Now it works as expected!

    enter image description here