Search code examples
woocommerceproduct

Woocommerce - Only show grouped products parent in the loop


I'm building a store for books. I have a bunch of grouped products. My pain is, that woocommerce lists both type by default. I only need the parent of the group to be listed without childrens.

Is there any hook or workaround for this?

Thanks.


Solution

  • Try the following:

    add_action( 'woocommerce_product_query', 'so_27975262_product_query' );
    
    function so_27975262_product_query( $q ){
        $q->set( 'post_parent', 0 );
    }
    

    The idea is that we're modifying the query such that it will only show top-level items.... thus (in theory) nothing that has been assigned to a group, which would then have the group product's ID as the post_parent.