Make state checkout field required for a Vietnam country in WooCommerce

后端 未结 1 1616
醉酒成梦
醉酒成梦 2021-01-25 06:18

The country of Vietnam in WooCommerce does not have defined states, so I added some states to my checkout page.

This is my code:

add_filter( \'woocommerce_         


        
1条回答
  •  时光说笑
    2021-01-25 07:04

    The following function will make for Vietnam the state field as a required in woocommerce:

    add_filter( 'woocommerce_get_country_locale', 'custom_country_locale', 10, 1 );
    function custom_default_address_fields( $locale ) {
        $locale['VN']['state']['required'] = true;
    
        return $locale;
    }
    

    Code goes in functions.php file of your active child theme (active theme). Tested and works.

    Explanations: Each country have specific "locale" fields settings in WooCommerce. We are adding/altering the default WooCommerce country locale settings that are defined on WC_Countries get_country_locale() method

    0 讨论(0)
提交回复
热议问题