Site icon Hip-Hop Website Design and Development

WordPress WooCommerce Recent Products Exclude Hidden Products [closed]

I’m trying to exclude a hidden product from the WooCommerce recent products shortcode by writing the following php code using a code snippet plugin but the empty product box still appears. Basically I was able to hide a product but recent products is still displaying an empty area of where the product used to be instead of replacing it with the next recent product. Here is my code but it seems to not be working.

function exclude_hidden_product( $should_index, $id ) {
    $product_id_to_exclude = array(9872);
    
    if (in_array($id,$product_id_to_hide) && !empty(wc_memberships_get_user_active_memberships())) {
        $should_index = false;
    }
    return $should_index;
}
add_filter( 'storefront_homepage_after_recent_products','exclude_hidden_product', 10, 2);

Could you guide me to the correct direction in how to exlucde a certain product on my WooCommerce webpage?

Thanks.