diff --git a/changelog/fix-8334-leftover-onboarding-sandbox-mode b/changelog/fix-8334-leftover-onboarding-sandbox-mode new file mode 100644 index 00000000000..e5891e26fe5 --- /dev/null +++ b/changelog/fix-8334-leftover-onboarding-sandbox-mode @@ -0,0 +1,5 @@ +Significance: patch +Type: fix +Comment: Prevent leftover sandbox mode onboarding and allow for live onboarding on subsequent retries. + + diff --git a/includes/class-wc-payments-account.php b/includes/class-wc-payments-account.php index 57c63333962..215b48149a6 100644 --- a/includes/class-wc-payments-account.php +++ b/includes/class-wc-payments-account.php @@ -1085,6 +1085,14 @@ public function maybe_handle_onboarding() { ) ) { // Redirect non-onboarded account to the onboarding flow, otherwise to payments overview page. if ( ! $this->is_stripe_connected() ) { + $should_onboard_in_test_mode = isset( $_GET['test_mode'] ) ? boolval( wc_clean( wp_unslash( $_GET['test_mode'] ) ) ) : false; + if ( ! $should_onboard_in_test_mode && WC_Payments_Onboarding_Service::is_test_mode_enabled() ) { + // If there is no test mode in the URL informing us to onboard in test mode, + // but the onboarding test mode is enabled in our DB, we should disable it. + // This is most likely a leftover from a previous onboarding attempt. + WC_Payments_Onboarding_Service::set_test_mode( false ); + } + $this->redirect_to_onboarding_flow_page( $source ); } else { // Accounts with Stripe account connected will be redirected to the overview page.