Product Collection: Fix: ensure the global product object is always ready for compatibility layer (#49971)

* add: method for block to declare extra block setting for registration

* update: register Product Template block with skip_inner_blocks

* chore: remove unused import

* chore: changelog

* Revert "update: register Product Template block with skip_inner_blocks"

This reverts commit 88b076bde3.

* Revert "add: method for block to declare extra block setting for registration"

This reverts commit d1545dbba5.

* fix: filter block setting for product template

* chore: changelog

* Revert "chore: remove unused import"

This reverts commit 0f8f66bad1.
This commit is contained in:
Tung Du 2024-08-09 16:37:45 +07:00 committed by GitHub
parent aaf3046eb6
commit 5047182efd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Fix: ensure the global product object is always ready for compatibility layer by disabling default render routine of Product Templates inner blocks.

View File

@ -17,6 +17,18 @@ class ProductTemplate extends AbstractBlock {
*/ */
protected $block_name = 'product-template'; protected $block_name = 'product-template';
/**
* Initialize this block type.
*
* - Hook into WP lifecycle.
* - Register the block with WordPress.
* - Hook into pre_render_block to update the query.
*/
protected function initialize() {
add_filter( 'block_type_metadata_settings', array( $this, 'add_block_type_metadata_settings' ), 10, 2 );
parent::initialize();
}
/** /**
* Get the frontend script handle for this block type. * Get the frontend script handle for this block type.
* *
@ -134,4 +146,19 @@ class ProductTemplate extends AbstractBlock {
return false; return false;
} }
/**
* Product Template renders inner blocks manually so we need to skip default
* rendering routine for its inner blocks
*
* @param array $settings Array of determined settings for registering a block type.
* @param array $metadata Metadata provided for registering a block type.
* @return array
*/
public function add_block_type_metadata_settings( $settings, $metadata ) {
if ( ! empty( $metadata['name'] ) && 'woocommerce/product-template' === $metadata['name'] ) {
$settings['skip_inner_blocks'] = true;
}
return $settings;
}
} }