Search code examples
wordpresswoocommercethumbnailshook-woocommerce

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?


Solution

  • 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 );
    }