-
Notifications
You must be signed in to change notification settings - Fork 219
Hide the shipping address form from Checkout Block in Editor and rename the Billing Address label when "Force shipping to the customer billing address" is enabled. #7800
Changes from 1 commit
1bc2100
52be2bd
c5775f4
2f3ef34
78aa56b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,13 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import formStepAttributes from '../../form-step/attributes'; | ||
import { DEFAULT_TITLE, DEFAULT_DESCRIPTION } from './constants'; | ||
|
||
export default { | ||
export const attributes: Record< string, Record< string, unknown > > = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we use the Gutenberg type You'd need to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's a better way to define types. Added the |
||
...formStepAttributes( { | ||
defaultTitle: __( 'Billing address', 'woo-gutenberg-products-block' ), | ||
defaultDescription: __( | ||
'Enter the billing address that matches your payment method.', | ||
'woo-gutenberg-products-block' | ||
), | ||
defaultTitle: DEFAULT_TITLE, | ||
defaultDescription: DEFAULT_DESCRIPTION, | ||
} ), | ||
className: { | ||
type: 'string', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
export const DEFAULT_TITLE = __( | ||
'Billing address', | ||
'woo-gutenberg-products-block' | ||
); | ||
export const DEFAULT_DESCRIPTION = __( | ||
'Enter the billing address that matches your payment method.', | ||
'woo-gutenberg-products-block' | ||
); | ||
|
||
export const DEFAULT_FORCED_BILLING_TITLE = __( | ||
'Billing and shipping address', | ||
'woo-gutenberg-products-block' | ||
); | ||
export const DEFAULT_FORCED_BILLING_DESCRIPTION = __( | ||
'Enter the billing and shipping address that matches your payment method.', | ||
'woo-gutenberg-products-block' | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ import classnames from 'classnames'; | |
import { useBlockProps } from '@wordpress/block-editor'; | ||
import { useCheckoutAddress } from '@woocommerce/base-context/hooks'; | ||
import { innerBlockAreas } from '@woocommerce/blocks-checkout'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
|
@@ -19,6 +18,12 @@ import { | |
useCheckoutBlockControlsContext, | ||
} from '../../context'; | ||
import Block from './block'; | ||
import { | ||
DEFAULT_TITLE, | ||
DEFAULT_DESCRIPTION, | ||
DEFAULT_FORCED_BILLING_DESCRIPTION, | ||
DEFAULT_FORCED_BILLING_TITLE, | ||
} from './constants'; | ||
|
||
export const Edit = ( { | ||
attributes, | ||
|
@@ -41,12 +46,30 @@ export const Edit = ( { | |
} = useCheckoutBlockContext(); | ||
const { addressFieldControls: Controls } = | ||
useCheckoutBlockControlsContext(); | ||
const { showBillingFields } = useCheckoutAddress(); | ||
const { showBillingFields, forcedBillingAddress } = useCheckoutAddress(); | ||
|
||
if ( ! showBillingFields ) { | ||
if ( ! showBillingFields && ! forcedBillingAddress ) { | ||
return null; | ||
} | ||
|
||
if ( forcedBillingAddress ) { | ||
attributes.title = | ||
attributes.title === DEFAULT_TITLE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This ternary operator is a little hard to reason with, maybe adding comments would be useful here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would also consider if we need the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's actually a good idea! I have moved the logic to a different function and added the comments for better understanding. Thank you! 🙂 |
||
? DEFAULT_FORCED_BILLING_TITLE | ||
: attributes.title; | ||
attributes.description = | ||
attributes.description === DEFAULT_DESCRIPTION | ||
? DEFAULT_FORCED_BILLING_DESCRIPTION | ||
: attributes.description; | ||
} else { | ||
attributes.title = | ||
attributes.title === DEFAULT_FORCED_BILLING_TITLE | ||
? DEFAULT_TITLE | ||
: attributes.title; | ||
attributes.description = | ||
attributes.description === DEFAULT_FORCED_BILLING_DESCRIPTION | ||
? DEFAULT_DESCRIPTION | ||
: attributes.description; | ||
} | ||
return ( | ||
<FormStepBlock | ||
setAttributes={ setAttributes } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,14 @@ import { CHECKOUT_STORE_KEY } from '@woocommerce/block-data'; | |
* Internal dependencies | ||
*/ | ||
import Block from './block'; | ||
import attributes from './attributes'; | ||
import { attributes } from './attributes'; | ||
import { useCheckoutBlockContext } from '../../context'; | ||
import { | ||
DEFAULT_TITLE, | ||
DEFAULT_DESCRIPTION, | ||
DEFAULT_FORCED_BILLING_DESCRIPTION, | ||
DEFAULT_FORCED_BILLING_TITLE, | ||
} from './constants'; | ||
|
||
const FrontendBlock = ( { | ||
title, | ||
|
@@ -43,7 +49,19 @@ const FrontendBlock = ( { | |
if ( ! showBillingFields && ! forcedBillingAddress ) { | ||
return null; | ||
} | ||
|
||
if ( forcedBillingAddress ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please see my comment about |
||
title = title === DEFAULT_TITLE ? DEFAULT_FORCED_BILLING_TITLE : title; | ||
description = | ||
description === DEFAULT_DESCRIPTION | ||
? DEFAULT_FORCED_BILLING_DESCRIPTION | ||
: description; | ||
} else { | ||
title = title === DEFAULT_FORCED_BILLING_TITLE ? DEFAULT_TITLE : title; | ||
description = | ||
description === DEFAULT_FORCED_BILLING_DESCRIPTION | ||
? DEFAULT_DESCRIPTION | ||
: description; | ||
} | ||
return ( | ||
<FormStep | ||
id="billing-fields" | ||
|
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.
How come we removed this and now only export a named const?
Should we add
export default attributes
at the bottom of this file?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.
Ah, I missed that. This is fixed now. Thank you!