Cobyfoster99
Cobyfoster99

Reputation: 55

Woocommerce PHP - Add product image to the page

I hope this isn't to vague. Please ask if you need more info.

I am creating a custom WooCommerce product page from scratch using WooCommerce's hooks. I am trying to include the product images using this

<?php do_action( 'woocommerce_product_thumbnails' );?>

I've found online that it has been discontinued, does anyone know how to include product images now? Note, I am looking for the main image, not the gallery.

Thanks in advance, again, let me know if you need more info.

Upvotes: 0

Views: 176

Answers (1)

Terminator-Barbapapa
Terminator-Barbapapa

Reputation: 3126

You can retrieve the main product thumbnail by getting the image_id from the product object and use it in the wp_get_attachment_image() function:

wp_get_attachment_image( $product->get_image_id() )

More information on the arguments you can pass to this function here: https://developer.wordpress.org/reference/functions/wp_get_attachment_image/

Upvotes: 1

Related Questions