timber icon indicating copy to clipboard operation
timber copied to clipboard

WooCommerce/Timber bug: Timber::get_terms producing inaccurate product count inside WooCommerce categories

Open tannermannjfit opened this issue 4 years ago • 0 comments
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

  1. In Woocommerce > Settings > Products > Inventory, check the box "Hide out of stock items from the catalog"
  2. Set a product to out-of-stock.
  3. 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

tannermannjfit avatar Jun 18 '21 19:06 tannermannjfit