-
Notifications
You must be signed in to change notification settings - Fork 0
fix: add the saas onboarding pattern to the shop, checkout and order received #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
YvesCesar
wants to merge
2
commits into
main
Choose a base branch
from
fix/saas-onboarding-pattern
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+293
−26
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?php | ||
| /** | ||
| * SaaS onboarding: shown only while buying a new plan. | ||
| * | ||
| * @package libresign | ||
| */ | ||
|
|
||
| defined( 'ABSPATH' ) || exit; | ||
|
|
||
| function libresign_theme_show_saas_onboarding_only_on_new_purchases( $block_content, $block ) { | ||
| $class_names = explode( ' ', $block['attrs']['className'] ?? '' ); | ||
| if ( ! in_array( 'libresign-saas-onboarding', $class_names, true ) ) { | ||
| return $block_content; | ||
| } | ||
|
|
||
| if ( function_exists( 'is_wc_endpoint_url' ) && is_wc_endpoint_url( 'order-pay' ) ) { | ||
| return ''; | ||
| } | ||
|
|
||
| $order_id = absint( get_query_var( 'order-received' ) ); | ||
| if ( $order_id && function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id, array( 'renewal', 'switch', 'resubscribe' ) ) ) { | ||
| return ''; | ||
| } | ||
|
|
||
| return $block_content; | ||
| } | ||
| add_filter( 'render_block_core/group', 'libresign_theme_show_saas_onboarding_only_on_new_purchases', 10, 2 ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| <?php | ||
| /** | ||
| * Title: SaaS onboarding | ||
| * Slug: libresign/saas-onboarding | ||
| * Inserter: no | ||
| */ | ||
| ?> | ||
|
|
||
| <!-- wp:group {"align":"wide","className":"libresign-saas-onboarding","style":{"spacing":{"margin":{"bottom":"var:preset|spacing|40"}}},"layout":{"type":"default"}} --> | ||
| <div class="wp-block-group alignwide libresign-saas-onboarding" style="margin-bottom:var(--wp--preset--spacing--40)"> | ||
| <!-- wp:heading {"level":2,"fontSize":"large"} --> | ||
| <h2 class="wp-block-heading has-large-font-size"><?php echo esc_html__( 'How your LibreSign workspace works', 'libresign' ); ?></h2> | ||
| <!-- /wp:heading --> | ||
|
|
||
| <!-- wp:columns --> | ||
| <div class="wp-block-columns"> | ||
| <!-- wp:column --> | ||
| <div class="wp-block-column"> | ||
| <!-- wp:heading {"level":3,"fontSize":"medium"} --> | ||
| <h3 class="wp-block-heading has-medium-font-size"><?php echo esc_html__( '1. Choose a plan', 'libresign' ); ?></h3> | ||
| <!-- /wp:heading --> | ||
|
|
||
| <!-- wp:paragraph --> | ||
| <p><?php echo esc_html__( 'Pick the plan that fits your team.', 'libresign' ); ?></p> | ||
| <!-- /wp:paragraph --> | ||
| </div> | ||
| <!-- /wp:column --> | ||
|
|
||
| <!-- wp:column --> | ||
| <div class="wp-block-column"> | ||
| <!-- wp:heading {"level":3,"fontSize":"medium"} --> | ||
| <h3 class="wp-block-heading has-medium-font-size"><?php echo esc_html__( '2. Create your workspace', 'libresign' ); ?></h3> | ||
| <!-- /wp:heading --> | ||
|
|
||
| <!-- wp:paragraph --> | ||
| <p><?php echo esc_html__( 'Set your email and password and complete the payment.', 'libresign' ); ?></p> | ||
| <!-- /wp:paragraph --> | ||
| </div> | ||
| <!-- /wp:column --> | ||
|
|
||
| <!-- wp:column --> | ||
| <div class="wp-block-column"> | ||
| <!-- wp:heading {"level":3,"fontSize":"medium"} --> | ||
| <h3 class="wp-block-heading has-medium-font-size"><?php echo esc_html__( '3. Start signing', 'libresign' ); ?></h3> | ||
| <!-- /wp:heading --> | ||
|
|
||
| <!-- wp:paragraph --> | ||
| <p><?php echo esc_html__( 'Sign in to LibreSign with the same email and password.', 'libresign' ); ?></p> | ||
| <!-- /wp:paragraph --> | ||
| </div> | ||
| <!-- /wp:column --> | ||
| </div> | ||
| <!-- /wp:columns --> | ||
| </div> | ||
| <!-- /wp:group --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { expect, Page, test } from '@playwright/test'; | ||
|
|
||
| import { addThePlanToTheCart, fillTheBillingAddress, placeOrder } from '../support/store'; | ||
|
|
||
| async function expectTheOnboarding( page: Page ): Promise< void > { | ||
| await expect( page.getByRole( 'heading', { name: 'How your LibreSign workspace works' } ) ).toHaveCount( 1 ); | ||
| await expect( page.getByRole( 'heading', { name: '1. Choose a plan' } ) ).toBeVisible(); | ||
| await expect( page.getByRole( 'heading', { name: '2. Create your workspace' } ) ).toBeVisible(); | ||
| await expect( page.getByRole( 'heading', { name: '3. Start signing' } ) ).toBeVisible(); | ||
| } | ||
|
|
||
| test.describe( 'Showing how the workspace works while buying', () => { | ||
| test( 'on the shop', async ( { page } ) => { | ||
| await page.goto( '/shop/' ); | ||
|
|
||
| await expectTheOnboarding( page ); | ||
| } ); | ||
|
|
||
| test( 'on the checkout', async ( { page } ) => { | ||
| await addThePlanToTheCart( page ); | ||
| await page.goto( '/checkout/' ); | ||
|
|
||
| await expectTheOnboarding( page ); | ||
| } ); | ||
|
|
||
| test( 'on the order received', async ( { page } ) => { | ||
| await addThePlanToTheCart( page ); | ||
| await fillTheBillingAddress( page, 'Brazil', '529.982.247-25' ); | ||
| await page.getByLabel( 'I agree to the terms and privacy policy before placing the order.' ).check(); | ||
| await placeOrder( page ); | ||
|
|
||
| await expect( page ).toHaveURL( /\/order-received\// ); | ||
| await expectTheOnboarding( page ); | ||
| } ); | ||
|
|
||
| test( 'not on other pages', async ( { page } ) => { | ||
| await page.goto( '/product/basic/' ); | ||
|
|
||
| await expect( page.getByRole( 'heading', { name: 'How your LibreSign workspace works' } ) ).toHaveCount( 0 ); | ||
| } ); | ||
| } ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| <?php | ||
|
|
||
| namespace LibreSign\WordPressTheme\Tests\Integration\Inc; | ||
|
|
||
| use LibreSign\WordPressTheme\Tests\Support\StoreFactory; | ||
| use WCS_Related_Order_Store; | ||
| use WP_UnitTestCase; | ||
|
|
||
| final class OnboardingTest extends WP_UnitTestCase { | ||
|
|
||
| private const HEADING = 'How your LibreSign workspace works'; | ||
|
|
||
| private $store; | ||
|
|
||
| public function set_up() { | ||
| parent::set_up(); | ||
|
|
||
| $this->store = new StoreFactory(); | ||
| } | ||
|
|
||
| public function tear_down() { | ||
| unset( $GLOBALS['wp']->query_vars['order-pay'], $GLOBALS['wp']->query_vars['order-received'] ); | ||
| set_query_var( 'order-received', '' ); | ||
|
|
||
| parent::tear_down(); | ||
| } | ||
|
|
||
| public function test_shows_the_onboarding_while_buying() { | ||
| $this->assertStringContainsString( self::HEADING, $this->onboarding() ); | ||
| } | ||
|
|
||
| public function test_shows_the_onboarding_when_a_new_order_is_received() { | ||
| $this->receive( $this->order() ); | ||
|
|
||
| $this->assertStringContainsString( self::HEADING, $this->onboarding() ); | ||
| } | ||
|
|
||
| public function test_hides_the_onboarding_when_paying_an_existing_order() { | ||
| $GLOBALS['wp']->query_vars['order-pay'] = (string) $this->order()->get_id(); | ||
|
|
||
| $this->assertSame( '', trim( $this->onboarding() ) ); | ||
| } | ||
|
|
||
| /** | ||
| * @dataProvider provide_orders_of_existing_subscriptions | ||
| */ | ||
| public function test_hides_the_onboarding_when_an_order_of_an_existing_subscription_is_received( $relation ) { | ||
| $order = $this->order(); | ||
| WCS_Related_Order_Store::instance()->add_relation( $order, $this->subscription(), $relation ); | ||
| $this->receive( $order ); | ||
|
|
||
| $this->assertSame( '', trim( $this->onboarding() ) ); | ||
| } | ||
|
|
||
| public static function provide_orders_of_existing_subscriptions() { | ||
| yield 'a renewal' => array( 'renewal' ); | ||
| yield 'a switch' => array( 'switch' ); | ||
| yield 'a resubscribe' => array( 'resubscribe' ); | ||
| } | ||
|
|
||
| public function test_keeps_other_groups_while_hiding_the_onboarding() { | ||
| $GLOBALS['wp']->query_vars['order-pay'] = (string) $this->order()->get_id(); | ||
|
|
||
| $this->assertStringContainsString( 'Other group', do_blocks( '<!-- wp:group --><div class="wp-block-group"><p>Other group</p></div><!-- /wp:group -->' ) ); | ||
| } | ||
|
|
||
| private function onboarding() { | ||
| return do_blocks( '<!-- wp:pattern {"slug":"libresign/saas-onboarding"} /-->' ); | ||
| } | ||
|
|
||
| private function order() { | ||
| $order = wc_create_order(); | ||
| $order->add_product( $this->store->plan() ); | ||
| $order->save(); | ||
|
|
||
| return $order; | ||
| } | ||
|
|
||
| private function subscription() { | ||
| return wcs_create_subscription( | ||
| array( | ||
| 'customer_id' => self::factory()->user->create(), | ||
| 'billing_period' => 'month', | ||
| 'billing_interval' => 1, | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| private function receive( $order ) { | ||
| $GLOBALS['wp']->query_vars['order-received'] = (string) $order->get_id(); | ||
| set_query_var( 'order-received', (string) $order->get_id() ); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Existing subscription flows also go through the normal checkout.
WooCommerce Subscriptions builds the cart and redirects renewals, resubscriptions and switches to
wc_get_checkout_url(). At that pointorder-payis no longer set and there is noorder-receivedyet, so this filter will render the onboarding during checkout.The plugin already provides
wcs_cart_contains_renewal(),wcs_cart_contains_resubscribe()andwcs_cart_contains_switches()to identify these flows.Since this onboarding should only be shown when buying a new plan, we should also hide it for these cart states and cover them with tests.