Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Mini Cart Contents: Use block pattern to make the empty cart message translatable #6248

Merged
merged 3 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/BlockTypes/MiniCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,17 @@ class MiniCart extends AbstractBlock {
*/
public function __construct( AssetApi $asset_api, AssetDataRegistry $asset_data_registry, IntegrationRegistry $integration_registry ) {
parent::__construct( $asset_api, $asset_data_registry, $integration_registry, $this->block_name );
}

/**
* Initialize this block type.
*
* - Hook into WP lifecycle.
* - Register the block with WordPress.
*/
protected function initialize() {
parent::initialize();
add_action( 'wp_loaded', array( $this, 'register_block_pattern' ) );
}

/**
Expand Down Expand Up @@ -486,4 +496,18 @@ protected function get_inner_blocks_translations() {

return implode( '', $translations );
}

/**
* Register block patter for Empty Cart Message to make it translatable.
dinhtungdu marked this conversation as resolved.
Show resolved Hide resolved
*/
public function register_block_pattern() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think renaming this method to register_empty_message_block_pattern (or something similar) would make it clearer?

register_block_pattern(
'woocommerce/mini-cart-empty-cart-message',
array(
'title' => __( 'Mini Cart Empty Cart Message', 'woo-gutenberg-products-block' ),
'inserter' => false,
'content' => '<!-- wp:paragraph {"align":"center"} --><p class="has-text-align-center"><strong>' . __( 'Your cart is currently empty!', 'woo-gutenberg-products-block' ) . '</strong></p><!-- /wp:paragraph -->',
)
);
}
}
6 changes: 1 addition & 5 deletions templates/parts/mini-cart.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@

<!-- wp:woocommerce/empty-mini-cart-contents-block -->
<div class="wp-block-woocommerce-empty-mini-cart-contents-block">
<!-- wp:paragraph {"align":"center"} -->
<p class="has-text-align-center">
<strong>Your cart is currently empty!</strong>
</p>
<!-- /wp:paragraph -->
<!-- wp:pattern {"slug":"woocommerce/mini-cart-empty-cart-message"} /-->

<!-- wp:woocommerce/mini-cart-shopping-button-block -->
<div class="wp-block-woocommerce-mini-cart-shopping-button-block"></div>
Expand Down