(.*?)<\/div>/si';
}
/**
* Render the Checkout Order Summary block.
*
* @param array $attributes Block attributes.
* @param string $content Block content.
* @param object $block Block object.
* @return string Rendered block.
*/
protected function render( $attributes, $content, $block ) {
// The order-summary-totals block was introduced as a new parent block for the totals
// (subtotal, discount, fees, shipping and taxes) blocks.
$regex_for_checkout_order_summary_totals = '/
/';
$order_summary_totals_content = '
';
// We want to move these blocks inside a parent 'totals' block.
$totals_inner_blocks = array( 'subtotal', 'discount', 'fee', 'shipping', 'taxes' );
if ( preg_match( $regex_for_checkout_order_summary_totals, $content ) ) {
return $content;
}
foreach ( $totals_inner_blocks as $key => $block_name ) {
$inner_block_content = $this->get_inner_block_content( $block_name, $content );
if ( $inner_block_content ) {
$order_summary_totals_content .= "\n" . $inner_block_content;
// The last block is replaced with the totals block.
if ( count( $totals_inner_blocks ) - 1 === $key ) {
$order_summary_totals_content .= '
';
$content = preg_replace( $this->inner_block_regex( $block_name ), $order_summary_totals_content, $content );
} else {
// Otherwise, remove the block.
$content = preg_replace( $this->inner_block_regex( $block_name ), '', $content );
}
}
}
// Remove empty lines.
return preg_replace( '/\n\n( *?)/i', '', $content );
}
}