Adding CSS to Product Category Woocommerce WordPress

function myClock( $classes ) {
global $post;

if ( is_product_category() ) {
$term_slug = ‘clocks’;
$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[] = ‘.product-thumb-hover’;
}
}
return $classes;
}
add_filter( ‘body_class’,’myClock’ );

————————

CSS:

.product-thumb-hover
{
top:-60px;
}

Comments are closed.

Freelance Web Designer | Web Design | WordPress | Hong Kong