Home » Php » php – Woocommerce remove programmatically product from shop loop and attributes from shop filters

php – Woocommerce remove programmatically product from shop loop and attributes from shop filters

Posted by: admin February 25, 2020 Leave a comment

Questions:

I have one issue on woocommerce.
I have to remove programmatically two product from shop page.
Based on Woocommerce API i used this code to remove one product. The product is successfully removed, but on attribute filters there is his attribute

add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );
function custom_pre_get_posts_query( $q ) {    
    $q->set( 'post__not_in', array('43') );
}

How i can remove his attribute from filters too?

Thanks

How to&Answers: