More cleanup and new fallback option for addresses
This commit is contained in:
parent
adcf83441b
commit
7419168e65
|
@ -808,23 +808,41 @@ class WC_Order extends WC_Abstract_Order {
|
||||||
/**
|
/**
|
||||||
* Get a formatted billing address for the 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
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_formatted_billing_address() {
|
public function get_formatted_billing_address( $empty_html = '' ) {
|
||||||
return WC()->countries->get_formatted_address( apply_filters( 'woocommerce_order_formatted_billing_address', $this->get_address( 'billing' ), $this ) );
|
$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.
|
* 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
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_formatted_shipping_address() {
|
public function get_formatted_shipping_address( $empty_html = '' ) {
|
||||||
|
$address = '';
|
||||||
|
|
||||||
if ( $this->has_shipping_address() ) {
|
if ( $this->has_shipping_address() ) {
|
||||||
return WC()->countries->get_formatted_address( apply_filters( 'woocommerce_order_formatted_shipping_address', $this->get_address( 'shipping' ), $this ) );
|
$address = apply_filters( 'woocommerce_order_formatted_shipping_address', $this->get_address( 'shipping' ), $this );
|
||||||
} else {
|
$address = WC()->countries->get_formatted_address( $address );
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -19,45 +19,44 @@
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
$show_shipping = ! wc_ship_to_billing_address_only() && $order->needs_shipping_address();
|
||||||
?>
|
?>
|
||||||
<section class="woocommerce-customer-details">
|
<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 if ( $order->get_billing_phone() ) : ?>
|
||||||
<?php echo ( $address = $order->get_formatted_billing_address() ) ? $address : __( 'N/A', 'woocommerce' ); ?>
|
<p class="woocommerce-customer-details--phone"><?php echo esc_html( $order->get_billing_phone() ); ?></p>
|
||||||
<?php if ( $order->get_billing_phone() ) : ?>
|
<?php endif; ?>
|
||||||
<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 ( ! 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>
|
</section><!-- /.col2-set -->
|
||||||
<?php echo ( $address = $order->get_formatted_shipping_address() ) ? $address : __( 'N/A', 'woocommerce' ); ?>
|
|
||||||
</address>
|
|
||||||
|
|
||||||
</div><!-- /.col-2 -->
|
<?php endif; ?>
|
||||||
|
|
||||||
</section><!-- /.col2-set -->
|
|
||||||
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
Loading…
Reference in New Issue