PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

Setting In Stock filter to default to On

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

Hi
Is it possible, and if so how, to default the In Stock filter/switch to on?

Many thanks

Hello

Yes, it's possible to set the In Stock filter to be checked/enabled by default!

Solution

Add next code to your theme's functions.php file (child theme recommended):

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

How it works

This code uses the woof_get_request_data filter hook to automatically add stock=instock to the filter request data, making the In Stock checkbox checked by default when users land on your shop pages.

Where to add the code

  1. Recommended: Add to your child theme's functions.php file:
    • wp-content/themes/your-child-theme/functions.php
  2. Alternative: Use a plugin like"Code Snippets" to add the code safely

Important: Don't add this to the parent theme's functions.php as it will be overwritten when you update the theme!

This will make the In Stock filter active by default every time users visit your shop pages.

Also read: https://products-filter.com/manipulate-search-data-options/

Hi Alex

thanks for the instructions. They were clear, easy to follow and did what I asked.

BUT...

The changes force the filter to be on, so it can no longer be turned off.

Is it possible to have it default to In Stock but allow it to be switched to the other setting - I am not sure what to call the opposite of In Stock in this circumstance.

Regards
John