I'm using WooCommerce website, with digits plugin for OTP login and sign up. I need country and state field dropdowns on digits sign up form. On the checkout page, for billing details, the dropdown is working well. But not on my sign-up page. How can I fix that?
This is my code:
global $woocommerce;
$countries_obj = new WC_Countries();
$countries = $countries_obj->__get('countries');
echo '<div id="my_custom_countries_field"><h2>' . __('Countries') . '</h2>';
woocommerce_form_field('my_country_field', array(
'type' => 'select',
'class' => array( 'chzn-drop' ),
'label' => __('Select a country'),
'placeholder' => __('Enter something'),
'options' => $countries
)
);
echo '</div>';
This is the code I tried on the WPCode plugin. But I didn't work for me. I want to showcase the drop-down for country and state on this third party plugin signup form.
Any help is highly appreciated.
First "country" and "state" field types are available for
woocommerce_form_field()function, so use them instead of the "select" type. This way, you don't need to get the countries options or states options. Additionally, here, the state field will be visible only for countries handling states, and populated with the correct states for the selected country.I have asked in Digits : WordPress Mobile Phone Number OTP Signup and Login Form as a comment, as this commercial plugin seems to support WooCommerce. You may ask them, as a purchaser, opening a support ticket.
The following code, based on this previous answer, will work flawlessly with any login and sign up form (you will just need to replace the function hook, or to pick the code inside the function, and add it to the required login / register template file):
Addition:
For those other fellows, who want to use that code in WooCommerce login form, here is the necessary code to validate and save the submitted country and state:
Code goes on functions.php file of your active child theme (or theme), or in any plugin file.
Tested and works.