Automattic\WooCommerce\Blocks\BlockTypes
MiniCartShoppingButtonBlock::render
Render the markup for the Mini-Cart Shopping Button block.
Метод класса: MiniCartShoppingButtonBlock{}
Хуков нет.
Возвращает
string. Rendered block type output.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->render( $attributes, $content, $block );
- $attributes(массив) (обязательный)
- Block attributes.
- $content(строка) (обязательный)
- Block content.
- $block(WP_Block) (обязательный)
- Block instance.
Код MiniCartShoppingButtonBlock::render() MiniCartShoppingButtonBlock::render WC 11.3.0
<?php
protected function render( $attributes, $content, $block ) {
// The button uses the core Button block classes, so load that block's stylesheet even when the page has no Button block.
wp_enqueue_style( 'wp-block-button' );
ob_start();
$shop_url = wc_get_page_permalink( 'shop' );
$default_start_shopping_label = __( 'Return to shop', 'woocommerce' );
$start_shopping_label = $attributes['startShoppingButtonLabel'] ? $attributes['startShoppingButtonLabel'] : $default_start_shopping_label;
// Same markup and classes as a core Button block, so the theme's button styles apply.
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => 'wp-block-button__link wp-element-button wc-block-mini-cart__shopping-button' ) );
?>
<div class="wp-block-button has-text-align-center">
<a
href="<?php echo esc_attr( $shop_url ); ?>"
<?php echo $wrapper_attributes; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
><?php echo esc_html( $start_shopping_label ); ?></a>
</div>
<?php
return (string) ob_get_clean();
}