Hide out of stock variations when filtering
-
This issue still exists till now (((.. and there is no universal solution.
Does anyone know how to fix it?
-
Hi @zimmerx
If I understand it correctly, you want to hide the out of stock products from WooCommerce core filters in the widget section.
Please confirm if you’ve enabled the “Hide out of stock items from the catalog” in WooCommerce > Settings > Products > Inventory. It should look like this:
Link to image: https://d.pr/i/bcRjYOIf you’ve already done that and if the behavior still exists, could you please share a copy of your site’s System Status to understand how your site is configured? You can find it via WooCommerce > Status. Select “Get system report” and then “Copy for support”.? Once you’ve done that, paste it here in your response.
Also please share with us an example on your site, that we can test from our end.
Thanks
Hi @tibetanitech
Thank you for your feedback.Yeah, you got me right, and I confirm that enabled the “Hide out of stock items from the catalog”.
Please review the status report bellow:
### WordPress Environment ### WordPress address (URL): https://zapatero.ge Site address (URL): https://zapatero.ge WC Version: 5.2.2 REST API Version: ? 5.2.2 WC Blocks Version: ? 4.7.2 Action Scheduler Version: ? 3.1.6 WC Admin Version: ? 2.1.5 Log Directory Writable: ? WP Version: 5.7.1 WP Multisite: – WP Memory Limit: 256 MB WP Debug Mode: – WP Cron: ? Language: ka_GE External object cache: – ### Server Environment ### Server Info: Apache PHP Version: 7.4.16 PHP Post Max Size: 50 MB PHP Time Limit: 300 PHP Max Input Vars: 1000 cURL Version: 7.64.1 OpenSSL/1.0.2r SUHOSIN Installed: – MySQL Version: 5.5.5-10.3.22-MariaDB-log Max Upload Size: 50 MB Default Timezone is UTC: ? fsockopen/cURL: ? SoapClient: ? DOMDocument: ? GZip: ? Multibyte String: ? Remote Post: ? Remote Get: ? ### Database ### WC Database Version: 5.0.0 WC Database Prefix: zp_ Total Database Size: 183.17MB Database Data Size: 125.66MB Database Index Size: 57.51MB zp_woocommerce_sessions: Data: 0.19MB + Index: 0.02MB + Engine InnoDB zp_woocommerce_api_keys: Data: 0.02MB + Index: 0.03MB + Engine InnoDB zp_woocommerce_attribute_taxonomies: Data: 0.02MB + Index: 0.02MB + Engine InnoDB zp_woocommerce_downloadable_product_permissions: Data: 0.02MB + Index: 0.06MB + Engine InnoDB zp_woocommerce_order_items: Data: 0.11MB + Index: 0.05MB + Engine InnoDB zp_woocommerce_order_itemmeta: Data: 1.52MB + Index: 0.66MB + Engine InnoDB zp_woocommerce_tax_rates: Data: 0.02MB + Index: 0.06MB + Engine InnoDB zp_woocommerce_tax_rate_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB zp_woocommerce_shipping_zones: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_woocommerce_shipping_zone_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB zp_woocommerce_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_woocommerce_payment_tokens: Data: 0.02MB + Index: 0.02MB + Engine InnoDB zp_woocommerce_payment_tokenmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB zp_woocommerce_log: Data: 0.02MB + Index: 0.02MB + Engine InnoDB zp_actionscheduler_actions: Data: 3.03MB + Index: 1.77MB + Engine InnoDB zp_actionscheduler_claims: Data: 0.02MB + Index: 0.02MB + Engine InnoDB zp_actionscheduler_groups: Data: 0.02MB + Index: 0.02MB + Engine InnoDB zp_actionscheduler_logs: Data: 2.03MB + Index: 1.95MB + Engine InnoDB zp_admin_columns: Data: 0.02MB + Index: 0.02MB + Engine InnoDB zp_commentmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB zp_comments: Data: 1.52MB + Index: 0.41MB + Engine InnoDB zp_imagify_files: Data: 0.02MB + Index: 0.08MB + Engine InnoDB zp_imagify_folders: Data: 0.02MB + Index: 0.03MB + Engine InnoDB zp_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB zp_mailchimp_carts: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_mailchimp_jobs: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_options: Data: 16.03MB + Index: 2.27MB + Engine InnoDB zp_pmxi_files: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_pmxi_hash: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_pmxi_history: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_pmxi_images: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_pmxi_imports: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_pmxi_posts: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_pmxi_templates: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_postmeta: Data: 78.25MB + Index: 33.59MB + Engine InnoDB zp_posts: Data: 11.27MB + Index: 7.25MB + Engine InnoDB zp_termmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB zp_terms: Data: 0.02MB + Index: 0.03MB + Engine InnoDB zp_term_relationships: Data: 5.23MB + Index: 2.27MB + Engine InnoDB zp_term_taxonomy: Data: 0.02MB + Index: 0.03MB + Engine InnoDB zp_usermeta: Data: 1.47MB + Index: 0.84MB + Engine InnoDB zp_users: Data: 0.09MB + Index: 0.08MB + Engine InnoDB zp_wc_admin_notes: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_wc_admin_note_actions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB zp_wc_category_lookup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_wc_customer_lookup: Data: 0.11MB + Index: 0.06MB + Engine InnoDB zp_wc_download_log: Data: 0.02MB + Index: 0.03MB + Engine InnoDB zp_wc_order_coupon_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB zp_wc_order_product_lookup: Data: 0.11MB + Index: 0.06MB + Engine InnoDB zp_wc_order_stats: Data: 0.09MB + Index: 0.05MB + Engine InnoDB zp_wc_order_tax_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB zp_wc_product_meta_lookup: Data: 3.28MB + Index: 5.03MB + Engine InnoDB zp_wc_reserved_stock: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_wc_tax_rate_classes: Data: 0.02MB + Index: 0.02MB + Engine InnoDB zp_wc_webhooks: Data: 0.02MB + Index: 0.02MB + Engine InnoDB zp_wdr_order_discounts: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_wdr_order_item_discounts: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_wdr_rules: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_wfblockediplog: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_wfblocks7: Data: 0.02MB + Index: 0.05MB + Engine InnoDB zp_wfconfig: Data: 0.09MB + Index: 0.00MB + Engine InnoDB zp_wfcrawlers: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_wffilechanges: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_wffilemods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_wfhits: Data: 0.02MB + Index: 0.05MB + Engine InnoDB zp_wfhoover: Data: 0.02MB + Index: 0.02MB + Engine InnoDB zp_wfissues: Data: 0.02MB + Index: 0.06MB + Engine InnoDB zp_wfknownfilelist: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_wflivetraffichuman: Data: 0.02MB + Index: 0.02MB + Engine InnoDB zp_wflocs: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_wflogins: Data: 0.02MB + Index: 0.03MB + Engine InnoDB zp_wfls_2fa_secrets: Data: 0.02MB + Index: 0.02MB + Engine InnoDB zp_wfls_settings: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_wfnotifications: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_wfpendingissues: Data: 0.02MB + Index: 0.06MB + Engine InnoDB zp_wfreversecache: Data: 0.02MB + Index: 0.00MB + Engine InnoDB zp_wfsnipcache: Data: 0.02MB + Index: 0.05MB + Engine InnoDB zp_wfstatus: Data: 0.02MB + Index: 0.03MB + Engine InnoDB zp_wftrafficrates: Data: 0.02MB + Index: 0.00MB + Engine InnoDB ### Post Type Counts ### attachment: 13440 custom_css: 1 elementor_library: 1 etheme_portfolio: 12 mc4wp-form: 1 nav_menu_item: 72 page: 16 product: 2454 product_variation: 11427 shop_order: 603 shop_order_refund: 13 staticblocks: 8 testimonials: 3 wpcf7_contact_form: 2 ### Security ### Secure connection (HTTPS): ? Hide errors from visitors: ? ### Active Plugins (19) ### Query Monitor: by John Blackbourn – 3.6.7 Change wp-admin login: by Nuno Morais Sarmento – 1.0.6 Contact Form 7: by Takayuki Miyoshi – 5.4 Elementor: by Elementor.com – 3.1.4 XStore Core: by 8theme – 3.2.7 Facebook for WooCommerce: by Facebook – 2.3.5 Imagify: by WP Media – 1.9.14 Insert Headers and Footers: by WPBeginner – 1.5.0 Loco Translate: by Tim Whitlock – 2.5.2 MC4WP: Mailchimp for WordPress: by ibericode – 4.8.3 Facebook for WordPress: by Facebook – 3.0.5 WooCommerce BOG Credit Card Payment Gateway: by Plug and Pay Ltd. – 2.1.2 Terms and Conditions Popup for WooCommerce: by BeRocket – 3.5.3 Transients Manager: by Pippin Williamson – 1.8.1 WC Fix Attributes: by Tofandel – 1.0 Woo Discount Rules: by Flycart – 2.3.5 WooCommerce Checkout Field Editor: by WooCommerce – 1.5.27 WooCommerce: by Automattic – 5.2.2 WP Rocket: by WP Media – 3.8.8 ### Inactive Plugins (0) ### ### Dropin Plugins (1) ### advanced-cache.php: advanced-cache.php ### Settings ### API Enabled: ? Force SSL: ? Currency: GEL (?) Currency Position: left Thousand Separator: , Decimal Separator: . Number of Decimals: 2 Taxonomies: Product Types: external (external) grouped (grouped) simple (simple) variable (variable) Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog) exclude-from-search (exclude-from-search) featured (featured) outofstock (outofstock) rated-1 (rated-1) rated-2 (rated-2) rated-3 (rated-3) rated-4 (rated-4) rated-5 (rated-5) Connected to WooCommerce.com: – ### WC Pages ### Shop base: #11 - / Cart: #12 - /cart/ Checkout: #7 - /checkout/ My account: #13 - /my-account/ Terms and conditions: #3 - /privacy-policy/ ### Theme ### Name: Zapatero Version: 1.0 Author URL: https://8theme.com Child Theme: ? Parent Theme Name: XStore Parent Theme Version: 7.2.7 Parent Theme Author URL: https://www.8theme.com WooCommerce Support: ? ### Templates ### Overrides: xstore/woocommerce/archive-product.php xstore/woocommerce/cart/cart-empty.php xstore/woocommerce/cart/cart-item-data.php xstore/woocommerce/cart/cart-shipping.php xstore/woocommerce/cart/cart.php xstore/woocommerce/cart/cross-sells.php xstore/woocommerce/cart/mini-cart.php xstore/woocommerce/checkout/form-billing.php xstore/woocommerce/checkout/form-checkout.php xstore/woocommerce/checkout/form-shipping.php xstore/woocommerce/checkout/thankyou.php xstore/woocommerce/content-product-cat.php xstore/woocommerce/content-product.php xstore/woocommerce/content-single-product.php xstore/woocommerce/content-widget-product.php xstore/woocommerce/content-widget-reviews.php xstore/woocommerce/global/breadcrumb.php xstore/woocommerce/global/form-login.php xstore/woocommerce/global/wrapper-end.php xstore/woocommerce/global/wrapper-start.php xstore/woocommerce/loop/loop-end.php xstore/woocommerce/loop/loop-start.php xstore/woocommerce/loop/no-products-found.php xstore/woocommerce/loop/result-count.php xstore/woocommerce/myaccount/dashboard.php xstore/woocommerce/myaccount/form-login.php xstore/woocommerce/myaccount/navigation.php xstore/woocommerce/single-product/add-to-cart/simple.php xstore/woocommerce/single-product/meta.php xstore/woocommerce/single-product/product-image.php xstore/woocommerce/single-product/related.php xstore/woocommerce/single-product/tabs/tabs.php xstore/woocommerce/single-product/title.php xstore/woocommerce/single-product/up-sells.php xstore/woocommerce/single-product.php ### Action Scheduler ### Complete: 7,959 Oldest: 2021-03-27 15:09:42 +0000 Newest: 2021-04-27 06:47:57 +0000 Failed: 30 Oldest: 2020-05-05 11:49:36 +0000 Newest: 2020-05-20 21:26:38 +0000 ### Status report information ### Generated at: 2021-04-27 10:54:12 +04:00
Here is the link of the website:
https://zapatero.ge/page/10/?filter_gender=%E1%83%99%E1%83%90%E1%83%AA%E1%83%98&filter_size=45Sorry for the speed, it’s super slow now ??
as you can see I’ve filtered it with men size 45 and on page 10 you can still see the products which don’t have size 45 in stock but they are on the filtered page.
So, I found out that those products which can be found still have size 45 in attributes but not in variations due to out of stock. and seems this point was missed and now we have a lot of products which such problems.
I’ve tried to use this code :
add_action('woocommerce_before_shop_loop_item', 'out_of_stock_variations_loop'); function out_of_stock_variations_loop() { global $product; $filter = 'size'; if ($product->product_type === 'variable') { $available = $product->get_available_variations(); if ($available) { foreach ($available as $instockvar) { if (isset($instockvar[ 'attributes' ][ 'attribute_pa_' . $filter ])) { if ($_GET[ 'filter_' . $filter ]) { if ( !in_array( $instockvar[ 'attributes' ][ 'attribute_pa_' . $filter ], explode(',', $_GET[ 'filter_' . $filter ]) , true ) || ($instockvar[ 'max_qty' ] <= 0) ) { echo "<style>.post-" . $product->get_id() . " {display: none}</style>"; } else { echo "<style>.post-" . $product->get_id() . " {display: list-item !important}</style>"; } } } } } } }
but after that you should work with layout and change a lot of things, also I don’t think that it’s the right way to do modifications.
Thank you.
Hello @zimmerx,
By default, the
Hide out of stock item from catalog
option only hides the products from the shop page. It is not meant to work for the filtering.It would be great to have you add your ideas to the Ideas Board, which is where developers go to look for future plugin features and improvements.
Also, I’m going to mark this as resolved – if you have any further questions, you can start a new thread.
Thanks!
- The topic ‘Hide out of stock variations when filtering’ is closed to new replies.