0
votes

In my WooCommerce store, I have "Hide out of stock items from the catalogue" enabled. This option causes product variations on individual pages to become invisible.

I want to apply "Hide out of stock items from the catalogue" option only on archive pages (search, categories).

Here is my code:

function featured_posts( $query ) {
    if ( ! $query->is_main_query() ) return;

    //What goes in here?
}
add_action( 'pre_get_posts', 'featured_posts' );

How can I achieve this?

Thanks

1

1 Answers

0
votes

Try This

You have to check page for do this as follow

function featured_posts( $query ) {

    if(is_product_category() || is_search()){
        if ( ! $query->is_main_query() ){
            return;
        }
    }
    ....
}
add_action( 'pre_get_posts', 'featured_posts' );