'wc_get_template_part in custom query

I've got a problem with custom query for upsell products. I'm trying to create popup on single-product.php page which pops when someone click add to cart button and shows upsells products.

I manage to create custom query which get upsell product in this popup but i've got a problem when it comes to get product template.

Right now code looks like this:

function the_dramatist_return_post_id() {
    $product_id = wc_get_product( get_the_ID() );
    $product = new WC_Product($product_id);
    $upsells = $product->get_upsells();
    
    if (!$upsells)
        return;

    $meta_query = WC()->query->get_meta_query();

    $args = array(
        'post_type' => 'product',
        'ignore_sticky_posts' => 1,
        'no_found_rows' => 1,
        'posts_per_page' => $posts_per_page,
        'orderby' => $orderby,
        'post__in' => $upsells,
        'meta_query' => $meta_query
    );
    $wc_query = new WP_Query($args); // (2)
     if ($wc_query->have_posts()) : // (3)
        while ($wc_query->have_posts()) : 
                    $wc_query->the_post(); 
//                  $upsell_product = new WC_Product(get_the_ID());
//                  echo $upsell_product;
                    wc_get_template_part( 'content', 'product' );
        endwhile;
        wp_reset_postdata();
    else:  ?>
    <p><?php _e( 'Brak produktów' ); // (8) ?></p>
    <?php endif;
}

But no products are displayed.

Can someone help me with this problem?

Best regards, Kuba!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source