Merge branch 'pr/16165'

This commit is contained in:
Mike Jolley 2017-08-08 13:10:16 +01:00
commit 73eb086696
3 changed files with 44 additions and 23 deletions

View File

@ -439,6 +439,17 @@ class WC_Customer extends WC_Legacy_Customer {
return $value;
}
/**
* Get billing.
*
* @since 3.2.0
* @param string $context
* @return array
*/
public function get_billing( $context = 'view' ) {
return $this->get_prop( 'billing', $context );
}
/**
* Get billing_first_name.
*
@ -559,6 +570,17 @@ class WC_Customer extends WC_Legacy_Customer {
return $this->get_address_prop( 'phone', 'billing', $context );
}
/**
* Get shipping.
*
* @since 3.2.0
* @param string $context
* @return array
*/
public function get_shipping( $context = 'view' ) {
return $this->get_prop( 'shipping', $context );
}
/**
* Get shipping_first_name.
*

View File

@ -240,6 +240,24 @@ function wc_get_account_payment_methods_types() {
) );
}
/**
* Get account formatted address.
*
* @since 3.2.0
* @param string $address_type billing or shipping.
* @return string
*/
function wc_get_account_formatted_address( $address_type ) {
$getter = "get_{$address_type}";
$customer = new WC_Customer( get_current_user_id() );
if ( is_callable( array( $customer, $getter ) ) ) {
$address = $customer->$getter();
unset( $address['email'], $address['tel'] );
}
return WC()->countries->get_formatted_address( apply_filters( 'woocommerce_my_account_my_address_formatted_address', $address, $customer->get_id(), $address_type ) );
}
/**
* Returns an array of a user's saved payments list for output on the account tab.
*

View File

@ -52,29 +52,10 @@ $col = 1;
<h3><?php echo $title; ?></h3>
<a href="<?php echo esc_url( wc_get_endpoint_url( 'edit-address', $name ) ); ?>" class="edit"><?php _e( 'Edit', 'woocommerce' ); ?></a>
</header>
<address>
<?php
$address = apply_filters( 'woocommerce_my_account_my_address_formatted_address', array(
'first_name' => get_user_meta( $customer_id, $name . '_first_name', true ),
'last_name' => get_user_meta( $customer_id, $name . '_last_name', true ),
'company' => get_user_meta( $customer_id, $name . '_company', true ),
'address_1' => get_user_meta( $customer_id, $name . '_address_1', true ),
'address_2' => get_user_meta( $customer_id, $name . '_address_2', true ),
'city' => get_user_meta( $customer_id, $name . '_city', true ),
'state' => get_user_meta( $customer_id, $name . '_state', true ),
'postcode' => get_user_meta( $customer_id, $name . '_postcode', true ),
'country' => get_user_meta( $customer_id, $name . '_country', true ),
), $customer_id, $name );
$formatted_address = WC()->countries->get_formatted_address( $address );
if ( ! $formatted_address ) {
_e( 'You have not set up this type of address yet.', 'woocommerce' );
} else {
echo $formatted_address;
}
?>
</address>
<address><?php
$address = wc_get_account_formatted_address( $name );
echo $address ? wp_kses_post( $address ) : esc_html_e( 'You have not set up this type of address yet.', 'woocommerce' );
?></address>
</div>
<?php endforeach; ?>