Automattic\WooCommerce\Blocks\BlockTypes
MiniCartTitleItemsCounterBlock::render_experimental_iapi_title_label_block
Render the interactivity API powered experimental title block.
Method of the class: MiniCartTitleItemsCounterBlock{}
No Hooks.
Returns
String. Rendered block type output.
Usage
// protected - for code of main (parent) or child class $result = $this->render_experimental_iapi_title_label_block();
MiniCartTitleItemsCounterBlock::render_experimental_iapi_title_label_block() MiniCartTitleItemsCounterBlock::render experimental iapi title label block code WC 10.6.2
<?php
protected function render_experimental_iapi_title_label_block() {
$cart = $this->get_cart_instance();
$cart_item_count = $cart ? $cart->get_cart_contents_count() : 0;
// The following translation is a temporary workaround. It will be
// reverted to the previous form `(%d items)` as soon as the
// `@wordpress/i18n` package is available as a script module.
// translators: %d number of items in the cart.
$cart_item_text = __( '(items: %d)', 'woocommerce' );
wp_interactivity_config(
$this->get_full_block_name(),
array(
'itemsInCartTextTemplate' => $cart_item_text,
)
);
wp_interactivity_state(
$this->get_full_block_name(),
array(
'itemsInCartText' => sprintf( $cart_item_text, $cart_item_count ),
)
);
$wrapper_attributes = get_block_wrapper_attributes(
array(
'data-wp-text' => 'state.itemsInCartText',
'data-wp-interactive' => 'woocommerce/mini-cart-title-items-counter-block',
)
);
ob_start();
?>
<span <?php echo $wrapper_attributes; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
</span>
<?php
return ob_get_clean();
}