More cleanup and new fallback option for addresses

This commit is contained in:
Mike Jolley 2017-10-16 08:12:07 -07:00
parent adcf83441b
commit 7419168e65
2 changed files with 49 additions and 32 deletions

View File

@ -808,23 +808,41 @@ class WC_Order extends WC_Abstract_Order {
/**
* Get a formatted billing address for the order.
*
* @param string $empty_html Content to show if no address is present. @since 3.3.0.
* @return string
*/
public function get_formatted_billing_address() {
return WC()->countries->get_formatted_address( apply_filters( 'woocommerce_order_formatted_billing_address', $this->get_address( 'billing' ), $this ) );
public function get_formatted_billing_address( $empty_html = '' ) {
$address = apply_filters( 'woocommerce_order_formatted_billing_address', $this->get_address( 'billing' ), $this );
$address = WC()->countries->get_formatted_address( $address );
return $address ? $address : $empty_content;
}
/**
* Get a formatted shipping address for the order.
*
* @param string $empty_html Content to show if no address is present. @since 3.3.0.
* @return string
*/
public function get_formatted_shipping_address() {
public function get_formatted_shipping_address( $empty_html = '' ) {
$address = '';
if ( $this->has_shipping_address() ) {
return WC()->countries->get_formatted_address( apply_filters( 'woocommerce_order_formatted_shipping_address', $this->get_address( 'shipping' ), $this ) );
} else {
return '';
$address = apply_filters( 'woocommerce_order_formatted_shipping_address', $this->get_address( 'shipping' ), $this );
$address = WC()->countries->get_formatted_address( $address );
}
return $address ? $address : $empty_content;
}
/**
* Returns true if the order has a billing address.
*
* @since 3.0.4
* @return boolean
*/
public function has_billing_address() {
return $this->get_shipping_address_1() || $this->get_shipping_address_2();
}
/**

View File

@ -19,45 +19,44 @@
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$show_shipping = ! wc_ship_to_billing_address_only() && $order->needs_shipping_address();
?>
<section class="woocommerce-customer-details">
<?php if ( ! wc_ship_to_billing_address_only() && $order->needs_shipping_address() ) : ?>
<?php if ( $show_shipping ) : ?>
<section class="woocommerce-columns woocommerce-columns--2 woocommerce-columns--addresses col2-set addresses">
<section class="woocommerce-columns woocommerce-columns--2 woocommerce-columns--addresses col2-set addresses">
<div class="woocommerce-column woocommerce-column--1 woocommerce-column--billing-address col-1">
<div class="woocommerce-column woocommerce-column--1 woocommerce-column--billing-address col-1">
<?php endif; ?>
<?php endif; ?>
<h2 class="woocommerce-column__title"><?php _e( 'Billing address', 'woocommerce' ); ?></h2>
<h2 class="woocommerce-column__title"><?php _e( 'Billing address', 'woocommerce' ); ?></h2>
<address>
<?php echo wp_kses_post( $order->get_formatted_billing_address( __( 'N/A', 'woocommerce' ) ) ); ?>
<address>
<?php echo ( $address = $order->get_formatted_billing_address() ) ? $address : __( 'N/A', 'woocommerce' ); ?>
<?php if ( $order->get_billing_phone() ) : ?>
<p class="woocommerce-customer-details--phone"><?php echo esc_html( $order->get_billing_phone() ); ?></p>
<?php endif; ?>
<?php if ( $order->get_billing_email() ) : ?>
<p class="woocommerce-customer-details--email"><?php echo esc_html( $order->get_billing_email() ); ?></p>
<?php endif; ?>
</address>
<?php if ( $order->get_billing_phone() ) : ?>
<p class="woocommerce-customer-details--phone"><?php echo esc_html( $order->get_billing_phone() ); ?></p>
<?php endif; ?>
<?php if ( ! wc_ship_to_billing_address_only() && $order->needs_shipping_address() ) : ?>
<?php if ( $order->get_billing_email() ) : ?>
<p class="woocommerce-customer-details--email"><?php echo esc_html( $order->get_billing_email() ); ?></p>
<?php endif; ?>
</address>
</div><!-- /.col-1 -->
<?php if ( $show_shipping ) : ?>
<div class="woocommerce-column woocommerce-column--2 woocommerce-column--shipping-address col-2">
</div><!-- /.col-1 -->
<h2 class="woocommerce-column__title"><?php _e( 'Shipping address', 'woocommerce' ); ?></h2>
<div class="woocommerce-column woocommerce-column--2 woocommerce-column--shipping-address col-2">
<h2 class="woocommerce-column__title"><?php _e( 'Shipping address', 'woocommerce' ); ?></h2>
<address>
<?php echo wp_kses_post( $order->get_formatted_shipping_address( __( 'N/A', 'woocommerce' ) ) ); ?>
</address>
</div><!-- /.col-2 -->
<address>
<?php echo ( $address = $order->get_formatted_shipping_address() ) ? $address : __( 'N/A', 'woocommerce' ); ?>
</address>
</section><!-- /.col2-set -->
</div><!-- /.col-2 -->
</section><!-- /.col2-set -->
<?php endif; ?>
<?php endif; ?>
</section>