• Resolved moemauphie

    (@moemauphie)


    Hello there,

    First off thanks for this awesome plugin.

    I don’t hide out of stock products in my shop and as you know woocommerce tends to show oldest products in the related products section so in order to avoid that I installed your plugin and checked “Exclude out of stock products” and for the most part it works as expected.

    But there is a problem with certain products. As you can see in the provided link, it only shows one related product. When I uncheck “Exclude out of stock products” it shows three more products which are all out of stock. So it seems the problem is the plugin can’t find enough in stock products.

    I would really appreciate it if you could help me solve this problem.

    Regards,

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello, i noticed the same just today. Only 1 Product or none is recommended. I hide out of stock products and just show products based on category and manufactor. Worked before, didnt change anything.

    Thread Starter moemauphie

    (@moemauphie)

    I asked ChatGDP and it gave me this code that works flawlessly with the default Woocommerce Related Products

    add_filter( 'woocommerce_related_products', 'mysite_filter_related_products', 10, 1 );
    function mysite_filter_related_products( $related_product_ids ) {
    
        // Get all in-stock products that belong to the same category or tag as the current product
        $query_args = array(
            'post_type'      => 'product',
            'post_status'    => 'publish',
            'posts_per_page' => -1,
            'tax_query'      => array(
                'relation' => 'OR',
                array(
                    'taxonomy' => 'product_cat',
                    'field'    => 'id',
                    'terms'    => wp_get_post_terms( get_the_ID(), 'product_cat', array( 'fields' => 'ids' ) ),
                ),
                array(
                    'taxonomy' => 'product_tag',
                    'field'    => 'id',
                    'terms'    => wp_get_post_terms( get_the_ID(), 'product_tag', array( 'fields' => 'ids' ) ),
                ),
            ),
            'meta_query' => array(
                array(
                    'key'     => '_stock_status',
                    'value'   => 'instock',
                    'compare' => '=',
                ),
            ),
        );
        $query = new WP_Query( $query_args );
    
        $related_product_ids = wp_list_pluck( $query->posts, 'ID' );
    
        // Get 4 products ordered by newest first
        $related_product_ids = array_slice( array_reverse( $related_product_ids ), 0, 4 );
    
        return $related_product_ids;
    }
    Plugin Support WebToffee Support

    (@webtoffeesupport)

    Hi @moemauphie @niburu,

    Thanks for reaching out. We are sorry for the inconvenience caused. We couldn’t replicate the issue when we tested the mentioned scenario on our end. However, we understand that you both are facing some issues in the mentioned section. Let’s take a look at how we can fix this together. It would be nice if you could share the screen recording of the scenario (include the plugin settings page and your product listing page including the status and category of that products) and share it with us via this link to identify the issue.

    Plugin Support WebToffee Support

    (@webtoffeesupport)

    Hi @moemauphie @niburu,

    This thread has been inactive for a bit. So we will go ahead and set this thread to resolve – please feel free to follow up on the ticket you have with us if you have further questions!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Weird Behaviour: Sometimes it only shows one product’ is closed to new replies.