How to hide out of stock products in Related Products via custom query in WooCommerce

Figured it out. None of the blog posts out there are accurate it seems.

Put this in your functions.php file. You can change the posts per page number to see if its working straight away or not.

add_filter( 'woocommerce_output_related_products_args', function( $args )
{
    $args = wp_parse_args( array(
        'posts_per_page' => 4,
        'meta_query' => array (
           'key' => '_stock_status',
           'value' => 'instock'
    )
    ), $args );
    return $args;
});