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

Allow shoppers to sign-up for an account from the Checkout block #3331

Merged
merged 5 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted a full stop on this comment, but eslint action told me to remove it cc4f7ed!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the lint rule got confused by the Checkout sentence case at the end of the line. Might be a bug in the rule.

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