From b1e3a8e9c1977810dd657b71d752280b7037c29c Mon Sep 17 00:00:00 2001 From: rjchow Date: Sun, 15 Sep 2024 15:49:53 +1000 Subject: [PATCH] feat: Add option to hide admin bar badge for coming soon mode --- .../launch-your-store/settings/slotfill.js | 31 +++++++++++++------ plugins/woocommerce/src/Admin/API/Options.php | 1 + .../src/Admin/Features/LaunchYourStore.php | 2 ++ .../ComingSoon/ComingSoonAdminBarBadge.php | 4 +-- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/plugins/woocommerce-admin/client/launch-your-store/settings/slotfill.js b/plugins/woocommerce-admin/client/launch-your-store/settings/slotfill.js index c250bfb404e..7f84ed2251b 100644 --- a/plugins/woocommerce-admin/client/launch-your-store/settings/slotfill.js +++ b/plugins/woocommerce-admin/client/launch-your-store/settings/slotfill.js @@ -48,7 +48,7 @@ const SiteVisibility = () => { setting?.woocommerce_private_link || 'no' ); const [ hideAdminBarBadge, setHideAdminBarBadge ] = useState( - setting?.woocommerce_hide_admin_bar_badge || 'no' + setting?.woocommerce_coming_soon_hide_admin_bar_badge || 'no' ); const formRef = useRef( null ); const saveButtonRef = useRef( null ); @@ -71,10 +71,16 @@ const SiteVisibility = () => { comingSoon: setting.woocommerce_coming_soon, storePagesOnly: setting.woocommerce_store_pages_only, privateLink: setting.woocommerce_private_link || 'no', - hideAdminBarBadge: setting.woocommerce_hide_admin_bar_badge || 'no', + hideAdminBarBadge: + setting.woocommerce_coming_soon_hide_admin_bar_badge || 'no', }; - const currentValues = { comingSoon, storePagesOnly, privateLink, hideAdminBarBadge }; + const currentValues = { + comingSoon, + storePagesOnly, + privateLink, + hideAdminBarBadge, + }; const saveButton = document.getElementsByClassName( 'woocommerce-save-button' )[ 0 ]; @@ -83,7 +89,8 @@ const SiteVisibility = () => { initValues.comingSoon === currentValues.comingSoon && initValues.storePagesOnly === currentValues.storePagesOnly && initValues.privateLink === currentValues.privateLink && - initValues.hideAdminBarBadge === currentValues.hideAdminBarBadge; + initValues.hideAdminBarBadge === + currentValues.hideAdminBarBadge; } }, [ comingSoon, storePagesOnly, privateLink, hideAdminBarBadge ] ); @@ -138,7 +145,7 @@ const SiteVisibility = () => {

{ __( 'Site visibility', 'woocommerce' ) }

@@ -158,13 +165,19 @@ const SiteVisibility = () => {

{ setHideAdminBarBadge( checked ? 'yes' : 'no' ); - recordEvent( 'site_visibility_hide_admin_bar_badge_toggle', { - enabled: checked, - } ); + recordEvent( + 'site_visibility_hide_admin_bar_badge_toggle', + { + enabled: checked, + } + ); } } />
diff --git a/plugins/woocommerce/src/Admin/API/Options.php b/plugins/woocommerce/src/Admin/API/Options.php index 836886fec81..be55091f071 100644 --- a/plugins/woocommerce/src/Admin/API/Options.php +++ b/plugins/woocommerce/src/Admin/API/Options.php @@ -219,6 +219,7 @@ class Options extends \WC_REST_Data_Controller { 'woocommerce_admin_customize_store_completed_theme_id', 'woocommerce_admin_customize_store_survey_completed', 'woocommerce_coming_soon', + 'woocommerce_coming_soon_hide_admin_bar_badge', 'woocommerce_store_pages_only', 'woocommerce_private_link', 'woocommerce_share_key', diff --git a/plugins/woocommerce/src/Admin/Features/LaunchYourStore.php b/plugins/woocommerce/src/Admin/Features/LaunchYourStore.php index 3bfff4518fe..bd71e2aa5f4 100644 --- a/plugins/woocommerce/src/Admin/Features/LaunchYourStore.php +++ b/plugins/woocommerce/src/Admin/Features/LaunchYourStore.php @@ -41,6 +41,7 @@ class LaunchYourStore { 'woocommerce_coming_soon' => array( 'yes', 'no' ), 'woocommerce_store_pages_only' => array( 'yes', 'no' ), 'woocommerce_private_link' => array( 'yes', 'no' ), + 'woocommerce_coming_soon_hide_admin_bar_badge' => array( 'yes', 'no' ), ); $event_data = array(); @@ -124,6 +125,7 @@ class LaunchYourStore { 'woocommerce_store_pages_only' => get_option( 'woocommerce_store_pages_only' ), 'woocommerce_private_link' => get_option( 'woocommerce_private_link' ), 'woocommerce_share_key' => get_option( 'woocommerce_share_key' ), + 'woocommerce_coming_soon_hide_admin_bar_badge' => get_option( 'woocommerce_coming_soon_hide_admin_bar_badge' ), ); } diff --git a/plugins/woocommerce/src/Internal/ComingSoon/ComingSoonAdminBarBadge.php b/plugins/woocommerce/src/Internal/ComingSoon/ComingSoonAdminBarBadge.php index 88bff9f6112..ab9fa09c5ae 100644 --- a/plugins/woocommerce/src/Internal/ComingSoon/ComingSoonAdminBarBadge.php +++ b/plugins/woocommerce/src/Internal/ComingSoon/ComingSoonAdminBarBadge.php @@ -30,7 +30,7 @@ class ComingSoonAdminBarBadge { */ public function site_visibility_badge( $wp_admin_bar ) { // Early exit if LYS feature is disabled or if the badge is hidden. - if ( ! Features::is_enabled( 'launch-your-store' ) || get_option( 'woocommerce_hide_admin_bar_badge' ) === 'yes' ) { + if ( ! Features::is_enabled( 'launch-your-store' ) || get_option( 'woocommerce_coming_soon_hide_admin_bar_badge' ) === 'yes' ) { return; } @@ -68,7 +68,7 @@ class ComingSoonAdminBarBadge { */ public function output_css() { // Early exit if LYS feature is disabled. - if ( ! Features::is_enabled( 'launch-your-store' ) ) { + if ( ! Features::is_enabled( 'launch-your-store' ) || get_option( 'woocommerce_coming_soon_hide_admin_bar_badge' ) === 'yes' ) { return; }