Automattic\WooCommerce\Blocks\BlockTypes

MiniCartCheckoutButtonBlock::render │ protected │ WC 1.0

Render the markup for the Mini-Cart Contents block.

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

Хуков нет.

Возвращает

string. Rendered block type output.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->render( $attributes, $content, $block );
$attributes(массив) (обязательный)
Block attributes.
$content(строка) (обязательный)
Block content.
$block(WP_Block) (обязательный)
Block instance.

Код MiniCartCheckoutButtonBlock::render() WC 11.3.0

<?php
protected function render( $attributes, $content, $block ) {
	$default_checkout_text = __( 'Checkout', 'woocommerce' );
	$checkout_text         = $attributes['checkoutButtonLabel'] ? $attributes['checkoutButtonLabel'] : $default_checkout_text;
	$checkout_page_id      = wc_get_page_id( 'checkout' );
	$checkout_page_url     = get_permalink( $checkout_page_id );
	$wrapper_attributes    = get_block_wrapper_attributes(
		array(
			'href'                        => esc_url( $checkout_page_url ),
			'class'                       => 'wc-block-components-button wp-element-button wc-block-mini-cart__footer-checkout',
			'data-wp-bind--aria-disabled' => 'woocommerce/mini-cart::state.isCartUpdating',
			'data-wp-on--click'           => 'woocommerce/mini-cart::actions.preventCheckoutWhileUpdating',
		)
	);

	ob_start();
	?>
	<a <?php echo $wrapper_attributes; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
		<div class="wc-block-components-button__text">
			<?php echo esc_html( $checkout_text ); ?>
		</div>
	</a>
	<?php
	return (string) ob_get_clean();
}