Automattic\WooCommerce\Blocks\BlockTypes

CheckoutExpressPaymentBlock::update_other_page_with_express_payment_attrsprivateWC 1.0

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

Метод класса: CheckoutExpressPaymentBlock{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

// private - только в коде основоного (родительского) класса
$result = $this->update_other_page_with_express_payment_attrs( $cart_or_checkout, $updated_attrs );
$cart_or_checkout(строка) (обязательный)
The page to update.
$updated_attrs(массив) (обязательный)
The updated attributes.

Код CheckoutExpressPaymentBlock::update_other_page_with_express_payment_attrs() WC 9.9.4

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 );
}