-
Notifications
You must be signed in to change notification settings - Fork 219
Fix the related products block result when used along a grouped product #8656
Conversation
The release ZIP for this PR is accessible via:
Script Dependencies ReportThere is no changed script dependency between this branch and trunk. This comment was automatically generated by the TypeScript Errors Report
🎉 🎉 This PR does not introduce new TS errors. |
Size Change: +50 B (0%) Total Size: 1.12 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…ocks into fix/8589-wrong-results-grouped-blocks
…b.com/woocommerce/woocommerce-blocks into fix/8589-wrong-results-grouped-blocks
Yes, I tested the block always below the Classic Single Grid Block. The issue is that the variable $product is set when the loop is started (source code). The filter This issue didn't happen when the block was below the Classic Single Grid Block because the block triggered the loop, and WC set the product in the global variable. I fixed it via ab0f601 |
* @return string The block content. | ||
*/ | ||
public function render_block( string $content, array $block ) { | ||
if ( ! $this->is_related_products_block( $block ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if this conditional is really necessary, because by default on line 120, it will always return the $content, except if the count( $related_products_ids ) < 1
(on line 117)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is hooked to the render_block
filter. So this means that every function hooked to the render_block
is executed for each block that will be rendered. For this reason, I do this check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything looks good to me. Thank you for working on this! 🚀
This PR fixes the related products block result when used along a grouped product: following WC Core, the block should not show any product.
Furthermore, I put inside the Related Products block a heading block with the text:
Related Products
. This is necessary because we only want to show theRelated Products
text when the related products block shows products. For this reason, it will be necessary to update #8515Fixes #8589
User Facing Testing
WooCommerce Single Product Block
, add theRelated Products block
.Related Products block
are equal to the row generated by theWooCommerce Single Product Block
.Related Products block
are equal to the row generated by theWooCommerce Single Product Block
. (no product should be displayed)WooCommerce Visibility