Okay
  Public Ticket #4187037
How to Make Shipping Address Phone Field Required on Checkout Form
Open

Comments

  • parisorn started the conversation

    Dear Salient Theme Support,

    I’m currently using the Salient theme with WooCommerce, and I would like to make the Phone field under the Shipping Address section of the checkout form mandatory.
    At the moment, the field is labeled as "Phone (optional)", and customers can proceed without entering it.
    I’ve tried the following approaches in my functions.php, but none of them have worked:

    1.
    add_filter( 'woocommerce_checkout_fields', 'salient_require_shipping_phone' ); function salient_require_shipping_phone( $fields ) {    $fields['shipping']['shipping_phone']['required'] = true;    return $fields; }

    2.
    add_filter( 'woocommerce_shipping_fields', 'make_shipping_phone_required' ); function make_shipping_phone_required( $fields ) {    $fields['shipping_phone']['required'] = true;    return $fields; }

    3.
    add_filter('woocommerce_checkout_get_value', 'ts_populate_shipping_phone', 10, 2);
    function ts_populate_shipping_phone($value, $input) { if ( 'shipping_phone' === $input ) { $value = WC()->customer->get_shipping_phone(); } return $value;
    }

    Unfortunately, these snippets don’t make the field required at checkout.
    Could you please guide me on the correct way to make the shipping phone field required, ideally via functions.php or using any available option in Salient?

    Your support is much appreciated.

    Best regards,

  •  9,377
    Tahir replied

    Hey parisorn ,

    Thanks for reaching out! .

    Could you confirm if you are using the Block Checkout or the Legacy Shortcode: https://themenectar.com/docs/salient/using-legacy-woocommerce-cart-checkout/ ? .

    Best,

     


     Salient Support Team 


  • parisorn replied

    No, we are using block checkout

  •  9,377
    Tahir replied

    Be sure to use the Legacy one for the filters to work .

    Thanks 


     Salient Support Team 


  • parisorn replied

    We use Legacy one then what is next we should do to get what we requests

  •  9,377
    Tahir replied

    Try using this filter and check: 

    add_filter( 'woocommerce_checkout_fields', function ( $fields ) {
        if ( isset( $fields['billing']['billing_phone'] ) ) {
            $fields['billing']['billing_phone']['required'] = true;
        }
        return $fields;
    });
    

    Best,

     


     Salient Support Team