Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I return only image src from "woocommerce_get_product_thumbnail()"?

echo woocommerce_get_product_thumbnail();

That output the whole image tag. How can I get only the image source?

Same problems solution with just WordPress: How do I get image url only on the_post_thumbnail

Is that possible with WooCommerce?

like image 482
Mahade Walid Avatar asked Dec 14 '22 02:12

Mahade Walid


2 Answers

Try to write your own code based on the function woocommerce_get_product_thumbnail() from wp-content/plugins/woocommerce/includes/wc-template-functions.php. For example:

function my_get_the_product_thumbnail_url( $size = 'shop_catalog' ) {
  global $post;
  $image_size = apply_filters( 'single_product_archive_thumbnail_size', $size );
  return get_the_post_thumbnail_url( $post->ID, $image_size );
}
like image 198
Gleb Kemarsky Avatar answered May 02 '23 13:05

Gleb Kemarsky


You can get the thumbnail of any post as such: $thumbnail = get_the_post_thumbnail_url($post->ID);

like image 27
Max Avatar answered May 02 '23 12:05

Max