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

Commit ca86f0f

Browse files
dinhtungduAljullugigitux
authored andcommitted
Mini Cart Contents: Use block pattern to make the empty cart message translatable (#6248)
* try: use block pattern to make empty cart message translatable * Update src/BlockTypes/MiniCart.php Co-authored-by: Albert Juhé Lluveras <[email protected]> * rename function Co-authored-by: Albert Juhé Lluveras <[email protected]> Co-authored-by: Luigi <[email protected]> (cherry picked from commit cfe73f1)
1 parent 333dcbd commit ca86f0f

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/BlockTypes/MiniCart.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,17 @@ class MiniCart extends AbstractBlock {
5353
*/
5454
public function __construct( AssetApi $asset_api, AssetDataRegistry $asset_data_registry, IntegrationRegistry $integration_registry ) {
5555
parent::__construct( $asset_api, $asset_data_registry, $integration_registry, $this->block_name );
56+
}
5657

58+
/**
59+
* Initialize this block type.
60+
*
61+
* - Hook into WP lifecycle.
62+
* - Register the block with WordPress.
63+
*/
64+
protected function initialize() {
65+
parent::initialize();
66+
add_action( 'wp_loaded', array( $this, 'register_empty_cart_message_block_pattern' ) );
5767
}
5868

5969
/**
@@ -486,4 +496,18 @@ protected function get_inner_blocks_translations() {
486496

487497
return implode( '', $translations );
488498
}
499+
500+
/**
501+
* Register block pattern for Empty Cart Message to make it translatable.
502+
*/
503+
public function register_empty_cart_message_block_pattern() {
504+
register_block_pattern(
505+
'woocommerce/mini-cart-empty-cart-message',
506+
array(
507+
'title' => __( 'Mini Cart Empty Cart Message', 'woo-gutenberg-products-block' ),
508+
'inserter' => false,
509+
'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 -->',
510+
)
511+
);
512+
}
489513
}

templates/parts/mini-cart.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@
2323

2424
<!-- wp:woocommerce/empty-mini-cart-contents-block -->
2525
<div class="wp-block-woocommerce-empty-mini-cart-contents-block">
26-
<!-- wp:paragraph {"align":"center"} -->
27-
<p class="has-text-align-center">
28-
<strong>Your cart is currently empty!</strong>
29-
</p>
30-
<!-- /wp:paragraph -->
26+
<!-- wp:pattern {"slug":"woocommerce/mini-cart-empty-cart-message"} /-->
3127

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

0 commit comments

Comments
 (0)