Automattic\WooCommerce\Internal\Admin\Onboarding

OnboardingSetupWizard::handle_admin_post_woocommerce_skip_onboarding_setup │ public │ WC 11.3.0

Handle the authenticated onboarding setup skip fallback.

Saves the skip without the REST API, then explains that some screens may not work and where to look.

Method of the class: OnboardingSetupWizard{}

No Hooks.

Returns

null. Nothing (null).

Usage

$OnboardingSetupWizard = new OnboardingSetupWizard();
$OnboardingSetupWizard->handle_admin_post_woocommerce_skip_onboarding_setup(): void;

Changelog

Since 11.3.0 Introduced.

OnboardingSetupWizard::handle_admin_post_woocommerce_skip_onboarding_setup() code WC 11.3.0

public function handle_admin_post_woocommerce_skip_onboarding_setup(): void {
	if ( ! current_user_can( 'manage_woocommerce' ) ) {
		wp_die(
			esc_html__( 'You do not have permission to skip WooCommerce setup.', 'woocommerce' ),
			'',
			array( 'response' => 403 )
		);
	}

	check_admin_referer( self::SKIP_ONBOARDING_SETUP_ACTION );

	$profile            = (array) get_option( OnboardingProfile::DATA_OPTION, array() );
	$profile['skipped'] = true;
	update_option( OnboardingProfile::DATA_OPTION, $profile );

	$persisted_profile = (array) get_option( OnboardingProfile::DATA_OPTION, array() );
	if ( true !== ( $persisted_profile['skipped'] ?? false ) ) {
		wp_die(
			esc_html__( 'WooCommerce could not save your setup preference. Please try again.', 'woocommerce' ),
			'',
			array( 'response' => 500 )
		);
	}

	if ( current_user_can( 'view_site_health_checks' ) ) {
		$next_step = sprintf(
			/* translators: %s: link to the WordPress Site Health screen. */
			esc_html__( 'If WooCommerce screens keep failing to load, check %s for problems with the REST API.', 'woocommerce' ),
			'<a href="' . esc_url( admin_url( 'site-health.php' ) ) . '">' . esc_html__( 'Site Health', 'woocommerce' ) . '</a>'
		);
	} else {
		$next_step = esc_html__( 'If WooCommerce screens keep failing to load, ask your hosting provider to check that your site’s REST API is working.', 'woocommerce' );
	}

	$store_location_notice = '';
	// The profiler adds this flag when it could not save the country and currency the merchant picked.
	if ( isset( $_GET['store_location_not_saved'] ) ) {
		$store_location_notice = '<p>' . sprintf(
			/* translators: %s: link to the WooCommerce general settings screen. */
			esc_html__( 'Your store location and currency were not saved. Set them in %s, since taxes and prices depend on them.', 'woocommerce' ),
			'<a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=general' ) ) . '">' . esc_html__( 'WooCommerce > Settings > General', 'woocommerce' ) . '</a>'
		) . '</p>';
	}

	wp_die(
		'<h1>' . esc_html__( 'WooCommerce setup skipped', 'woocommerce' ) . '</h1>' .
		'<p>' . esc_html__( 'Your choice to skip setup is saved. Your site’s REST API did not respond correctly, so some WooCommerce screens may not work until that is fixed.', 'woocommerce' ) . '</p>' .
		wp_kses_post( $store_location_notice ) .
		'<p>' . wp_kses_post( $next_step ) . '</p>' .
		'<p><a class="button button-primary" href="' . esc_url( wc_admin_url() ) . '">' . esc_html__( 'Continue to WooCommerce Home', 'woocommerce' ) . '</a></p>',
		esc_html__( 'WooCommerce setup skipped', 'woocommerce' ),
		array( 'response' => 200 )
	);
}