enter image description here

I have external products which I don’t want to show in related products section in single product. Normally related products are 4 on my website, but when i added meta query to it to exclude the external product, it excludes fine, but shows 3 products, instead of 4 because one of the product is external. What I want is to get related products and if one or several of them are external products, just exclude them, and within that empty space that is left after excluding those external products replace them with normal products so that it will still show 4 products instead of 3 or 2. I opened related.php to modify the args to select the products which have price greater than 1, which will result in excluding the external products.

$args = apply_filters( 'woocommerce_related_products_args', array(
    'post_type'            => 'product',
    'ignore_sticky_posts'  => 1,
    'no_found_rows'        => 1,
    'posts_per_page'       => $posts_per_page,
    'orderby'              => $orderby,
    'post__in'             => $related,
    'post__not_in'         => array( $product->id ),

    'meta_query' => array(
            array(
                'key' => '_price',
                'value' => 1,
                'compare' => '>',
                'type' => 'NUMERIC',
                    'no_found_rows'  => false
            )
        )
) );

Kindly help me out with this. Thanks!

Read more here: Meta query shows 3 posts instead of 4


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: