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

Commit

Permalink
Fix Single Product Classic Template block not showing on the front-end (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
sunyatasattva authored and gigitux committed Nov 8, 2023
1 parent 1c17b88 commit fdaa429
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/BlockTypes/ClassicTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,16 @@ protected function render_single_product() {
*/
do_action( 'woocommerce_before_main_content' );

while ( have_posts() ) :
$product_query = new \WP_Query(
array(
'post_type' => 'product',
'p' => get_the_ID(),
)
);

while ( $product_query->have_posts() ) :

the_post();
$product_query->the_post();
wc_get_template_part( 'content', 'single-product' );

endwhile;
Expand Down

0 comments on commit fdaa429

Please sign in to comment.