Question:
How to add a Postcode Checkout Field for specific country in WooCommerce

The following will do the job, making the WooCommerce postcode Checkout Field required only when the country is not Saudi Arabia:

add_filter( 'woocommerce_get_country_locale', 'custom_country_locale_postcode', 10, 1 );

function custom_country_locale_postcode( $locale ) {

    foreach ( $locale as $country => $data ){

        $locale[$country] = array( 'postcode' => array(

            'required' => true,

        ) );

    }


    $locale['SA'] = array( 'postcode' => array(

        'required' => false,

    ) );


    return $locale;

}


This code checks if the customer's shipping or billing country matches the specified country code. If it does, it adds a custom postcode field for that country. Adjust the country code and field settings according to your requirements.


Answered by:> LoicTheAztec

Credit:> StackOverflow



Blog Link: 

>How you can create an array with an associative array in other array php?

>PHP Error Solved: htaccess problem with an empty string in URL

>How to merge cells with HTML, CSS, and PHP?

>How to solve the issue of producing the wrong output value in PHP?

>What makes Python 'flow' with HTML nicely as compared to PHP?



Nisha Patel

Nisha Patel

Submit
0 Answers