@@ -76,7 +76,7 @@ public function prepare_object_for_response( $object, $request ) {
7676 ),
7777 'shipping_class ' => $ object ->get_shipping_class (),
7878 'shipping_class_id ' => $ object ->get_shipping_class_id (),
79- 'image ' => current ( $ this ->get_images ( $ object ) ),
79+ 'image ' => $ this ->get_image ( $ object ),
8080 'attributes ' => $ this ->get_attributes ( $ object ),
8181 'menu_order ' => $ object ->get_menu_order (),
8282 'meta_data ' => $ object ->get_meta_data (),
@@ -311,20 +311,24 @@ protected function prepare_object_for_database( $request, $creating = false ) {
311311 * @param WC_Product_Variation $variation Variation
312312 * @return array
313313 */
314- protected function get_images ( $ variation ) {
314+ protected function get_image ( $ variation ) {
315+ if ( ! has_post_thumbnail ( $ variation ->get_id () ) ) {
316+ return ;
317+ }
318+
315319 $ attachment_id = $ variation ->get_image_id ();
316320 $ attachment_post = get_post ( $ attachment_id );
317321 if ( is_null ( $ attachment_post ) ) {
318- $ image = array () ;
322+ return ;
319323 }
320324
321325 $ attachment = wp_get_attachment_image_src ( $ attachment_id , 'full ' );
322326 if ( ! is_array ( $ attachment ) ) {
323- $ image = array () ;
327+ return ;
324328 }
325329
326330 if ( ! isset ( $ image ) ) {
327- $ image = array (
331+ return array (
328332 'id ' => (int ) $ attachment_id ,
329333 'date_created ' => wc_rest_prepare_date_response ( $ attachment_post ->post_date , false ),
330334 'date_created_gmt ' => wc_rest_prepare_date_response ( strtotime ( $ attachment_post ->post_date_gmt ) ),
@@ -336,7 +340,7 @@ protected function get_images( $variation ) {
336340 );
337341 }
338342
339- return array ( $ image ) ;
343+ return ;
340344 }
341345
342346 /**
0 commit comments