Automattic\WooCommerce\Admin\Features
LaunchYourStore::maybe_add_coming_soon_banner_on_frontend()
Add 'coming soon' banner on the frontend when the following conditions met.
- User must be either an admin or store editor (must be logged in).
- 'woocommerce_coming_soon' option value must be 'yes'
- The page must not be the Coming soon page itself.
Method of the class: LaunchYourStore{}
No Hooks.
Return
null
. Nothing (null).
Usage
$LaunchYourStore = new LaunchYourStore(); $LaunchYourStore->maybe_add_coming_soon_banner_on_frontend();
LaunchYourStore::maybe_add_coming_soon_banner_on_frontend() LaunchYourStore::maybe add coming soon banner on frontend code WC 9.7.1
public function maybe_add_coming_soon_banner_on_frontend() { // Do not show the banner if the site is being previewed. if ( isset( $_GET['site-preview'] ) ) { // @phpcs:ignore return false; } $current_user_id = get_current_user_id(); if ( ! $current_user_id ) { return false; } $has_dismissed_banner = WCAdminUser::get_user_data_field( $current_user_id, self::BANNER_DISMISS_USER_META_KEY ) // Remove this check in WC 9.4. || get_user_meta( $current_user_id, 'woocommerce_' . self::BANNER_DISMISS_USER_META_KEY, true ) === 'yes'; if ( $has_dismissed_banner ) { return false; } if ( ! $this->is_manager_or_admin() ) { return false; } // 'woocommerce_coming_soon' must be 'yes' if ( get_option( 'woocommerce_coming_soon', 'no' ) !== 'yes' ) { return false; } $store_pages_only = get_option( 'woocommerce_store_pages_only' ) === 'yes'; if ( $store_pages_only && ! WCAdminHelper::is_store_page() ) { return false; } $link = admin_url( 'admin.php?page=wc-settings&tab=site-visibility' ); $rest_url = rest_url( 'wp/v2/users/' . $current_user_id ); $rest_nonce = wp_create_nonce( 'wp_rest' ); $text = sprintf( // translators: no need to translate it. It's a link. __( " This page is in \"Coming soon\" mode and is only visible to you and those who have permission. To make it public to everyone, <a href='%s'>change visibility settings</a> ", 'woocommerce' ), $link ); // phpcs:ignore echo "<div id='coming-soon-footer-banner'><div class='coming-soon-footer-banner__content'>$text</div><a class='coming-soon-footer-banner-dismiss' data-rest-url='$rest_url' data-rest-nonce='$rest_nonce'></a></div>"; }