Answer the question
In order to leave comments, you need to log in
How to crop thumbnails based on category?
Let's say I registered a new thumbnail:
add_image_size( 'cart_thumbnail_all', 70, 70, true );
$thumbnail_url = wp_get_attachment_image_src( get_post_thumbnail_id( $_product->get_id() ), 'cart_thumbnail_all', true);
$terms_cats = get_the_terms( $_product->get_id(), 'product_cat' );
$terms_cat_slug = [];
foreach ( $terms_cats as $terms_cat ) {
array_push($terms_cat_slug, $terms_cat->slug);
}
if ( in_array( 'obuv', $terms_cat_slug ) ) {
$crop = true;
} else {
$crop = false;
}
add_image_size( 'cart_thumbnail', 70, 45, $crop );
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question