Avoid using meta directly

This commit is contained in:
Mike Jolley 2017-08-08 13:04:27 +01:00
parent b64d855d96
commit 2f6aaa85bb
3 changed files with 34 additions and 26 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

@ -244,30 +244,18 @@ function wc_get_account_payment_methods_types() {
* Get account formatted address.
*
* @since 3.2.0
* @param string $name
* @param string $address_type billing or shipping.
* @return string
*/
function wc_get_account_formatted_address( $name ) {
$customer_id = get_current_user_id();
$meta_keys = [
'first_name',
'last_name',
'company',
'address_1',
'address_2',
'city',
'postcode',
'country',
];
$meta = [];
foreach ( $meta_keys as $key ) {
$meta[ $key ] = get_user_meta( $customer_id, $name . '_' . $key, true );
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'] );
}
$address = apply_filters( 'woocommerce_my_account_my_address_formatted_address', $meta, $customer_id, $name );
return WC()->countries->get_formatted_address( $address );
return WC()->countries->get_formatted_address( apply_filters( 'woocommerce_my_account_my_address_formatted_address', $address, $customer->get_id(), $address_type ) );
}
/**

View File

@ -52,12 +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><?php
$address = wc_get_account_formatted_address( $name );
echo $address ? $address : __( 'You have not set up this type of address yet.', 'woocommerce' );
?>
</address>
echo $address ? wp_kses_post( $address ) : esc_html_e( 'You have not set up this type of address yet.', 'woocommerce' );
?></address>
</div>
<?php endforeach; ?>