diff --git a/includes/wc-notice-functions.php b/includes/wc-notice-functions.php index bef5038f9c6..577fb3650a2 100644 --- a/includes/wc-notice-functions.php +++ b/includes/wc-notice-functions.php @@ -264,9 +264,19 @@ function wc_kses_notice( $message ) { * @return string */ function wc_get_notice_data_attr( $notice ) { - if ( ! isset( $notice['data']['id'] ) ) { + if ( empty( $notice['data'] ) ) { return; } - return sprintf( ' data-element-id="%s"', esc_attr( $notice['data']['id'] ) ); + $attr = ''; + + foreach ( $notice['data'] as $key => $value ) { + $attr .= sprintf( + ' data-%1$s="%2$s"', + sanitize_title( $key ), + esc_attr( $value ) + ); + } + + return $attr; } diff --git a/tests/unit-tests/util/notice-functions.php b/tests/unit-tests/util/notice-functions.php index 48fa303b82e..b6f676027e5 100644 --- a/tests/unit-tests/util/notice-functions.php +++ b/tests/unit-tests/util/notice-functions.php @@ -171,7 +171,7 @@ class WC_Tests_Notice_Functions extends WC_Unit_Test_Case { public function test_wc_print_notice_data() { // Specific type. - $this->expectOutputString( '' ); + $this->expectOutputString( '' ); wc_print_notice( 'Error!', 'error', array( 'id' => 'billing_postcode' ) ); }