Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 2
CRAP
n/a
0 / 0
wpcom_redirect_to_woo_design_with_ai
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
wpcom_maybe_redirect_to_woo_design_with_ai
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2/**
3 * Redirects user to Woo's Design With AI when user
4 * creates a site through the Entrepreneur signup flow.
5 *
6 * @package wpcomsh
7 */
8
9/**
10 * Redirect to Design With AI page with `ref=entrepreneur-signup` in the URL.
11 * Also deletes the `_wc_activation_redirect` transient which is used for first-time woo onboarding.
12 *
13 * @return never
14 */
15function wpcom_redirect_to_woo_design_with_ai() {
16    delete_transient( '_wc_activation_redirect' );
17    wp_safe_redirect( wc_admin_url( '&path=%2Fcustomize-store%2Fdesign-with-ai&ref=entrepreneur-signup' ) );
18    exit( 0 );
19}
20
21/**
22 * Determine whether to redirect to Design With AI page when user lands on the admin page
23 * based on the whether the site is created through Entrepreneur signup flow
24 * and if we are still at the stage of first-time woo onboarding.
25 */
26function wpcom_maybe_redirect_to_woo_design_with_ai() {
27
28    // Skip if the blog is not created through Entrepreneur signup flow.
29    if ( ! get_option( 'wpcom_is_entrepreneur_signup' ) ) {
30        return;
31    }
32
33    // Skip if Woo is no longer doing a first-time activation redirect.
34    if ( ! get_transient( '_wc_activation_redirect' ) ) {
35        return;
36    }
37
38    // When this function is called, we intervene OnboardingSetupWizard::do_admin_redirects()
39    // and redirect the user to the Woo's Design With AI page.
40    add_filter( 'woocommerce_prevent_automatic_wizard_redirect', 'wpcom_redirect_to_woo_design_with_ai' );
41}
42
43add_action( 'admin_init', 'wpcom_maybe_redirect_to_woo_design_with_ai', 1 );