0
votes

I'm trying to hide the related products on single product pages in a category (using Woocommerce). This is what I have so far, and it hides related products on ALL categories:

function wc_remove_related_products( $args )
{
    if (is_product() && has_term( 'Donations', 'product_cat'))
    {
        return array();
    }
}
add_filter('woocommerce_related_products_args','wc_remove_related_products', 10);
2

2 Answers

3
votes

I believe you need to return the original, supplied $args if your conditional isn't true:

function wc_remove_related_products( $args )
{
    if (is_product() && has_term( 'Donations', 'product_cat'))
    {
        return array();
    } 

    return $args;
}
add_filter('woocommerce_related_products_args','wc_remove_related_products', 10);
0
votes

Do it like this:

function wc_remove_related_products( $args ) {
    return array();
}
add_filter('woocommerce_related_products_args','wc_remove_related_products', 10);