Woocommerce – Custom sorting and then ABC order

I have code that I am modifying inside of Up-Sells.php

I want to order by using a custom meta (OrderForProduct) and then I want to sort by ABC order. Does anyone know how to do this?

Read More

Right now when I add the meta query sorting, the products do not show if they do not have this custom value. I am looking to have it sort by the custom value and then have it sort by ABC order.

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

$args = array(
    'post_type'           => 'product',
    'ignore_sticky_posts' => 1,
    'no_found_rows'       => 1,
    'meta_key' => 'OrderForProduct',
    'posts_per_page'      => 50,
    'orderby' => 'meta_value_num', 'order'=>'ASC',
    'post__in'            => $upsells,
    'post__not_in'        => array( $product->id ),
    'meta_query'          => $meta_query
);

$products = new WP_Query( $args );

Related posts

1 comment

Comments are closed.