Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Allow shoppers to sign-up for an account from the Checkout block (#3331)
Browse files Browse the repository at this point in the history
* expose checkout signup feature to release build (feature plugin):
- remove isExperimental from block/editor js (the block is already gated
  to plugin only)
- gate entire service class to feature plugin && Woo >= 4.7
  - this ensures our custom email and set password flow are only active
    for supported woo version, if blocks plugin is active
  - also refactored the gating logic so the woo version check is used to
    gate all code

* eslint action told me to delete comment `.` ... ?

* remove experimental feature flag for checkout signup front-end:
- "Create Account?" checkbox in address/contact component
- logged-out prompt logic - handle case when signup is enabled and guest
checkout is not enabled, i.e. checkout requires automatic signup

* fix formatting issues

* add allowCreateAccount to proptypes for CheckoutForm and AddressStep
  • Loading branch information
haszari authored Oct 28, 2020
1 parent fc79bb9 commit 87fecc2
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 22 deletions.
10 changes: 2 additions & 8 deletions assets/js/blocks/cart-checkout/checkout/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ import {
Main,
} from '@woocommerce/base-components/sidebar-layout';
import withScrollToTop from '@woocommerce/base-hocs/with-scroll-to-top';
import {
CHECKOUT_ALLOWS_GUEST,
isExperimentalBuild,
} from '@woocommerce/block-settings';
import { CHECKOUT_ALLOWS_GUEST } from '@woocommerce/block-settings';
import { compareWithWooVersion, getSetting } from '@woocommerce/settings';

/**
Expand Down Expand Up @@ -87,11 +84,8 @@ const Checkout = ( { attributes, scrollToTop } ) => {
// Checkout signup is feature gated to WooCommerce 4.7 and newer;
// uses updated my-account/lost-password screen from 4.7+ for
// setting initial password.
// Also currently gated to dev builds only.
const allowCreateAccount =
attributes.allowCreateAccount &&
isExperimentalBuild() &&
compareWithWooVersion( '4.7.0', '<=' );
attributes.allowCreateAccount && compareWithWooVersion( '4.7.0', '<=' );

useEffect( () => {
if ( hasErrorsToDisplay ) {
Expand Down
7 changes: 3 additions & 4 deletions assets/js/blocks/cart-checkout/checkout/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
PRIVACY_URL,
TERMS_URL,
CHECKOUT_PAGE_ID,
isExperimentalBuild,
} from '@woocommerce/block-settings';
import { compareWithWooVersion, getAdminLink } from '@woocommerce/settings';
import { createInterpolateElement } from 'wordpress-element';
Expand Down Expand Up @@ -58,9 +57,9 @@ const BlockSettings = ( { attributes, setAttributes } ) => {
// Checkout signup is feature gated to WooCommerce 4.7 and newer;
// uses updated my-account/lost-password screen from 4.7+ for
// setting initial password.
// Also currently gated to dev builds only.
const showCreateAccountOption =
isExperimentalBuild() && compareWithWooVersion( '4.7.0', '<=' );
// Also implicitly gated to feature plugin, because Checkout
// block is gated to plugin
const showCreateAccountOption = compareWithWooVersion( '4.7.0', '<=' );
return (
<InspectorControls>
{ currentPostId !== CHECKOUT_PAGE_ID && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ AddressStep.propTypes = {
showApartmentField: PropTypes.bool.isRequired,
showCompanyField: PropTypes.bool.isRequired,
showPhoneField: PropTypes.bool.isRequired,
allowCreateAccount: PropTypes.bool.isRequired,
};

export default AddressStep;
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { __ } from '@wordpress/i18n';
import { FormStep } from '@woocommerce/base-components/cart-checkout';
import { DebouncedValidatedTextInput } from '@woocommerce/base-components/text-input';
import { useCheckoutContext } from '@woocommerce/base-context';
import {
CHECKOUT_ALLOWS_GUEST,
isExperimentalBuild,
} from '@woocommerce/block-settings';
import { CHECKOUT_ALLOWS_GUEST } from '@woocommerce/block-settings';
import CheckboxControl from '@woocommerce/base-components/checkbox-control';

/**
Expand All @@ -27,11 +24,9 @@ const ContactFieldsStep = ( {
setShouldCreateAccount,
} = useCheckoutContext();

// "Create Account" checkbox is gated to dev builds only.
const createAccountUI = ! customerId &&
allowCreateAccount &&
CHECKOUT_ALLOWS_GUEST &&
isExperimentalBuild() && (
CHECKOUT_ALLOWS_GUEST && (
<CheckboxControl
className="wc-block-checkout__create-account"
label={ __(
Expand Down
1 change: 1 addition & 0 deletions assets/js/blocks/cart-checkout/checkout/form/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ CheckoutForm.propTypes = {
showCompanyField: PropTypes.bool.isRequired,
showOrderNotes: PropTypes.bool.isRequired,
showPhoneField: PropTypes.bool.isRequired,
allowCreateAccount: PropTypes.bool.isRequired,
};

export default CheckoutForm;
7 changes: 4 additions & 3 deletions src/Domain/Services/CreateAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ private static function is_feature_enabled() {
// Checkout signup is feature gated to WooCommerce 4.7 and newer;
// uses updated my-account/lost-password screen from 4.7+ for
// setting initial password.
// Also currently gated to dev builds only.
return Package::is_experimental_build();
// This service is feature gated to plugin only, to match the
// availability of the Checkout block (feature plugin only).
return Package::is_feature_plugin_build() && defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '4.7', '>=' );
}

/**
* Init - register handlers for WooCommerce core email hooks.
*/
public function init() {
if ( ! self::is_feature_enabled() || defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '4.7', '<' ) ) {
if ( ! self::is_feature_enabled() ) {
return;
}

Expand Down

0 comments on commit 87fecc2

Please sign in to comment.