Woocommerce – Changing the order of the upsell products [closed]

Getting too long for a comment, sooo in my super simple test overriding up-sells.php on a fresh WC install with a WP_Query, I can change the orderby and order parameters and the products display in the order of my array of product ids:

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

$my_upsells = [171, 170, 172];

$args = array(
    'post_type'           => 'product',
    'ignore_sticky_posts' => 1,
    'no_found_rows'       => 1,
    'posts_per_page'      => $posts_per_page,
    'orderby'             => 'post__in',
    'order'               => 'asc',
    'post__in'            => $my_upsells,
    'meta_query'          => $meta_query
);

$products = new WP_Query( $args );

while( $products->have_posts() ) : $products->the_post();
    echo get_the_title() . "<br>";
endwhile;

One thing to note, WordPress does say that you cannot combine post__in and post__not_in in the same query, and you shouldn’t need it anyways if your $upsells array already has the ids you want.

Would you mind sharing the whole template file you’re working in, or at least more about how you’re outputting the results of this query? It doesn’t sound like the query you’re working on is affecting your output at all, so that makes me think you have some kind of disconnect going on there.

Edit: It appears that you are using a very old version of woocommerce @ v1.6.4 that means your Woocommerce hasn’t been updated since 2012! The function get_upsells() that you said you added is actually a woocommerce function, and it’s deprecated in Woocommerce 3, which is what I’m testing on. I’d strongly suggest doing some updates before you continue attempting to fix anything.

I can’t continue to help you until we know your issues aren’t being caused by your out of date version of Woocommerce, and possibly an outdated version of WordPress.