diff --git a/src/BlockTypes/Checkout.php b/src/BlockTypes/Checkout.php index c553c52f04e..66a44ba4650 100644 --- a/src/BlockTypes/Checkout.php +++ b/src/BlockTypes/Checkout.php @@ -82,18 +82,12 @@ protected function render( $attributes, $content ) { wp_dequeue_script( 'selectWoo' ); wp_dequeue_style( 'select2' ); - /** - * We need to check if the structure from $content has one of the newly added blocks from the last iteration - * The new block needs to be always in the structure, so only test for blocks with the locked:{remove:true} attribute. - * If it does, we are in the latest version of the block - * If not, we need to add a fallback to assure a successful migration of the block to the new structure - * woocommerce/checkout-order-summary-subtotal-block was added in C&C i3 and is a locked block, that should always appear - */ - $regex_for_new_block = '//mi'; + // If the content is empty, we may still be in the older checkout block. Insert the default list of blocks. + $regex_for_empty_block = '/
<\/div>/mi'; - $block_has_older_structure = ! preg_match( $regex_for_new_block, $content ); + $is_empty = preg_match( $regex_for_empty_block, $content ); - if ( $block_has_older_structure ) { + if ( $is_empty ) { /** * This fallback needs to match the defaultTemplate variables defined in the block's edit.tsx files, * starting from the parent block and going down each inner block @@ -106,9 +100,9 @@ protected function render( $attributes, $content ) {
' . - ( isset( $attributes['showOrderNotes'] ) && false === $attributes['showOrderNotes'] ? '' : '
' ) . - ( isset( $attributes['showPolicyLinks'] ) && false === $attributes['showPolicyLinks'] ? '' : '
' ) . - '
+ ( isset( $attributes['showOrderNotes'] ) && false === $attributes['showOrderNotes'] ? '' : '
' ) . + ( isset( $attributes['showPolicyLinks'] ) && false === $attributes['showPolicyLinks'] ? '' : '
' ) . + '