/** * External dependencies */ import { createBlock, type BlockInstance } from '@wordpress/blocks'; import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ import type { OnClickCallbackParameter, InheritedAttributes } from './types'; const isConversionPossible = () => { return true; }; const getButtonLabel = () => __( 'Transform into blocks', 'woo-gutenberg-products-block' ); const getBlockifiedTemplate = ( inheritedAttributes: InheritedAttributes ) => [ createBlock( 'woocommerce/order-confirmation-status', { ...inheritedAttributes, fontSize: 'large', } ), createBlock( 'woocommerce/order-confirmation-summary', inheritedAttributes ), createBlock( 'woocommerce/order-confirmation-totals-wrapper', inheritedAttributes ), createBlock( 'woocommerce/order-confirmation-downloads-wrapper', inheritedAttributes ), createBlock( 'core/columns', { ...inheritedAttributes, className: 'woocommerce-order-confirmation-address-wrapper', }, [ createBlock( 'core/column', inheritedAttributes, [ createBlock( 'woocommerce/order-confirmation-shipping-wrapper', inheritedAttributes ), ] ), createBlock( 'core/column', inheritedAttributes, [ createBlock( 'woocommerce/order-confirmation-billing-wrapper', inheritedAttributes ), ] ), ] ), createBlock( 'woocommerce/order-confirmation-additional-information', inheritedAttributes ), ].filter( Boolean ) as BlockInstance[]; const onClickCallback = ( { clientId, attributes, getBlocks, replaceBlock, selectBlock, }: OnClickCallbackParameter ) => { replaceBlock( clientId, getBlockifiedTemplate( attributes ) ); const blocks = getBlocks(); const groupBlock = blocks.find( ( block ) => block.name === 'core/group' && block.innerBlocks.some( ( innerBlock ) => innerBlock.name === 'woocommerce/store-notices' ) ); if ( groupBlock ) { selectBlock( groupBlock.clientId ); } }; const getDescription = () => { return __( 'This block represents the classic template used to display the order confirmation. The actual rendered template may appear different from this placeholder.', 'woo-gutenberg-products-block' ); }; const getSkeleton = () => { return (
{ __( 'Thank you. Your order has been received.', 'woo-gutenberg-products-block' ) }
{ __( 'Product', 'woo-gutenberg-products-block' ) } | { __( 'Total', 'woo-gutenberg-products-block' ) } |
---|---|
Sample Product{ ' ' } × 2 { ' ' } | $20.00 |
{ __( 'Subtotal', 'woo-gutenberg-products-block' ) } : | $20.00 |
{ __( 'Total', 'woo-gutenberg-products-block' ) } : | $20.00 |