Trim commas and empty lines off address formats Fixes #5411
This commit is contained in:
parent
616542b09c
commit
b6c4d9a852
|
@ -667,7 +667,7 @@ class WC_Countries {
|
|||
$full_state = ( $country && $state && isset( $this->states[ $country ][ $state ] ) ) ? $this->states[ $country ][ $state ] : $state;
|
||||
|
||||
// Substitute address parts into the string
|
||||
$replace = apply_filters( 'woocommerce_formatted_address_replacements', array(
|
||||
$replace = array_map( 'esc_html', apply_filters( 'woocommerce_formatted_address_replacements', array(
|
||||
'{first_name}' => $first_name,
|
||||
'{last_name}' => $last_name,
|
||||
'{name}' => $first_name . ' ' . $last_name,
|
||||
|
@ -688,9 +688,7 @@ class WC_Countries {
|
|||
'{state_upper}' => strtoupper( $full_state ),
|
||||
'{postcode_upper}' => strtoupper( $postcode ),
|
||||
'{country_upper}' => strtoupper( $full_country ),
|
||||
), $args ) ;
|
||||
|
||||
$replace = array_map( 'esc_html', $replace );
|
||||
), $args ) );
|
||||
|
||||
$formatted_address = str_replace( array_keys( $replace ), $replace, $format );
|
||||
|
||||
|
@ -698,13 +696,25 @@ class WC_Countries {
|
|||
$formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) );
|
||||
$formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );
|
||||
|
||||
// Break newlines apart and remove empty lines/trim commas and white space
|
||||
$formatted_address = array_filter( array_map( array( $this, 'trim_formatted_address_line' ), explode( "\n", $formatted_address ) ) );
|
||||
|
||||
// Add html breaks
|
||||
$formatted_address = nl2br( $formatted_address );
|
||||
$formatted_address = implode( '<br/>', $formatted_address );
|
||||
|
||||
// We're done!
|
||||
return $formatted_address;
|
||||
}
|
||||
|
||||
/**
|
||||
* trim white space and commans off a line
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
private function trim_formatted_address_line( $line ) {
|
||||
return trim( $line, ", " );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the fields we show by default. This can be filtered later on.
|
||||
|
|
Loading…
Reference in New Issue