I'm working with the WooCommerce API I can't get the product image
product.php
stdClass Object
(
[id] => 11
[name] => Remera
......
)
[images] => Array
(
[0] => stdClass Object
(
[id] => 12
[date_created] => 2021-09-25T14:19:15
[date_created_gmt] => 2021-09-25T20:19:15
[date_modified] => 2021-09-25T14:19:15
[date_modified_gmt] => 2021-09-25T20:19:15
[src] => https://tiendawordpress/prueba/wp-content/uploads/2021/09/remera_azul_lisa_3.jpg
[name] => remera_azul_lisa_3
[alt] =>
)
)
I loop through the array
$product = $woocommerce->get('products/11');
//echo '<img src="'.$product->src.'">';
And this is the error I have
Notice: Undefined property: stdClass::$src in ... product.php on line 35
UPDATED
echo $product->images['src'];
I made a change to get the image but the error now is that it is not definedsrc
Notice: Undefined index: src in
I appreciate the help in advance!
How do you loop through the array? There's the answer.
You have to traverse the array of
images
to get to the image that is insrc
. The same with the rest.Kisses