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

Commit

Permalink
Revert changes to Checkout.php, we don't need to test for inner blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ralucaStan committed Apr 11, 2022
1 parent e4ab313 commit fc39535
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/BlockTypes/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '/<div[\n\r\s\ta-zA-Z0-9_\-=\'"]*data-block-name="woocommerce\/checkout-order-summary-subtotal-block"[\n\r\s\ta-zA-Z0-9_\-=\'"]*>/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 class="[a-zA-Z0-9_\- ]*wp-block-woocommerce-checkout[a-zA-Z0-9_\- ]*"><\/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
Expand All @@ -106,9 +100,9 @@ protected function render( $attributes, $content ) {
<div data-block-name="woocommerce/checkout-billing-address-block" class="wp-block-woocommerce-checkout-billing-address-block"></div>
<div data-block-name="woocommerce/checkout-shipping-methods-block" class="wp-block-woocommerce-checkout-shipping-methods-block"></div>
<div data-block-name="woocommerce/checkout-payment-block" class="wp-block-woocommerce-checkout-payment-block"></div>' .
( isset( $attributes['showOrderNotes'] ) && false === $attributes['showOrderNotes'] ? '' : '<div data-block-name="woocommerce/checkout-order-note-block" class="wp-block-woocommerce-checkout-order-note-block"></div>' ) .
( isset( $attributes['showPolicyLinks'] ) && false === $attributes['showPolicyLinks'] ? '' : '<div data-block-name="woocommerce/checkout-terms-block" class="wp-block-woocommerce-checkout-terms-block"></div>' ) .
'<div data-block-name="woocommerce/checkout-actions-block" class="wp-block-woocommerce-checkout-actions-block"></div>
( isset( $attributes['showOrderNotes'] ) && false === $attributes['showOrderNotes'] ? '' : '<div data-block-name="woocommerce/checkout-order-note-block" class="wp-block-woocommerce-checkout-order-note-block"></div>' ) .
( isset( $attributes['showPolicyLinks'] ) && false === $attributes['showPolicyLinks'] ? '' : '<div data-block-name="woocommerce/checkout-terms-block" class="wp-block-woocommerce-checkout-terms-block"></div>' ) .
'<div data-block-name="woocommerce/checkout-actions-block" class="wp-block-woocommerce-checkout-actions-block"></div>
</div>
<div data-block-name="woocommerce/checkout-totals-block" class="wp-block-woocommerce-checkout-totals-block">
<div data-block-name="woocommerce/checkout-order-summary-block" class="wp-block-woocommerce-checkout-order-summary-block">
Expand Down

0 comments on commit fc39535

Please sign in to comment.