In Stock as default, but not applied at page load
-
Hello,
I have mainly unique products. So I don’t want to show out of stock products.
I wrote a function, modifying pre_get_posts to hide those when searching inside my web site.
add_action( 'pre_get_posts', 'my_hide_out_of_stock_products' );
I works well this way, but it seems that Woocommerce Product Filter works differently. So I choose to add the “Stock Status” filter, choose “In stock” as default value and hide this filter.
But at page first load, no (pre)filter is applied. If I select something in a filter, it works well:pr_stock=instock
is added to the query, andoutofstock
items are not shown.But still: at first page load, in my “Size” filter, I have option (say it is “X”) that lead to “No product found” and disappearance of this X option from the filter when removing the selected size filter.
What is weird is that without instock filter, the filter behaves the same: I check “X”, it filters, no product found, I remove “X”, filters change and now the “X” option isn’t shown anymore (this is great but why was the “X” option shown in the first place”?)?Do you have a wordpress filter or could you had and option to chosse if outofstock items are to be considered or not?
Thanks
- The topic ‘In Stock as default, but not applied at page load’ is closed to new replies.