( wc_get_page_id( 'shop' ) ), 'woocommerce_coming_soon' => get_option( 'woocommerce_coming_soon' ), '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' ), ); } return $settings; } /** * User must be an admin or editor. * * @return bool */ private function is_manager_or_admin() { // phpcs:ignore if ( ! current_user_can( 'shop_manager' ) && ! current_user_can( 'administrator' ) ) { return false; } return true; } /** * 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. */ 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; } if ( get_user_meta( $current_user_id, self::BANNER_DISMISS_USER_META_KEY, true ) === 'yes' ) { 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, change visibility settings ", 'woocommerce' ), $link ); // phpcs:ignore echo "
"; } /** * Register user meta fields for Launch Your Store. */ public function register_launch_your_store_user_meta_fields() { if ( ! $this->is_manager_or_admin() ) { return; } register_meta( 'user', 'woocommerce_launch_your_store_tour_hidden', array( 'type' => 'string', 'description' => 'Indicate whether the user has dismissed the site visibility tour on the home screen.', 'single' => true, 'show_in_rest' => true, ) ); register_meta( 'user', self::BANNER_DISMISS_USER_META_KEY, array( 'type' => 'string', 'description' => 'Indicate whether the user has dismissed the coming soon notice or not.', 'single' => true, 'show_in_rest' => true, ) ); } /** * Reset 'woocommerce_coming_soon_banner_dismissed' user meta to 'no'. * * Runs when a user logs-in successfully. * * @param string $user_login user login. * @param object $user user object. */ public function reset_woocommerce_coming_soon_banner_dismissed( $user_login, $user ) { $existing_meta = get_user_meta( $user->ID, self::BANNER_DISMISS_USER_META_KEY, true ); if ( 'yes' === $existing_meta ) { update_user_meta( $user->ID, self::BANNER_DISMISS_USER_META_KEY, 'no' ); } } }