1

I would like to add a custom CSS when displaying product images. E.g. when calling the woocommerce_get_product_thumbnail function.

I've tried solutions like this: Add CSS class to every image but they don't work. The class only gets added to images that are not related to products.

1

1 Answer 1

1

If it's still relevant, you can add a class to the product thumbnail the following way.

function loop_product_custom_thumbnail() {
  echo the_post_thumbnail('thumbnail', array('class' => 'your-class-name'));
}
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10);
add_action( 'woocommerce_before_shop_loop_item_title', 'loop_product_custom_thumbnail', 10 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.