From 1928f34699d61bd454929375aa381e9441b62b79 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 4 Feb 2019 13:18:09 +0000 Subject: [PATCH] Add notice hash to store notice cookie Closes #21963 --- assets/js/frontend/woocommerce.js | 15 +++++++++------ includes/wc-template-functions.php | 4 +++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/assets/js/frontend/woocommerce.js b/assets/js/frontend/woocommerce.js index 3183d98e08a..693ece80893 100644 --- a/assets/js/frontend/woocommerce.js +++ b/assets/js/frontend/woocommerce.js @@ -14,19 +14,22 @@ jQuery( function( $ ) { } }); - // Set a cookie and hide the store notice when the dismiss button is clicked - $( '.woocommerce-store-notice__dismiss-link' ).click( function() { - Cookies.set( 'store_notice', 'hidden', { path: '/' } ); - $( '.woocommerce-store-notice' ).hide(); - }); + var noticeID = $( '.woocommerce-store-notice' ).data( 'notice-id' ) || '', + cookieName = 'store_notice' + noticeID; // Check the value of that cookie and show/hide the notice accordingly - if ( 'hidden' === Cookies.get( 'store_notice' ) ) { + if ( 'hidden' === Cookies.get( cookieName ) ) { $( '.woocommerce-store-notice' ).hide(); } else { $( '.woocommerce-store-notice' ).show(); } + // Set a cookie and hide the store notice when the dismiss button is clicked + $( '.woocommerce-store-notice__dismiss-link' ).click( function() { + Cookies.set( cookieName, 'hidden', { path: '/' } ); + $( '.woocommerce-store-notice' ).hide(); + }); + // Make form field descriptions toggle on focus. $( document.body ).on( 'click', function() { $( '.woocommerce-input-wrapper span.description:visible' ).prop( 'aria-hidden', true ).slideUp( 250 ); diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index 07700eec66f..1d47c59bd2e 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -963,7 +963,9 @@ if ( ! function_exists( 'woocommerce_demo_store' ) ) { $notice = __( 'This is a demo store for testing purposes — no orders shall be fulfilled.', 'woocommerce' ); } - echo apply_filters( 'woocommerce_demo_store', '

' . wp_kses_post( $notice ) . ' ' . esc_html__( 'Dismiss', 'woocommerce' ) . '

', $notice ); // WPCS: XSS ok. + $notice_id = md5( $notice ); + + echo apply_filters( 'woocommerce_demo_store', '', $notice ); // WPCS: XSS ok. } }