'List Out of Stock products last in WooCommerce Shortcodes

Using this code to have products listed as "out of stock" listed last on Shop page but it doesn't change the order of the Woocommerce shortcodes. Looking specifically for [product_category] shortcode to have "out of stock" products listed last.

 * Sorts the Woocommerce Archive product query to push out of stock products to the end 
 */
function _nok_order_by_stock_status( $posts_clauses, $query ) {

    // only change query on WooCommerce loops
    if ( $query->is_main_query() && ( is_product_category() || is_product_tag() || is_product_taxonomy() || is_shop() ) ) {
        global $wpdb;

        $posts_clauses['join'] .= 
        " LEFT JOIN ( 
            SELECT post_id, meta_id, meta_value FROM $wpdb->postmeta 
            WHERE meta_key = '_stock_status' AND meta_value <> '' 
        ) istockstatus ON ($wpdb->posts.ID = istockstatus.post_id) ";

        $posts_clauses['orderby'] = 
        " CASE istockstatus.meta_value WHEN 
            'outofstock' THEN 1 
            ELSE 0 
        END ASC, " . $posts_clauses['orderby'];
    }

    return $posts_clauses;
}
add_filter( 'posts_clauses', '_nok_order_by_stock_status', 2000, 2 );


Sources

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

Source: Stack Overflow

Solution Source