Fixed "Illegal offset" error caused by #24146

Introduces new filters to better handle order's formatted addresses
This commit is contained in:
Claudio Sanches 2019-09-24 13:15:35 -03:00
parent 8bd6a44763
commit 52108c1577
1 changed files with 22 additions and 10 deletions

View File

@ -876,10 +876,17 @@ class WC_Order extends WC_Abstract_Order {
* @return string
*/
public function get_formatted_billing_address( $empty_content = '' ) {
$address = apply_filters( 'woocommerce_order_formatted_billing_address', $this->get_address( 'billing' ), $this );
$address = WC()->countries->get_formatted_address( $address );
$raw_address = apply_filters( 'woocommerce_order_formatted_billing_address', $this->get_address( 'billing' ), $this );
$address = WC()->countries->get_formatted_address( $raw_address );
return $address ? $address : $empty_content;
/**
* Filter orders formatterd billing address.
*
* @since 3.7.1
* @param string $address Formatted billing address string.
* @param array $raw_address Raw billing address.
*/
return apply_filters( 'woocommerce_order_get_formatted_billing_address', $address ? $address : $empty_content, $raw_address );
}
/**
@ -889,17 +896,22 @@ class WC_Order extends WC_Abstract_Order {
* @return string
*/
public function get_formatted_shipping_address( $empty_content = '' ) {
$address = '';
if ( $this->has_shipping_address() ) {
$address = $this->get_address( 'shipping' );
}
$address = apply_filters( 'woocommerce_order_formatted_shipping_address', $address, $this );
$address = '';
$raw_address = $this->get_address( 'shipping' );
if ( $this->has_shipping_address() ) {
$address = WC()->countries->get_formatted_address( $address );
$raw_address = apply_filters( 'woocommerce_order_formatted_shipping_address', $raw_address, $this );
$address = WC()->countries->get_formatted_address( $raw_address );
}
return $address ? $address : $empty_content;
/**
* Filter orders formatterd shipping address.
*
* @since 3.7.1
* @param string $address Formatted shipping address string.
* @param array $raw_address Raw shipping address.
*/
return apply_filters( 'woocommerce_order_get_formatted_shipping_address', $address ? $address : $empty_content, $raw_address );
}
/**