diff --git a/includes/api/class-wc-api-products.php b/includes/api/class-wc-api-products.php index 5a39d4f2327..bc183c7ca7a 100644 --- a/includes/api/class-wc-api-products.php +++ b/includes/api/class-wc-api-products.php @@ -1604,9 +1604,11 @@ class WC_API_Products extends WC_API_Resource { if ( is_wp_error( $upload ) ) { return new WP_Error( 'woocommerce_api_cannot_upload_product_image', $upload->get_error_message(), array( 'status' => 400 ) ); } - } - $gallery[] = $this->set_product_image_as_attachment( $upload, $id ); + $gallery[] = $this->set_product_image_as_attachment( $upload, $id ); + } else { + $gallery[] = $attachment_id; + } } }