G
G
Genri_Rus2020-01-22 23:53:23
WordPress
Genri_Rus, 2020-01-22 23:53:23

How to crop thumbnails based on category?

Let's say I registered a new thumbnail:

add_image_size( 'cart_thumbnail_all', 70, 70, true );

Can I somehow crop not all the thumbnails in the basket?
$thumbnail_url = wp_get_attachment_image_src( get_post_thumbnail_id( $_product->get_id() ), 'cart_thumbnail_all', true);

Let's say it's somehow possible?
$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 );

But I don't want to work

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question