mardi 30 décembre 2014

Woocommerce- Show upsells in order received page [on hold]


I am trying to show the upsell products in the order received page. (thank you page after the order is placed)


I have managed to get the product id on that page, however i am unable to get the upsell ids from that product id.


Here is what I tried to use.



$items = $order->get_items();

foreach ( $items as $item ) {
$product_id = $item['product_id'];
}

echo $product_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,
'post__not_in' => array($product->id),
'meta_query' => $meta_query
);

$products = new WP_Query($args);
if ( $products->have_posts() ) : ?>

<div class="upsells products">

<h2><?php _e( 'You may also like&hellip;', 'woocommerce' ) ?></h2>

<?php woocommerce_product_loop_start(); ?>

<?php while ( $products->have_posts() ) : $products->the_post(); ?>

<?php wc_get_template_part( 'content', 'product' ); ?>

<?php endwhile; // end of the loop. ?>

<?php woocommerce_product_loop_end(); ?>

</div>

<?php endif; ?>


There is always only ONE product in the cart and not many products.


The above loop doesn't display anything at all. WP_Debug is true, still no error !


Any help is appreciated.





Aucun commentaire:

Enregistrer un commentaire