timber
timber copied to clipboard
WooCommerce/Timber bug: Timber::get_terms producing inaccurate product count inside WooCommerce categories
trafficstars
Expected behavior
I have 38 products in a category in WooCommerce. One of them is out of stock. Since I have out-of-stock products set to be hidden in WooCommerce settings, I am expecting the post count on this category when calling Timber::get_terms to be 37, just like when I use Wordpress's default get_terms.
Actual behavior
Timber::get_terms shows a post count of 38 (undesirable), while get_terms correctly shows 37.
Steps to reproduce behavior
- In Woocommerce > Settings > Products > Inventory, check the box "Hide out of stock items from the catalog"
- Set a product to out-of-stock.
- Print out the following variables to test:
// Shows 37 (correct)
$test_wp_terms = get_terms('product_cat', array('parent' => 0, 'hide_empty' => true));
// Shows 38 (incorrect)
$timber_terms = Timber::get_terms('product_cat', array('parent' => 0, 'hide_empty' => true)));
What version of WordPress, PHP and Timber are you using?
WordPress 5.7.2, PHP 7.4, Timber 1.18.2
How did you install Timber? (for example, from GitHub, Composer/Packagist, WP.org?)
Upgraded to newest version via plugin updater in WordPress dashboard