How to get 2nd or 3rd image of woocommerce image gallary with [shortcode]

Question

I am using following code to view the first image of woo-commerce product images with the shortcode of [product_first_img]

function gal_first_shortcode( $atts, $content = null ) {
    extract( shortcode_atts( array('size' => ''), $atts ) );
    $image_size = 'medium';
    if($size =! '') { $image_size = $size; }
    $images = get_children(array(
    'post_parent' => get_the_ID(),
    'post_type' => 'attachment',
    'numberposts' => 1,
    'post_mime_type' => 'image',
    'orderby' => 'menu_order',
    //'exclude' => get_post_thumbnail_id()));

    if($images) {
    $gallery = '';
    foreach( $images as $image ) {
        $gallery .= wp_get_attachment_image($image->ID, $image_size);
    }
    $gallery .= '';
    return $gallery;
    }
    }

    add_shortcode('product_first_img', 'gal_first_shortcode');

Now, The problem is that I can get only the first image. What should I need to do if I want to get 2nd or thrid image through [shortcode]? I am not a developer. I will appreciate your help 🙂

--------------------------------------------------

>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/how-to-get-2nd-or-3rd-image-of-woocommerce-image-gallary-with-shortcode/">

How to get 2nd or 3rd image of woocommerce image gallary with [shortcode]</a>
0
, , user188572 1 week 0 Answers 19 views 0

Leave an answer