Support » Plugin: OnSale Page for WooCommerce » Filter Out of Stock?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author wpgenie2

    (@wpgenie2)

    Hm, they shouldn’t appear there unless you set “show out of stock” items in catalog settings in Woocommerce settings.

    I may be asking for too much…

    Yes, I want to show products that are out of stock in the rest of the store to allow customers to add them to a Waitlist – so the “Show Out of Stock” items is enabled.

    For items that are on-sale I don’t want to show those that are out of stock because they may not be on-sale when inventory returns – don’t want customers to Waitlist something that’s on-sale but out of stock.

    …the reason for doing it within the plug-in is because inventory availability and on-sale status is set nightly during a scheduled import. With over 7,000 items it’s not possible/feasible to go back and do manual corrections to the product catalog (slow and labor intense) – having the On Sale list filtered would make it automatic.

    …still love the plug in, just gotta figure out a way around this kink.

    Plugin Author wpgenie2

    (@wpgenie2)

    You can add code below to functions.php

    add_filter('woocommerce_product_query_meta_query' , 'hide_outofstock_from_sale_page',10,2);
    function hide_outofstock_from_sale_page($meta_query,$q){
     global $wp_query;
     if(isset($wp_query->is_sale_page) && $wp_query->is_sale_page === true ){
     $meta_query['stock_status']  = array(
       'key'   => '_stock_status',
       'value'  => 'instock',
       'compare'  => '=');
     }
     return $meta_query;
    
    }

    Hmm… Almost – I think.

    As described, it didn’t work – products that were listed as “Out of Stock” still appeared in the On-Sale page.

    This may become suddenly more complicated;
    A product that appears on the On Sale page, but also showing the “Out of Stock” badge shows the following in it’s Product Details;
    Regular price: <some value>
    Sale price: <some lower value>
    Manage Stock: <enabled>
    Stock quantity: 0
    Stock status: ‘In Stock’ *See note

    In your sample code it looks like you may be looking at the field ‘stock_status’..which in this case is not a good field to look at. I tried changing things around a little to to work with the ‘Stock quantity’ without success..but that’s mostly because I don’t know what I am doing.

    Your help thus far is much appreciated.

    NOTE: The fact that the Stock Status and the Stock Quantity fields don’t reflect themselves is do to the nightly import I mentioned. Apparently my import script is jamming a Stock quantity value but not also updating the Stock Status. Odd, though, because the product used in my example can’t be purchased because WC really does believe it to be out of stock.

    Success!

    I tweaked the fields being compared as follows

    add_filter('woocommerce_product_query_meta_query' , 'hide_outofstock_from_sale_page',10,2);
    function hide_outofstock_from_sale_page($meta_query,$q){
     global $wp_query;
     if(isset($wp_query->is_sale_page) && $wp_query->is_sale_page === true ){
     $meta_query['stock']  = array(
       'key'   => '_stock',
       'value'  => '0',
       'compare'  => '>');
     }
     return $meta_query;
    }

    And now it only display products with a Stock quantity greater than 0.

    Thanks!

    …pffft.

    Just when I thought things were awesome: Your “On-Sale Page” works perfect, and even better after the tweak to consider the value of stock quantity ( _stock), but…

    I use a side-bar that has navigation for Category, Brand, etc. And although your On-Sale Page shows only the applicable brands, categories, etc based on the found set of on-sale items(it even counts the correct number of records for each on-sale brand, category, etc) as soon as you click on a brand, or category, or etc you immediately lose the ‘On-Sale’-ness…you end up on a page with the entire product set of whatever brand, category or etc you clicked on.

    This shouldn’t be this hard.

    Plugin Author wpgenie2

    (@wpgenie2)

    Hm, don’t know why is that, because that function above should run only on on-sale page and modify query there.

    Plugin Author wpgenie2

    (@wpgenie2)

    closing old topic

    Plugin Author wpgenie2

    (@wpgenie2)

    Closing topic

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.