私は読んで、次のチュートリアルHow to add custom fields in user registration on the "My Account" pageに続き、マイアカウントページ(ユーザーがログアウトしたときに表示される)の登録フォームにいくつかのカスタムフィールドを追加しました。WooCommerce - 国/州を追加して登録フォームにフィールドを追加しますか?
お店のオーナーが定義している場合は、選択欄として請求先の国/州を追加したいと思います。 (つまり、カナダでのみサービスを提供する場合は、州のみをご利用ください)。
残念ながら、このチュートリアルでは、選択フィールド、基本的なテキストフィールドについては説明しません。国を追加する方法をリストした別のスレッドが見つかりましたが、それはすべての国であり、店主が指定したものではありません。
誰かが、店主が設定した国/地域/州を読み込む際にさらに詳しい情報を持っていますか?これまでのところ私は、次のを持っている:
/**
* Add new register fields for WooCommerce registration.
*
* @return string Register fields HTML.
*/
function wooc_extra_register_fields() {
$countries_obj = new WC_Countries();
$countries = $countries_obj->__get('countries');
?>
<fieldset>
<legend><h3>Address</h3></legend>
<p>Please provide the main contact address for this account.</p>
<p class="form-row form-row-wide">
<label for="reg_billing_address_1"><?php _e('Address', 'woocommerce'); ?> <span class="required">*</span></label>
<input type="text" class="input-text" name="billing_address_1" id="reg_billing_address_1" placeholder="Street/P.O Box address" value="<?php if (! empty($_POST['billing_address_1'])) esc_attr_e($_POST['billing_address_1']); ?>" />
</p>
<div class="clear"></div>
<p class="form-row form-row-wide">
<label for="reg_billing_address_2"><?php _e('Address Line 2', 'woocommerce'); ?></label>
<input type="text" class="input-text" name="billing_address_2" id="reg_billing_address_2" placeholder="Apartment, suite, unit etc. (optional)" value="<?php if (! empty($_POST['billing_address_2'])) esc_attr_e($_POST['billing_address_2']); ?>" />
</p>
<div class="clear"></div>
<p class="form-row form-row-wide">
<label for="reg_billing_city"><?php _e('Town/City', 'woocommerce'); ?> <span class="required">*</span></label>
<input type="text" class="input-text" name="billing_city" id="reg_billing_city" value="<?php if (! empty($_POST['billing_city'])) esc_attr_e($_POST['billing_city']); ?>" />
</p>
<div class="clear"></div>
<p class="form-row form-row-wide">
<label for="reg_billing_postcode"><?php _e('Postal Code', 'woocommerce'); ?></label>
<input type="text" class="input-text" name="billing_postcode" id="reg_billing_postcode" value="<?php if (! empty($_POST['billing_postcode'])) esc_attr_e($_POST['billing_postcode']); ?>" />
</p>
<div class="clear"></div>
<p class="form-row form-row-wide">
<label for="reg_billing_country"><?php _e('Country', 'woocommerce'); ?> <span class="required">*</span></label>
<select class="country_select" name="billing_country" id="reg_billing_country">
<?php foreach ($countries as $key => $value): ?>
<option value="<?php echo $key?>"><?php echo $value?></option>
<?php endforeach; ?>
</select>
</p>
</fieldset>
<?php
}
add_action('woocommerce_register_form_start', 'wooc_extra_register_fields');
は、私は、カスタム登録フォームを実装するためにそれを使用し 、私はカスケードに状態や地域のフィールドを走る部分のJSを探していた 、ありがとうございました。 –