ProductImageGallery Block Fails to Apply Zoom and Lightbox Filters in Block Context
Summary:
The ProductImageGallery block contains logic to enable the WooCommerce product image zoom and lightbox features by filtering woocommerce_single_product_zoom_enabled and woocommerce_single_product_photoswipe_enabled to return true. This logic is correctly implemented within the block's code.
However, a critical issue arises because this filter is applied during the block's render method. If the block is rendered before the wp_enqueue_scripts hook fires (which is common when blocks are processed), the filter is not yet active. Consequently, any code checking the state of these filters from within a block context (e.g., inside a render_block filter) will receive false instead of the expected true.
This bug breaks the expected behavior for developers extending WooCommerce blocks, as they cannot reliably detect if the core zoom/lightbox features are enabled. It specifically impacts scenarios where custom content is injected into other blocks, like the Add to Cart form block, that need to interact with the product gallery's functionality.
How to Replicate:
- Add a filter to the
render_block_woocommerce/add-to-cart-formhook. - Inside the callback function, check the value of the
woocommerce_single_product_photoswipe_enabledfilter. - Observe that the value returned is
falseeven when the ProductImageGallery block is present and expected to enable it. - The provided code snippet in the report demonstrates this exact replication step.