O
O
Oviplokos2020-05-19 14:05:40
WordPress
Oviplokos, 2020-05-19 14:05:40

How to hide certain attributes only in the product catalog?

Is it possible to hide some attributes only in the product catalog? Suppose I need to display only the size and material in the catalog, and +8 more attributes inside on the product page? It's just that now there is an opportunity to hide attributes with a function

spoiler
function devise_hide_attributes_from_additional_info_tabs( $attributes, $product ) {
    $hidden_attributes = [
        'pa_network',
        'pa_merchant',
        'pa_brand',
    ];
    foreach ( $hidden_attributes as $hidden_attribute ) {
        if ( ! isset( $attributes[ $hidden_attribute ] ) ) {
            continue;
        }
        $attribute = $attributes[ $hidden_attribute ];
        $attribute->set_visible( false );
    }
    return $attributes;
}
add_filter( 'woocommerce_product_get_attributes', 'devise_hide_attributes_from_additional_info_tabs', 20, 2 );

But then the attributes disappear both from the catalog and from the product card, but it is necessary that they be removed only from the catalog. Can this be implemented in some other way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Litvinenko, 2020-05-19
@Oviplokos

Do a check on the catalog page via is_shop()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question