I want to export the image links of my products in different columns. For example like IMG1 IMG2 IMG3.
So i wrote this code below (Not Worked):
foreach( $articles as $key => $article ) {
if ( array_key_exists( 'ID', $article ) ) {
$i = 1;
$product = wc_get_product( $article['ID'] );
if ( ! empty( $product ) ) {
$featured_img = wp_get_attachment_url( $product->get_image_id() );
if ( ! empty( $featured_img ) ) {
$articles[ $key ]['Image ' . $i] = $featured_img;
}
$other_imgs = $product->get_gallery_image_ids();
if ( ! empty( $other_imgs ) ) {
foreach ( $other_imgs as $id ) {
$i++;
$img = wp_get_attachment_url( $id );
$articles[ $key ]['Image ' . $i] = $img;
UPDATE
Code returns null
Pass the
$product
to the function and it will return the images of the product as an array.