Remove any product that is featured from regular display loop [WooCommerce]

I have set up a custom loop to display featured products at the top of their relevant category pages.

but now I would like to go about removing featured products from the regular loop below, which is using the standard woocommerce code to display products,

Any help would be greatly appreciated

http://onthesquareauctions.com/index.php/product-category/emporium/furniture/chairs-emporium/

Topic woocommerce-offtopic featured-post loop categories customization Wordpress

Category Web


I like Benoti answer and the other thing you can do is use woocommerce_product_query hook.

<?php

/**
 *  Add in your themes functions.php    
 *  Exclude featured product in the main product loop
 */
add_action( 'woocommerce_product_query', function ($query) {

    if ( ! is_admin() && $query->is_main_query() ) {
        // Not a query for an admin page.
        // It's the main query for a front end page of your site.

        if ( is_product_category() ) {
            // It's the main query for a product category archive.

            $tax_query = (array) $query->get( 'tax_query' );

            // Tax query to exclude featured product 
            $tax_query[] = array(
                'taxonomy' => 'product_visibility',
                'field'    => 'name',
                'terms'    => 'featured',
                'operator' => 'NOT IN', 
            );


            $query->set( 'tax_query', $tax_query );
        }

    }

} ); 

see my full notes on this topic https://jameshwartlopez.com/plugin/remove-any-product-that-is-featured-from-regular-display-loop/


Use the pre_get_posts filter to remove your sticked product from the product loop.

add_action( 'pre_get_posts', 'exclude_stycky_product' );

function exclude_sticky_product(){
    // target only the main query
    if ( ! is_admin() && $query->is_main_query()  ) {
         $query->set('ignore_sticky_posts');
         $query->set('meta_value', '1');
    }
}

Hope it helps you !

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.