M
M
Max Brilliant2020-08-20 18:17:06
WordPress
Max Brilliant, 2020-08-20 18:17:06

How to display Woocommerce product gallery?

Good day. Tell me a php script that displays a WooCommerce product gallery. I added 3 photos and I need to display exactly 3 photos, without any attributes that the wokomerz itself creates. I've searched all over the Internet, I've been looking for half a day. There's no such thing. If it displays, it displays pictures as links, a bunch of divs, 200 classes of pieces. I don’t need it like that. Just display 3 pictures that I added to the gallery, I will define them myself in my own script. Thank you!
5f3e955f79d7b560083155.png
The screenshot shows that a bunch of garbage displays

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
its2easyy, 2020-08-20
@its2easyy

Something like this

global $product;

$attachment_ids = $product->get_gallery_image_ids();

foreach ( $attachment_ids as $attachment_id ) {
    $full_src          = wp_get_attachment_image_src( $attachment_id, 'full' );
    echo "<img src='" .full_src[0] ."'>
}

wp_get_attachment_image_src can be replaced with any function that gets information about the image by id

M
Max Brilliant, 2020-08-20
@brilliantmaksim

ok, it worked, but something went wrong5f3e9db886d6a160214998.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question