Automattic\WooCommerce\Blocks\Utils

CartCheckoutUtils::update_blocks_with_new_attrs()public staticWC 1.0

Given an array of blocks, find the express payment block and update its attributes.

Method of the class: CartCheckoutUtils{}

No Hooks.

Return

null. Nothing (null).

Usage

$result = CartCheckoutUtils::update_blocks_with_new_attrs( $blocks, $cart_or_checkout, $updated_attrs );
$blocks(array) (required) (passed by reference — &)
Blocks to search.
$cart_or_checkout(string) (required)
The block type to check.
$updated_attrs(array) (required)
The new attributes to set.

CartCheckoutUtils::update_blocks_with_new_attrs() code WC 9.5.1

public static function update_blocks_with_new_attrs( &$blocks, $cart_or_checkout, $updated_attrs ) {
	$express_block_name = 'woocommerce/' . $cart_or_checkout . '-express-payment-block';
	foreach ( $blocks as $key => &$block ) {
		if ( ! empty( $block['blockName'] ) && $express_block_name === $block['blockName'] ) {
			$blocks[ $key ]['attrs'] = $updated_attrs;
		}

		if ( ! empty( $block['innerBlocks'] ) ) {
			self::update_blocks_with_new_attrs( $block['innerBlocks'], $cart_or_checkout, $updated_attrs );
		}
	}
}