Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* Plugin Name: Fix woocommerce admin analytics performance issue
* Plugin URI:
* Description:
* Version: 1.0.0
* Author:
* Author URI:
* License: MIT
*/
add_filter('posts_where', function ($where, WP_Query $wp_query) {
if ($wp_query->get('low_in_stock')) {
$wp_query->set('low_in_stock', false);
}
return $where;
}, 9, 3);
@odirlon

This comment has been minimized.

Copy link

@odirlon odirlon commented Jul 16, 2021

Very good! It worked.

@HWGehring

This comment has been minimized.

Copy link

@HWGehring HWGehring commented Jul 16, 2021

Thanks. I had to bump priority up to 9999 for it to work, but this was what I was looking for.

@jlbeltrana

This comment has been minimized.

Copy link

@jlbeltrana jlbeltrana commented Jul 19, 2021

Excuse the question, but where should I put that file?

@fitimvata

This comment has been minimized.

Copy link
Owner Author

@fitimvata fitimvata commented Jul 19, 2021

Excuse the question, but where should I put that file?

@jlbeltrana you need to add this file in wp-content/mu-plugins

@jlbeltrana

This comment has been minimized.

Copy link

@jlbeltrana jlbeltrana commented Jul 19, 2021

Excuse the question, but where should I put that file?

@jlbeltrana you need to add this file in wp-content/mu-plugins

Thanks

@ThrudUK

This comment has been minimized.

Copy link

@ThrudUK ThrudUK commented Jul 20, 2021

Can this just go in functions.php?

@fitimvata

This comment has been minimized.

Copy link
Owner Author

@fitimvata fitimvata commented Jul 20, 2021

@ThrudUK yes

@ThrudUK

This comment has been minimized.

Copy link

@ThrudUK ThrudUK commented Jul 20, 2021

@ThrudUK yes

Many thanks!

So much weird Woo behaviour around product info generally with this security update!

@fitimvata

This comment has been minimized.

Copy link
Owner Author

@fitimvata fitimvata commented Jul 20, 2021

Weird why? I think that security update was not related with this issue. The issue with this query has been for a long time but was detected in latest release because the query is executed more frequently. See this comment woocommerce/woocommerce-admin#7358 (comment)

@ThrudUK

This comment has been minimized.

Copy link

@ThrudUK ThrudUK commented Jul 20, 2021

Weird why? I think that security update was not related with this issue. The issue with this query has been for a long time but was detected in latest release because the query is executed more frequently. See this comment woocommerce/woocommerce-admin#7358 (comment)

Hmm... might not be the security update. But for example :

In any product....
Go to Quick Edit
Set Product as hidden
Update
Go To Quick Edit
Product is showing as hidden
Change to Catalog & Search
Update
Go to Quick Edit
Product is showing as hidden
REFRESH THE BROWSER
Go to quick edit
Product is showing as Catalog and search

I'm seeing this on multiple installs of Woo

@rickdroio

This comment has been minimized.

Copy link

@rickdroio rickdroio commented Jul 21, 2021

Thanks!! worked like a charm!! low stock query was blocking my website!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment