Dev Resources

  • Home
  • Reference
  • BuddyX Theme
  • Functions
  • Hooks
  • Classes
Filter by type:
Search
Browse: Home / Reference / Classes / WC_Shortcode_My_Account / WC_Shortcode_My_Account::edit_address()

WC_Shortcode_My_Account::edit_address( string $load_address = 'billing' )

Edit address page.

Contents

  • Description
    • Parameters
    • Source
  • Related
    • Uses
    • Used By
  • User Contributed Notes

Description #Description


Parameters #Parameters

$load_address

(Optional) Type of address to load.

Default value: 'billing'


Top ↑

Source #Source

File: includes/shortcodes/class-wc-shortcode-my-account.php

	public static function edit_address( $load_address = 'billing' ) {
		$current_user = wp_get_current_user();
		$load_address = sanitize_key( $load_address );
		$country      = get_user_meta( get_current_user_id(), $load_address . '_country', true );

		if ( ! $country ) {
			$country = WC()->countries->get_base_country();
		}

		if ( 'billing' === $load_address ) {
			$allowed_countries = WC()->countries->get_allowed_countries();

			if ( ! array_key_exists( $country, $allowed_countries ) ) {
				$country = current( array_keys( $allowed_countries ) );
			}
		}

		if ( 'shipping' === $load_address ) {
			$allowed_countries = WC()->countries->get_shipping_countries();

			if ( ! array_key_exists( $country, $allowed_countries ) ) {
				$country = current( array_keys( $allowed_countries ) );
			}
		}

		$address = WC()->countries->get_address_fields( $country, $load_address . '_' );

		// Enqueue scripts.
		wp_enqueue_script( 'wc-country-select' );
		wp_enqueue_script( 'wc-address-i18n' );

		// Prepare values.
		foreach ( $address as $key => $field ) {

			$value = get_user_meta( get_current_user_id(), $key, true );

			if ( ! $value ) {
				switch ( $key ) {
					case 'billing_email':
					case 'shipping_email':
						$value = $current_user->user_email;
						break;
				}
			}

			$address[ $key ]['value'] = apply_filters( 'woocommerce_my_account_edit_address_field_value', $value, $key, $load_address );
		}

		wc_get_template(
			'myaccount/form-edit-address.php',
			array(
				'load_address' => $load_address,
				'address'      => apply_filters( 'woocommerce_address_to_edit', $address, $load_address ),
			)
		);
	}

Expand full source code Collapse full source code


Top ↑

Related #Related

Top ↑

Uses #Uses

Uses
Uses Description
woocommerce.php: WC()

Returns the main instance of WC.

includes/wc-core-functions.php: wc_get_template()

Get other templates (e.g. product attributes) passing attributes and including the file.

Top ↑

Used By #Used By

Used By
Used By Description
includes/wc-template-functions.php: woocommerce_account_edit_address()

My Account > Edit address template.


Top ↑

User Contributed Notes #User Contributed Notes

You must log in before being able to contribute a note or feedback.

Proudly powered by WordPress