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

Commit d9e8809

Browse files
Fix Single Product Classic Template block not showing on the front-end (#11455)
In WordPress 6.4, it appears that the global `have_posts` is `false` in the context of the full site editing single product template. This breaks the Classic Template block. In this commit, we are creating a custom query using the available id instead of relying on the global query. This might be a temporary workaround as we are waiting to see if that's an issue that core is willing to fix, as it might affect backwards-compatibility for other vendors.
1 parent 159322f commit d9e8809

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/BlockTypes/ClassicTemplate.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,16 @@ protected function render_single_product() {
173173
*/
174174
do_action( 'woocommerce_before_main_content' );
175175

176-
while ( have_posts() ) :
176+
$product_query = new \WP_Query(
177+
array(
178+
'post_type' => 'product',
179+
'p' => get_the_ID(),
180+
)
181+
);
182+
183+
while ( $product_query->have_posts() ) :
177184

178-
the_post();
185+
$product_query->the_post();
179186
wc_get_template_part( 'content', 'single-product' );
180187

181188
endwhile;

0 commit comments

Comments
 (0)