Ivan Cherepukhin
Ivan Cherepukhin

Reputation: 1

WooCommerce: exclude recent products from all products

I want to show a number of recent products and than all other without those in recent.

I know that it's possible to do with posts in Wordpress by using 'offset' but I have no idea what to do with Woocommerce.

Any idea how to exclude first N products from all of them?

Upvotes: 0

Views: 311

Answers (1)

Ewout
Ewout

Reputation: 2478

you can modify the query via pre_get_posts and then simply set the offset.

add_action( 'pre_get_posts', 'custom_pre_get_posts_query' );

function custom_pre_get_posts_query( $q ) {

    if ( ! $q->is_main_query() ) return;
    if ( ! $q->is_post_type_archive() ) return;

    if ( ! is_admin() ) {
        $q->set( 'offset', 5);
    }

    remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );

}

(based on this snippet)

Upvotes: 1

Related Questions