Set country value when loading fields rather than in template files
This commit is contained in:
parent
ce2473e09f
commit
04d7e54d42
|
@ -1273,6 +1273,7 @@ class WC_Countries {
|
|||
foreach ( $fields as $key => $value ) {
|
||||
if ( 'state' === $key ) {
|
||||
$value['country_field'] = $type . 'country';
|
||||
$value['country'] = $country;
|
||||
}
|
||||
$address_fields[ $type . $key ] = $value;
|
||||
}
|
||||
|
|
|
@ -12,24 +12,20 @@
|
|||
*
|
||||
* @see https://docs.woocommerce.com/document/template-structure/
|
||||
* @package WooCommerce/Templates
|
||||
* @version 3.0.9
|
||||
* @version 3.6.0
|
||||
* @global WC_Checkout $checkout
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/** @global WC_Checkout $checkout */
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
?>
|
||||
<div class="woocommerce-billing-fields">
|
||||
<?php if ( wc_ship_to_billing_address_only() && WC()->cart->needs_shipping() ) : ?>
|
||||
|
||||
<h3><?php _e( 'Billing & Shipping', 'woocommerce' ); ?></h3>
|
||||
<h3><?php esc_html_e( 'Billing & Shipping', 'woocommerce' ); ?></h3>
|
||||
|
||||
<?php else : ?>
|
||||
|
||||
<h3><?php _e( 'Billing details', 'woocommerce' ); ?></h3>
|
||||
<h3><?php esc_html_e( 'Billing details', 'woocommerce' ); ?></h3>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
|
@ -37,14 +33,11 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
|
||||
<div class="woocommerce-billing-fields__field-wrapper">
|
||||
<?php
|
||||
$fields = $checkout->get_checkout_fields( 'billing' );
|
||||
$fields = $checkout->get_checkout_fields( 'billing' );
|
||||
|
||||
foreach ( $fields as $key => $field ) {
|
||||
if ( isset( $field['country_field'], $fields[ $field['country_field'] ] ) ) {
|
||||
$field['country'] = $checkout->get_value( $field['country_field'] );
|
||||
}
|
||||
woocommerce_form_field( $key, $field, $checkout->get_value( $key ) );
|
||||
}
|
||||
foreach ( $fields as $key => $field ) {
|
||||
woocommerce_form_field( $key, $field, $checkout->get_value( $key ) );
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
|
@ -57,7 +50,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
|
||||
<p class="form-row form-row-wide create-account">
|
||||
<label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox">
|
||||
<input class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" id="createaccount" <?php checked( ( true === $checkout->get_value( 'createaccount' ) || ( true === apply_filters( 'woocommerce_create_account_default_checked', false ) ) ), true ) ?> type="checkbox" name="createaccount" value="1" /> <span><?php _e( 'Create an account?', 'woocommerce' ); ?></span>
|
||||
<input class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" id="createaccount" <?php checked( ( true === $checkout->get_value( 'createaccount' ) || ( true === apply_filters( 'woocommerce_create_account_default_checked', false ) ) ), true ); ?> type="checkbox" name="createaccount" value="1" /> <span><?php esc_html_e( 'Create an account?', 'woocommerce' ); ?></span>
|
||||
</label>
|
||||
</p>
|
||||
|
||||
|
|
|
@ -12,20 +12,18 @@
|
|||
*
|
||||
* @see https://docs.woocommerce.com/document/template-structure/
|
||||
* @package WooCommerce/Templates
|
||||
* @version 3.0.9
|
||||
* @version 3.6.0
|
||||
* @global WC_Checkout $checkout
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
?>
|
||||
<div class="woocommerce-shipping-fields">
|
||||
<?php if ( true === WC()->cart->needs_shipping_address() ) : ?>
|
||||
|
||||
<h3 id="ship-to-different-address">
|
||||
<label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox">
|
||||
<input id="ship-to-different-address-checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" <?php checked( apply_filters( 'woocommerce_ship_to_different_address_checked', 'shipping' === get_option( 'woocommerce_ship_to_destination' ) ? 1 : 0 ), 1 ); ?> type="checkbox" name="ship_to_different_address" value="1" /> <span><?php _e( 'Ship to a different address?', 'woocommerce' ); ?></span>
|
||||
<input id="ship-to-different-address-checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" <?php checked( apply_filters( 'woocommerce_ship_to_different_address_checked', 'shipping' === get_option( 'woocommerce_ship_to_destination' ) ? 1 : 0 ), 1 ); ?> type="checkbox" name="ship_to_different_address" value="1" /> <span><?php esc_html_e( 'Ship to a different address?', 'woocommerce' ); ?></span>
|
||||
</label>
|
||||
</h3>
|
||||
|
||||
|
@ -35,14 +33,11 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
|
||||
<div class="woocommerce-shipping-fields__field-wrapper">
|
||||
<?php
|
||||
$fields = $checkout->get_checkout_fields( 'shipping' );
|
||||
$fields = $checkout->get_checkout_fields( 'shipping' );
|
||||
|
||||
foreach ( $fields as $key => $field ) {
|
||||
if ( isset( $field['country_field'], $fields[ $field['country_field'] ] ) ) {
|
||||
$field['country'] = $checkout->get_value( $field['country_field'] );
|
||||
}
|
||||
woocommerce_form_field( $key, $field, $checkout->get_value( $key ) );
|
||||
}
|
||||
foreach ( $fields as $key => $field ) {
|
||||
woocommerce_form_field( $key, $field, $checkout->get_value( $key ) );
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
|
@ -59,7 +54,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
|
||||
<?php if ( ! WC()->cart->needs_shipping() || wc_ship_to_billing_address_only() ) : ?>
|
||||
|
||||
<h3><?php _e( 'Additional information', 'woocommerce' ); ?></h3>
|
||||
<h3><?php esc_html_e( 'Additional information', 'woocommerce' ); ?></h3>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
*
|
||||
* @see https://docs.woocommerce.com/document/template-structure/
|
||||
* @package WooCommerce/Templates
|
||||
* @version 3.4.0
|
||||
* @version 3.6.0
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
@ -35,9 +35,6 @@ do_action( 'woocommerce_before_edit_account_address_form' ); ?>
|
|||
<div class="woocommerce-address-fields__field-wrapper">
|
||||
<?php
|
||||
foreach ( $address as $key => $field ) {
|
||||
if ( isset( $field['country_field'], $address[ $field['country_field'] ] ) ) {
|
||||
$field['country'] = wc_get_post_data_by_key( $field['country_field'], $address[ $field['country_field'] ]['value'] );
|
||||
}
|
||||
woocommerce_form_field( $key, $field, wc_get_post_data_by_key( $key, $field['value'] ) );
|
||||
}
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue