After updating to Woocommerce 3, the result count and pagination of products is incorrect with the "Hide out of stock items from the catalog" option selected ( in product inventory settings ).
I tested this on a clean install with wpdocker and the woocommerce test data.
23 total products, "Hide out of stock items from the catalog" option, set 1 to out of stock
Store page results have 23 products, 3 pages in pagination.
First page shows 10 products
Second page shows 9 products, this is the page where the out of stock product would have displayed.
Third page shows 3 products
Disabling ElasticPress shows results as expected, 22 total, page 1 is 10, page 2 is 10, page 3 is 2.
@ivankristianto mind taking a look at this one?
I think I have gotten this working on the site where I needed this setting with this https://github.com/djrmom/ep-product-visibility/blob/2bbbedffc780f808178a95ebbd213a581995c2fc/ep-product-visibility.php
On further testing, the above wasn't indexing correctly, so I now have https://github.com/djrmom/ep-product-visibility/blob/684d1552a5d16e302509f6a691a5972479f889c9/ep-product-visibility.php
@djrmom I create a PR to fix this issue at #838, would you mind testing it?
And let me know if it is fixed
Hi @ivankristianto, this does not work on my existing site. I think it is because the term_taxonomy_id is not the same as term_id for these terms.
I tried updating the code to change from term_taxonomy_id to term_id to this and seems to work:
$tax_query = array_map( function( $tax_query_el ) {
if ( is_array( $tax_query_el ) && isset( $tax_query_el[ 'field' ] ) && 'term_taxonomy_id' == $tax_query_el[ 'field' ] ) {
$tax_query_el[ 'field' ] = 'term_id';
if ( ! empty( $tax_query_el[ 'terms' ] ) ) {
$tax_query_el[ 'terms' ] = array_map( function( $tax_query_term ) {
if ( $term = get_term_by( 'term_taxonomy_id', $tax_query_term ) ) {
$tax_query_term = absint( $term->term_id );
}
return $tax_query_term;
}, (array)$tax_query_el[ 'terms' ] );
}
}
return $tax_query_el;
}, $tax_query );
@djrmom i create another PR: #840 can you test again? please reindex first
@ivankristianto #840 gives me correct results
This works awesome. Thanks @ivankristianto !