skip to Main Content

I want to make a filter by attribute for variable products but the problem is that the filter shows out of stock product, and I have to hide the out of stock products checked, but it didn’t solve the issue, thanks in advance

2

Answers


  1. Chosen as BEST ANSWER

    I am using WOOF product filter plugin, so i found that i need to put this code in functions.php to only get in stock products filter

    add_filter('woof_get_request_data', 'my_woof_get_request_data');
    
    function my_woof_get_request_data($data){
        $data['stock']='instock';
        return $data;
    }
    

  2. This is standard woocommerce functionality, it shows “out of stock” products on the shop page, in the woocommerce widgets, everywhere.

    Only on the product single is “Out of stock” shown instead of an “Add to cart”.

    1. Go to Woocommerce → Settings and click the Products tab

    2. Click the Inventory link at the top

    3. Check the Out Of Stock Visibility option to hide out of stock items

    If above option is already checked. Please try below code in your functions.php file of current theme.

    function check_variation_is_active( $active, $variation ) {
      if( ! $variation->is_in_stock() ) {
         return false;
      }
      return $active;
    }
    add_filter( 'woocommerce_variation_is_active','check_variation_is_active', 10, 2 );
    

    I hope it will help you.
    Thanks

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search