Automattic\WooCommerce\Blocks\BlockTypes

MiniCartCartButtonBlock::render_experimental_iapi_markupprotectedWC 1.0

Render experimental iAPI block markup.

Method of the class: MiniCartCartButtonBlock{}

No Hooks.

Returns

String. Rendered block type output.

Usage

// protected - for code of main (parent) or child class
$result = $this->render_experimental_iapi_markup( $attributes, $content, $block );
$attributes(array) (required)
Block attributes.
$content(string) (required)
Block content.
$block(WP_Block) (required)
Block instance.

MiniCartCartButtonBlock::render_experimental_iapi_markup() code WC 10.8.1

<?php
protected function render_experimental_iapi_markup( $attributes, $content, $block ) {
	$default_view_cart_text = __( 'View my cart', 'woocommerce' );
	$view_cart_text         = $attributes['cartButtonLabel'] ? $attributes['cartButtonLabel'] : $default_view_cart_text;
	$cart_page_id           = wc_get_page_id( 'cart' );
	$cart_page_url          = get_permalink( $cart_page_id );
	$classes                = implode(
		' ',
		array_filter(
			array(
				'wc-block-components-button',
				'wp-element-button wc-block-mini-cart__footer-cart',
				// Default style class is not added by default, so it needs to be added manually if it doesn't exist.
				( ! isset( $attributes['className'] ) || strpos( $attributes['className'], 'is-style-' ) === false ) ? 'is-style-outline' : '',
			)
		)
	);
	$wrapper_attributes     = get_block_wrapper_attributes(
		array(
			'href'  => esc_url( $cart_page_url ),
			'class' => $classes,
		)
	);

	ob_start();

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