Automattic\WooCommerce\Blocks\BlockTypes

CheckoutExpressPaymentBlock::update_other_page_with_express_payment_attrs()privateWC 1.0

Update the express payment attributes in the other page (Cart or Checkout).

Method of the class: CheckoutExpressPaymentBlock{}

No Hooks.

Return

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->update_other_page_with_express_payment_attrs( $cart_or_checkout, $updated_attrs );
$cart_or_checkout(string) (required)
The page to update.
$updated_attrs(array) (required)
The updated attributes.

CheckoutExpressPaymentBlock::update_other_page_with_express_payment_attrs() code WC 9.6.0

private function update_other_page_with_express_payment_attrs( $cart_or_checkout, $updated_attrs ) {
	$page_id = 'cart' === $cart_or_checkout ? wc_get_page_id( 'cart' ) : wc_get_page_id( 'checkout' );

	if ( -1 === $page_id ) {
		return;
	}

	$post = get_post( $page_id );

	if ( empty( $post->post_content ) ) {
		return;
	}

	$blocks = parse_blocks( $post->post_content );
	CartCheckoutUtils::update_blocks_with_new_attrs( $blocks, $cart_or_checkout, $updated_attrs );

	$updated_content = serialize_blocks( $blocks );
	remove_action( 'save_post', array( $this, 'sync_express_payment_attrs' ), 10, 2 );

	wp_update_post(
		array(
			'ID'           => $page_id,
			'post_content' => $updated_content,
		),
		false,
		false
	);

	add_action( 'save_post', array( $this, 'sync_express_payment_attrs' ), 10, 2 );
}