Commit f174ef7887a for woocommerce

commit f174ef7887ade1b23049f657c8df2ea284836be8
Author: Bero <1199991+bgrgicak@users.noreply.github.com>
Date:   Fri Oct 30 09:59:20 2026 +0100

    Add gallery images to shared product links (#70283)

    * Add gallery images to shared product links

    * Guard filtered gallery image IDs

diff --git a/plugins/woocommerce/changelog/add-open-graph-gallery b/plugins/woocommerce/changelog/add-open-graph-gallery
new file mode 100644
index 00000000000..705ac1a8975
--- /dev/null
+++ b/plugins/woocommerce/changelog/add-open-graph-gallery
@@ -0,0 +1,4 @@
+Significance: minor
+Type: add
+
+Include gallery images in shared product links and keep each image’s details together.
diff --git a/plugins/woocommerce/src/Internal/StructuredData/ProductOpenGraphTags.php b/plugins/woocommerce/src/Internal/StructuredData/ProductOpenGraphTags.php
index b1fc6224db7..de04cf4cc72 100644
--- a/plugins/woocommerce/src/Internal/StructuredData/ProductOpenGraphTags.php
+++ b/plugins/woocommerce/src/Internal/StructuredData/ProductOpenGraphTags.php
@@ -21,7 +21,7 @@ defined( 'ABSPATH' ) || exit;
 class ProductOpenGraphTags {

 	/**
-	 * Build metadata from the product and its featured image.
+	 * Build metadata from the product and its gallery images.
 	 *
 	 * @since 11.4.0
 	 *
@@ -43,11 +43,22 @@ class ProductOpenGraphTags {
 		foreach ( $this->get_site_tags() as $property => $value ) {
 			$tags[] = array( $property => $value );
 		}
-		$image = $this->get_image_tags( (int) $product->get_image_id(), $product->get_name() );
-		if ( $image ) {
-			$tags[] = $image;
+		$gallery   = $product->get_gallery_image_ids();
+		$image_ids = array_merge( array( $product->get_image_id() ), is_array( $gallery ) ? $gallery : array() );
+		$image_ids = array_slice( array_unique( array_filter( array_map( 'intval', $image_ids ) ) ), 0, 6 );
+		if ( ! empty( $image_ids ) ) {
+			// Prime caches to reduce future queries.
+			_prime_post_caches( $image_ids );
+		}
+		$urls = array();
+		foreach ( $image_ids as $image_id ) {
+			$image = $this->get_image_tags( $image_id, $product->get_name() );
+			if ( $image && ! in_array( $image['og:image'], $urls, true ) ) {
+				$tags[] = $image;
+				$urls[] = $image['og:image'];
+			}
 		}
-		$tags[] = array( 'twitter:card' => $image ? 'summary_large_image' : 'summary' );
+		$tags[] = array( 'twitter:card' => $urls ? 'summary_large_image' : 'summary' );

 		foreach ( wc_get_container()->get( ProductMediaSources::class )->get_sources( $product ) as $media => $source ) {
 			$root  = 'og:' . $media;