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

Commit

Permalink
Mini Cart Contents: Use block pattern to make the empty cart message …
Browse files Browse the repository at this point in the history
…translatable (#6248)

* try: use block pattern to make empty cart message translatable

* Update src/BlockTypes/MiniCart.php

Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>

* rename function

Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
Co-authored-by: Luigi <gigitux@gmail.com>
  • Loading branch information
3 people committed Apr 13, 2022
1 parent 3bbf648 commit cfe73f1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
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_empty_cart_message_block_pattern' ) );
}

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

return implode( '', $translations );
}

/**
* Register block pattern for Empty Cart Message to make it translatable.
*/
public function register_empty_cart_message_block_pattern() {
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

0 comments on commit cfe73f1

Please sign in to comment.