简体   繁体   中英

Edit type of field in registration form woocommerce


I use the following code to add custom fields in user registration on the "My Account" page using woocommerce,it worked succesfully, but now i want to change the type of one fields be displayed as a select to display only 3 state:
- Paris,
- London
- Algiers
So how can I edit this code:

<p class="form-row form-row-last">
    <label for="reg_billing_state"><?php _e( 'State', 'woocommerce' ); ?> <span class="required">*</span></label>
    <input type="text" class="input-text" name="billing_state" id="reg_billing_state" value="<?php if ( ! empty( $_POST['billing_state'] ) ) esc_attr_e( $_POST['billing_state'] ); ?>" />

    </p>

I have tried this but it doesn't work!

<p class="form-row form-row-last">
    <label for="reg_billing_state"><?php _e( 'Commune', 'woocommerce' ); ?> <span class="required">*</span></label>
    <input  list="states" class="input-text" name="billing_state" id="reg_billing_state" value="<?php if ( ! empty( $_POST['billing_state'] ) ) esc_attr_e( $_POST['billing_state'] ); ?>" />
    <datalist id="states">
    <option value="Paris">
    <option value="London">
    <option value="Algiers">
  </datalist> 
    </p>

Thank you in advanced!

Solved
The solution I found for now is the following:

<p class="form-row form-row-last">
    <label for="reg_billing_state"><?php _e( 'Commune', 'woocommerce' ); ?> <span class="required">*</span></label>
    <select id="reg_billing_state" class="input-text" name="billing_state">
        <option value="Alger">Alger</option>
        <option value="Zeralda">Zeralda</option>
        <option value="Beni Messous">Beni Messous</option>
    </select>
</p>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM