I need to display the featured products in top of the shop page and also needs to display out of stock products in the bottom of the list.
I am able to make the out of stock products in the bottom with the following code but it re-orders the featured product along with it.
add_action( 'pre_get_posts', function ( $q ) {
if ( is_shop() // Target only front end
&& $q->is_main_query() // Only target the main query
&& $q->is_post_type_archive() // Change to suite your needs
) {
$q->set( 'meta_key', '_stock_status' );
$q->set( 'orderby', 'meta_value' );
$q->set( 'order', 'ASC' );
}
}, PHP_INT_MAX );
Is there a way through which I can achieve both?
Please help me in it.
Thanks.