Automattic\WooCommerce\Blocks\BlockTypes

FilledMiniCartContentsBlock::render_experimental_filled_mini_cart_contentsprotectedWC 1.0

Render the experimental interactivity API powered Filled Mini-Cart Contents block.

Method of the class: FilledMiniCartContentsBlock{}

No Hooks.

Returns

String. Rendered block type output.

Usage

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

FilledMiniCartContentsBlock::render_experimental_filled_mini_cart_contents() code WC 10.8.1

<?php
protected function render_experimental_filled_mini_cart_contents( $attributes, $content, $block ) {
	$consent = 'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WooCommerce';
	$notices = BlocksSharedState::get_cart_error_notices( $consent );

	$context = wp_json_encode(
		array(
			'notices' => $notices,
		),
		JSON_NUMERIC_CHECK
			| JSON_HEX_TAG
			| JSON_HEX_APOS
			| JSON_HEX_QUOT
			| JSON_HEX_AMP
	);

	$wrapper_attributes = get_block_wrapper_attributes(
		array(
			'data-wp-interactive'  => 'woocommerce/mini-cart',
			'data-wp-context'      => 'woocommerce/store-notices::' . $context,
			'data-wp-bind--hidden' => 'state.cartIsEmpty',
		)
	);

	$dismiss_aria_label = __( 'Dismiss this notice', 'woocommerce' );

	ob_start();
	?>
	<div <?php echo $wrapper_attributes; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
		<div
			class="wc-block-components-notices"
			data-wp-interactive="woocommerce/store-notices"
		><template
				data-wp-each--notice="context.notices"
				data-wp-each-key="context.notice.id"
			>
				<div
					class="wc-block-components-notice-banner"
					data-wp-class--is-error="state.isError"
					data-wp-class--is-success="state.isSuccess"
					data-wp-class--is-info="state.isInfo"
					data-wp-class--is-dismissible="context.notice.dismissible"
					data-wp-bind--role="state.role"
					data-wp-watch="callbacks.injectIcon"
				>
					<div class="wc-block-components-notice-banner__content">
						<span data-wp-init="callbacks.renderNoticeContent"></span>
					</div>
					<button
						data-wp-bind--hidden="!context.notice.dismissible"
						class="wc-block-components-button wp-element-button wc-block-components-notice-banner__dismiss contained"
						aria-label="<?php echo esc_attr( $dismiss_aria_label ); ?>"
						data-wp-on--click="actions.removeNotice"
					>
						<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
							<path d="M13 11.8l6.1-6.3-1-1-6.1 6.2-6.1-6.2-1 1 6.1 6.3-6.5 6.7 1 1 6.5-6.6 6.5 6.6 1-1z" />
						</svg>
					</button>
				</div>
			</template>
		</div>
		<?php
			// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
			echo $content;
		?>
	</div>
	<?php
	return ob_get_clean();
}