J
J
JyriG2019-09-03 13:03:59
WordPress
JyriG, 2019-09-03 13:03:59

How to display the first photo in woocommerce outside the slider?

Hi all!
How to display the first photo of a product from a wordpress array?

<?php
                                $product_id = get_the_ID();
                                $product = new WC_product($product_id);
                                $attachment_ids = $product->get_gallery_attachment_ids();

                                foreach($attachment_ids as $attachment_id){
                                    echo '<div class="slide w-slide product__slider_modalbtn" style="background-image: url('.wp_get_attachment_url($attachment_id).');"></div>';
                                }
                            ?>

Here is the original code, but it displays all the photos of the product, and I need the first/second/third/etc photo. How to change the code so that it outputs the first one and so on. a photo of the product (if there is one, of course)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Gvozdev, 2019-09-03
@arty23_03

'offset' => 1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question