Add
<?php
add_filter( 'woocommerce_api_product_response', function( $product_data, $product, $fields, $server ) {
if($latin_name = get_field('latin_name', $product)) {
$product_data['latin_name'] = $latin_name;
}
if($image_without_watermark = get_field('image_without_watermark', $product)) {
$product_data['image_without_watermark'] = $image_without_watermark;
}
if(isset($product_data['featured_src'])) {
$product_data['featured_src'] = wp_get_attachment_image_src( get_post_thumbnail_id( $product->get_id() ), 'suiteseven_shopping' );
}
return $product_data;
}, 4, 10);
add_filter("woocommerce_rest_prepare_product_object", function( $response, $post, $request ) {
global $_wp_additional_image_sizes;
if (empty($response->data)) {
return $response;
}
foreach ($response->data['images'] as $key => $image) {
$image_urls = [];
foreach ($_wp_additional_image_sizes as $size => $value) {
$image_info = wp_get_attachment_image_src($image['id'], $size);
$response->data['images'][$key][$size] = $image_info[0];
}
}
$response->data['meta_data'][] = [
'id' => 9999,
'key' => 'featured_image_url',
'value' => wp_get_attachment_image_src( get_post_thumbnail_id( $post->get_id() ), 'suiteseven_shopping' )[0]
];
$attachment_ids = $post->get_gallery_image_ids();
$gallery = [];
foreach($attachment_ids as $id) {
$gallery[$id] = wp_get_attachment_image_src( $id , 'suiteseven_shopping' )[0];
}
if(!empty($gallery)) {
$response->data['meta_data'][] = [
'id' => 99999,
'key' => 'featured_image_urls',
'value' => array_values($gallery)
];
}
return $response;
}, 99999999999, 3);
add_filter("woocommerce_rest_prepare_product_variation_object", function( $response, $variation, $request ) {
$attachment_id = 0;
if($variation->get_image_id()) {
$attachment_id = $variation->get_image_id();
} else {
$attachment_id = get_post_thumbnail_id( $variation->get_parent_id() );
}
if($attachment_id) {
$response->data['meta_data'][] = [
'id' => 9999,
'key' => 'featured_image_url',
'value' => wp_get_attachment_image_src( $attachment_id , 'suiteseven_shopping' )[0]
];
if($post_id = $variation->get_parent_id()) {
$post = wc_get_product($post_id);
$attachment_ids = $post->get_gallery_image_ids();
$gallery = [];
foreach($attachment_ids as $id) {
$gallery[$id] = wp_get_attachment_image_src( $id , 'suiteseven_shopping' )[0];
}
$thumb_id = get_post_thumbnail_id( $post->get_id() );
$gallery[$thumb_id] = wp_get_attachment_image_src( $thumb_id , 'suiteseven_shopping' )[0];
if(isset($gallery[$attachment_id])) {
unset($gallery[$attachment_id]);
}
if(!empty($gallery)) {
$response->data['meta_data'][] = [
'id' => 99999,
'key' => 'featured_image_urls',
'value' => array_values($gallery)
];
}
}
}
return $response;
}, 99999999999, 3);