diff --git a/plugins/woocommerce/includes/class-wc-privacy-exporters.php b/plugins/woocommerce/includes/class-wc-privacy-exporters.php index 1f32e9acd64..bdfa7bbd55b 100644 --- a/plugins/woocommerce/includes/class-wc-privacy-exporters.php +++ b/plugins/woocommerce/includes/class-wc-privacy-exporters.php @@ -279,7 +279,7 @@ class WC_Privacy_Exporters { break; case 'formatted_billing_address': case 'formatted_shipping_address': - $value = preg_replace( '##i', ', ', $order->{"get_$prop"}() ); + $value = wc_get_address_plain_text( $order->{"get_$prop"}() ); break; default: if ( is_callable( array( $order, 'get_' . $prop ) ) ) { diff --git a/plugins/woocommerce/includes/wc-formatting-functions.php b/plugins/woocommerce/includes/wc-formatting-functions.php index 2549d909bfb..7dc59c1db06 100644 --- a/plugins/woocommerce/includes/wc-formatting-functions.php +++ b/plugins/woocommerce/includes/wc-formatting-functions.php @@ -1574,3 +1574,23 @@ add_filter( 'woocommerce_admin_settings_sanitize_option_woocommerce_myaccount_ed add_filter( 'woocommerce_admin_settings_sanitize_option_woocommerce_myaccount_payment_methods_endpoint', 'wc_sanitize_endpoint_slug', 10, 1 ); add_filter( 'woocommerce_admin_settings_sanitize_option_woocommerce_myaccount_lost_password_endpoint', 'wc_sanitize_endpoint_slug', 10, 1 ); add_filter( 'woocommerce_admin_settings_sanitize_option_woocommerce_logout_endpoint', 'wc_sanitize_endpoint_slug', 10, 1 ); + +/** + * Get the address in plain text, stripped of tags. + * + * @param $address string Address to format. + * @return string + */ +function wc_get_address_plain_text( $address, $replace = ', ' ) { + $p = new WP_HTML_Tag_Processor( $address ); + $content = ''; + while ( $p->next_token() ) { + if( 'BR' === $p->get_tag() ) { + $content .= $replace; + continue; + } + $token = $p->get_modifiable_text(); + $content .= $token; + } + return $content; +} \ No newline at end of file diff --git a/plugins/woocommerce/src/Internal/Admin/Orders/ListTable.php b/plugins/woocommerce/src/Internal/Admin/Orders/ListTable.php index d6a46c68b0e..214e106307f 100644 --- a/plugins/woocommerce/src/Internal/Admin/Orders/ListTable.php +++ b/plugins/woocommerce/src/Internal/Admin/Orders/ListTable.php @@ -1080,7 +1080,7 @@ class ListTable extends WP_List_Table { $address = $order->get_formatted_billing_address(); if ( $address ) { - echo esc_html( preg_replace( '##i', ', ', $address ) ); + echo wc_get_address_plain_text( $address ); if ( $order->get_payment_method() ) { /* translators: %s: payment method */ @@ -1102,7 +1102,7 @@ class ListTable extends WP_List_Table { $address = $order->get_formatted_shipping_address(); if ( $address ) { - echo '' . esc_html( preg_replace( '##i', ', ', $address ) ) . ''; + echo '' . wc_get_address_plain_text( $address ) . ''; if ( $order->get_shipping_method() ) { /* translators: %s: shipping method */ echo '' . sprintf( esc_html__( 'via %s', 'woocommerce' ), esc_html( $order->get_shipping_method() ) ) . ''; diff --git a/plugins/woocommerce/templates/emails/plain/email-addresses.php b/plugins/woocommerce/templates/emails/plain/email-addresses.php index 8475ddc9959..5078318dfdc 100644 --- a/plugins/woocommerce/templates/emails/plain/email-addresses.php +++ b/plugins/woocommerce/templates/emails/plain/email-addresses.php @@ -18,7 +18,7 @@ defined( 'ABSPATH' ) || exit; echo "\n" . esc_html( wc_strtoupper( esc_html__( 'Billing address', 'woocommerce' ) ) ) . "\n\n"; -echo preg_replace( '##i', "\n", $order->get_formatted_billing_address() ) . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped +echo wc_get_address_plain_text( $order->get_formatted_billing_address() ) . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped if ( $order->get_billing_phone() ) { echo $order->get_billing_phone() . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped @@ -45,7 +45,7 @@ if ( ! wc_ship_to_billing_address_only() && $order->needs_shipping_address() ) { if ( $shipping ) { echo "\n" . esc_html( wc_strtoupper( esc_html__( 'Shipping address', 'woocommerce' ) ) ) . "\n\n"; - echo preg_replace( '##i', "\n", $shipping ) . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + echo wc_get_address_plain_text( $shipping, "\n" ) . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped if ( $order->get_shipping_phone() ) { echo $order->get_shipping_phone() . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped