/** * External dependencies */ import classnames from 'classnames'; import { __ } from '@wordpress/i18n'; import { InspectorControls } from '@wordpress/block-editor'; import { PanelBody, ToggleControl, CheckboxControl, Notice, Disabled, } from '@wordpress/components'; import BlockErrorBoundary from '@woocommerce/base-components/block-error-boundary'; import { PRIVACY_URL, TERMS_URL, CHECKOUT_PAGE_ID, CHECKOUT_ALLOWS_SIGNUP, } from '@woocommerce/block-settings'; import { isWcVersion, getAdminLink } from '@woocommerce/settings'; import { createInterpolateElement } from 'wordpress-element'; import { useRef } from '@wordpress/element'; import { EditorProvider, useEditorContext, StoreNoticesProvider, } from '@woocommerce/base-context'; import { CartCheckoutFeedbackPrompt } from '@woocommerce/editor-components/feedback-prompt'; import PageSelector from '@woocommerce/editor-components/page-selector'; import { CartCheckoutCompatibilityNotice } from '@woocommerce/editor-components/compatibility-notices'; import { previewCart, previewSavedPaymentMethods, } from '@woocommerce/resource-previews'; /** * Internal dependencies */ import Block from './block.js'; import './editor.scss'; const BlockSettings = ( { attributes, setAttributes } ) => { const { showCompanyField, showApartmentField, showPhoneField, requireCompanyField, requirePhoneField, allowCreateAccount, showOrderNotes, showPolicyLinks, showReturnToCart, cartPageId, hasDarkControls, } = attributes; const { currentPostId } = useEditorContext(); const { current: savedCartPageId } = useRef( cartPageId ); // 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 implicitly gated to feature plugin, because Checkout // block is gated to plugin const showCreateAccountOption = CHECKOUT_ALLOWS_SIGNUP && isWcVersion( '4.7.0', '>=' ); return ( { currentPostId !== CHECKOUT_PAGE_ID && ( { createInterpolateElement( __( 'If you would like to use this block as your default checkout you must update your page settings in WooCommerce.', 'woo-gutenberg-products-block' ), { a: ( // eslint-disable-next-line jsx-a11y/anchor-has-content ), } ) } ) } { __( 'Include additional address fields in the checkout form.', 'woo-gutenberg-products-block' ) } setAttributes( { showCompanyField: ! showCompanyField, } ) } /> { showCompanyField && ( setAttributes( { requireCompanyField: ! requireCompanyField, } ) } className="components-base-control--nested" /> ) } setAttributes( { showApartmentField: ! showApartmentField, } ) } /> setAttributes( { showPhoneField: ! showPhoneField, } ) } /> { showPhoneField && ( setAttributes( { requirePhoneField: ! requirePhoneField, } ) } className="components-base-control--nested" /> ) } { showCreateAccountOption && ( setAttributes( { allowCreateAccount: ! allowCreateAccount, } ) } /> ) } { __( 'Reduce the number of fields to checkout.', 'woo-gutenberg-products-block' ) } setAttributes( { showOrderNotes: ! showOrderNotes, } ) } /> setAttributes( { showPolicyLinks: ! showPolicyLinks, } ) } /> { showPolicyLinks && ( ! PRIVACY_URL || ! TERMS_URL ) && ( { createInterpolateElement( __( 'Pages must be first setup in store settings: Privacy policy, Terms and conditions.', 'woo-gutenberg-products-block' ), { a1: ( // eslint-disable-next-line jsx-a11y/anchor-has-content ), a2: ( // eslint-disable-next-line jsx-a11y/anchor-has-content ), } ) } ) } setAttributes( { showReturnToCart: ! showReturnToCart, } ) } /> { showReturnToCart && ! ( currentPostId === CHECKOUT_PAGE_ID && savedCartPageId === 0 ) && ( setAttributes( { cartPageId: id } ) } labels={ { title: __( 'Return to Cart button', 'woo-gutenberg-products-block' ), default: __( 'WooCommerce Cart Page', 'woo-gutenberg-products-block' ), } } /> ) } setAttributes( { hasDarkControls: ! hasDarkControls, } ) } /> ); }; const CheckoutEditor = ( { attributes, setAttributes } ) => { const { className, isPreview } = attributes; return ( <> > ); }; export default CheckoutEditor;
{ __( 'Include additional address fields in the checkout form.', 'woo-gutenberg-products-block' ) }
{ __( 'Reduce the number of fields to checkout.', 'woo-gutenberg-products-block' ) }