get_checkout_fields method refactored
This commit is contained in:
parent
a04c54a896
commit
d7458493c6
|
@ -193,45 +193,54 @@ class WC_Checkout {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_checkout_fields( $fieldset = '' ) {
|
public function get_checkout_fields( $fieldset = '' ) {
|
||||||
if ( is_null( $this->fields ) ) {
|
if ( ! is_null( $this->fields ) ) {
|
||||||
$this->fields = array(
|
return $fieldset ? $this->fields[ $fieldset ] : $this->fields;
|
||||||
'billing' => WC()->countries->get_address_fields( $this->get_value( 'billing_country' ), 'billing_' ),
|
}
|
||||||
'shipping' => WC()->countries->get_address_fields( $this->get_value( 'shipping_country' ), 'shipping_' ),
|
|
||||||
'account' => array(),
|
$this->fields = array(
|
||||||
'order' => array(
|
'billing' => WC()->countries->get_address_fields(
|
||||||
'order_comments' => array(
|
$this->get_value( 'billing_country' ),
|
||||||
'type' => 'textarea',
|
'billing_'
|
||||||
'class' => array( 'notes' ),
|
),
|
||||||
'label' => __( 'Order notes', 'woocommerce' ),
|
'shipping' => WC()->countries->get_address_fields(
|
||||||
'placeholder' => esc_attr__( 'Notes about your order, e.g. special notes for delivery.', 'woocommerce' ),
|
$this->get_value( 'shipping_country' ),
|
||||||
|
'shipping_'
|
||||||
|
),
|
||||||
|
'account' => array(),
|
||||||
|
'order' => array(
|
||||||
|
'order_comments' => array(
|
||||||
|
'type' => 'textarea',
|
||||||
|
'class' => array( 'notes' ),
|
||||||
|
'label' => __( 'Order notes', 'woocommerce' ),
|
||||||
|
'placeholder' => esc_attr__(
|
||||||
|
'Notes about your order, e.g. special notes for delivery.',
|
||||||
|
'woocommerce'
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( 'no' === get_option( 'woocommerce_registration_generate_username' ) ) {
|
||||||
|
$this->fields['account']['account_username'] = array(
|
||||||
|
'type' => 'text',
|
||||||
|
'label' => __( 'Account username', 'woocommerce' ),
|
||||||
|
'required' => true,
|
||||||
|
'placeholder' => esc_attr__( 'Username', 'woocommerce' ),
|
||||||
);
|
);
|
||||||
if ( 'no' === get_option( 'woocommerce_registration_generate_username' ) ) {
|
|
||||||
$this->fields['account']['account_username'] = array(
|
|
||||||
'type' => 'text',
|
|
||||||
'label' => __( 'Account username', 'woocommerce' ),
|
|
||||||
'required' => true,
|
|
||||||
'placeholder' => esc_attr__( 'Username', 'woocommerce' ),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( 'no' === get_option( 'woocommerce_registration_generate_password' ) ) {
|
|
||||||
$this->fields['account']['account_password'] = array(
|
|
||||||
'type' => 'password',
|
|
||||||
'label' => __( 'Create account password', 'woocommerce' ),
|
|
||||||
'required' => true,
|
|
||||||
'placeholder' => esc_attr__( 'Password', 'woocommerce' ),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->fields = apply_filters( 'woocommerce_checkout_fields', $this->fields );
|
|
||||||
}
|
}
|
||||||
if ( $fieldset ) {
|
|
||||||
return $this->fields[ $fieldset ];
|
if ( 'no' === get_option( 'woocommerce_registration_generate_password' ) ) {
|
||||||
} else {
|
$this->fields['account']['account_password'] = array(
|
||||||
return $this->fields;
|
'type' => 'password',
|
||||||
|
'label' => __( 'Create account password', 'woocommerce' ),
|
||||||
|
'required' => true,
|
||||||
|
'placeholder' => esc_attr__( 'Password', 'woocommerce' ),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->fields = apply_filters( 'woocommerce_checkout_fields', $this->fields );
|
||||||
|
|
||||||
|
return $fieldset ? $this->fields[ $fieldset ] : $this->fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue