PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

Wrong count of filtered products when some of them are out-of-stock, but they are hidden with woocommerce settings

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.
There is a problem - when i have some out-of-stock products, but they are hidden with woocommerce settings, i can see"showing N results" message, for example, on product's category pages (they are built with divi theme builder and consist of shortcodes [woof] and [woof_products]), where N is incorrect - it is a number of all products, in and out of stock - while only in-stock products are shown. This make some empty pages in pagination. When i don't use woof plugin, i can solve the count problem with this code in theme functions.php:
add_action('woocommerce_product_query', 'right_count');

function right_count($query) {
$meta_query = $q->get( 'meta_query' );
$meta_query[] = array(
'key' => '_stock_status',
'compare' => '=',
'value' => 'instock'
);
$q->set( 'meta_query', $meta_query );
}

But when i use woof filtering plugin, with inserting shortcode [woof_products] of this plugin into divi builder category layout, this code does nothing. Maybe woof plugin doesn't use standart woocommerce_product_query behavior but it's modificated version, as i can see in this part of woof's code:

public function woocommerce_product_query($q) {
        $meta_query = $q->get('meta_query');
//for extensions
        if (!empty(WOOF_EXT::$includes['html_type_objects'])) {
            foreach (WOOF_EXT::$includes['html_type_objects'] as $obj) {
                if (method_exists($obj, 'assemble_query_params')) {
                    $q->set('meta_query', $obj->assemble_query_params($meta_query, $q));
                }
            }
        }
        return $q;
    }

if i add right_count() function to this plugin code this way:

public function woocommerce_product_query($q) {
        $meta_query = $q->get('meta_query');
        $meta_query[] = array(
        'key' => '_stock_status',
        'compare' => '=',
        'value' => 'instock'
);
$q->set( 'meta_query', $meta_query );
        //for extensions
        if (!empty(WOOF_EXT::$includes['html_type_objects'])) {
            foreach (WOOF_EXT::$includes['html_type_objects'] as $obj) {
                if (method_exists($obj, 'assemble_query_params')) {
                    $q->set('meta_query', $obj->assemble_query_params($meta_query, $q));
                }
            }
        }
        return $q;
    }

nothing changes - the count is also wrong. How can i fix it?

Hello

I answered  you  on another  topic

Dear users, who also have this problem - please see the link on this forum https://pluginus.net/support/topic/woof-shows-results-not-only-from-it-s-category-but-also-from-others/

There is a working solution )

Hello

Ok!  Thank you for  cooperation