skip to Main Content

I have added dropshaddow to product images in catalouge-pages. But i want to leave the products of the category “utility” out, so the pictures in this category do not have drop shaddow. (EDIT: so they don’t have dropshaddow even if they are shown in another category where they also belong)
This is what I have to add to all products:

.woocommerce ul.products li.product a img {
    box-shadow: 0 0 14px #aaa !important;
}

I’m trying to target the specific category:

.product-cat-utility ul.products li.product a img {
    box-shadow: 0 0 0 #aaa !important;
}

It does not work, and I am hoping for a more elegant solution.
Thanks.

2

Answers


  1. Chosen as BEST ANSWER

    For anyone searching, this seams to do the trick:

    .woocommerce ul.products li.product a img {
        box-shadow: 0 0 14px #aaa ;
    }
    
    .product_cat-utility img {
      box-shadow: 0 0 0px #aaa !important;
    } 
    

  2. The <body class="..."> on each category page contain unique classes, both the term id and term name

    Try something like this

    .woocommerce ul.products li.product a img {
        box-shadow: 0 0 14px #aaa !important;
    }
    
    .term-utility ul.products li.product a img, .myclass-utility ul.products li.product a img {
        box-shadow: 0 0 0 #aaa !important;
    }
    

    add a custom body class for term (parent) utility and the childs

    function my_body_classes( $classes ) {
        global $post;
    
        if ( is_product_category() ) {
            $term_slug = 'utility';
            $taxonomy  = 'product_cat';
            $term_id   = get_term_by( 'slug', $term_slug, $taxonomy )->term_id; // Get the term ID
            $child_ids = get_term_children( $term_id, $taxonomy ); // Get the children terms IDs
            $terms_ids = array_merge( $child_ids, [$term_id] ); // an array of all term IDs (main term Id and it's children)
    
            if ( has_term( $terms_ids, $taxonomy, $post->ID ) ) {
                $classes[] = 'myclass-utility';
            }
        }
    
        return $classes;  
    }
    add_filter( 'body_class','my_body_classes' );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search