feat: Add option to hide admin bar badge for coming soon mode

This commit is contained in:
rjchow 2024-09-15 15:49:53 +10:00
parent b56f337b43
commit b1e3a8e9c1
No known key found for this signature in database
4 changed files with 27 additions and 11 deletions

View File

@ -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 = () => {
<input
type="hidden"
value={ hideAdminBarBadge }
name="woocommerce_hide_admin_bar_badge"
name="woocommerce_coming_soon_hide_admin_bar_badge"
/>
<h2>{ __( 'Site visibility', 'woocommerce' ) }</h2>
<p className="site-visibility-settings-slotfill-description">
@ -158,13 +165,19 @@ const SiteVisibility = () => {
</p>
<ToggleControl
label={ __( 'Hide admin bar badge', 'woocommerce' ) }
help={ __( 'Hide the site visibility badge from the admin bar.', 'woocommerce' ) }
help={ __(
'Hide the site visibility badge from the admin bar.',
'woocommerce'
) }
checked={ hideAdminBarBadge === 'yes' }
onChange={ ( checked ) => {
setHideAdminBarBadge( checked ? 'yes' : 'no' );
recordEvent( 'site_visibility_hide_admin_bar_badge_toggle', {
enabled: checked,
} );
recordEvent(
'site_visibility_hide_admin_bar_badge_toggle',
{
enabled: checked,
}
);
} }
/>
<div className="site-visibility-settings-slotfill-section">

View File

@ -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',

View File

@ -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' ),
);
}

View File

@ -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;
}