Commit 677187eb9fc for woocommerce

commit 677187eb9fccc1fba2f701a90eb9e5aa6833d69a
Author: Bero <1199991+bgrgicak@users.noreply.github.com>
Date:   Fri Oct 30 11:47:04 2026 +0100

    Add brands and ratings to shared product links (#70282)

    * Add brands and ratings to shared product links

    * Rerun checks against trunk

diff --git a/plugins/woocommerce/changelog/add-open-graph-product-details b/plugins/woocommerce/changelog/add-open-graph-product-details
new file mode 100644
index 00000000000..fa3cae06718
--- /dev/null
+++ b/plugins/woocommerce/changelog/add-open-graph-product-details
@@ -0,0 +1,4 @@
+Significance: minor
+Type: add
+
+Include brands and ratings in shared product links.
diff --git a/plugins/woocommerce/src/Internal/StructuredData/OpenGraphMarkup.php b/plugins/woocommerce/src/Internal/StructuredData/OpenGraphMarkup.php
index 69cfabe2774..255801ccab8 100644
--- a/plugins/woocommerce/src/Internal/StructuredData/OpenGraphMarkup.php
+++ b/plugins/woocommerce/src/Internal/StructuredData/OpenGraphMarkup.php
@@ -72,6 +72,14 @@ class OpenGraphMarkup {
 				'match'  => '/^og:video(?::|$)/D',
 				'exists' => false,
 			),
+			'brand'        => array(
+				'match'  => '/^(product|og):brand$/D',
+				'exists' => false,
+			),
+			'ratings'      => array(
+				'match'  => '/^og:rating(_scale|_count)?$/D',
+				'exists' => false,
+			),
 		);

 		$processor = new WP_HTML_Tag_Processor( $html );
diff --git a/plugins/woocommerce/src/Internal/StructuredData/ProductOpenGraphTags.php b/plugins/woocommerce/src/Internal/StructuredData/ProductOpenGraphTags.php
index 404a2e97993..21fab5dfefb 100644
--- a/plugins/woocommerce/src/Internal/StructuredData/ProductOpenGraphTags.php
+++ b/plugins/woocommerce/src/Internal/StructuredData/ProductOpenGraphTags.php
@@ -84,6 +84,22 @@ class ProductOpenGraphTags {
 			$tags[] = array( $property => $value );
 		}

+		$brand_ids = $product->get_brand_ids();
+		if ( is_array( $brand_ids ) && 1 === count( $brand_ids ) ) {
+			$brand = get_term( reset( $brand_ids ), 'product_brand' );
+			if ( $brand instanceof \WP_Term ) {
+				$tags[] = array( 'product:brand' => $brand->name );
+				$tags[] = array( 'og:brand' => $brand->name );
+			}
+		}
+		if ( wc_review_ratings_enabled() && $product->get_rating_count() > 0 ) {
+			$tags[] = array(
+				'og:rating'       => (string) $product->get_average_rating(),
+				'og:rating_scale' => '5',
+				'og:rating_count' => (string) $product->get_rating_count(),
+			);
+		}
+
 		foreach ( wc_get_container()->get( ProductMediaSources::class )->get_sources( $product ) as $media => $source ) {
 			$root  = 'og:' . $media;
 			$group = array();
diff --git a/plugins/woocommerce/tests/php/src/Internal/StructuredData/OpenGraphTest.php b/plugins/woocommerce/tests/php/src/Internal/StructuredData/OpenGraphTest.php
index d3e4e7cdb15..b23a47a582a 100644
--- a/plugins/woocommerce/tests/php/src/Internal/StructuredData/OpenGraphTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/StructuredData/OpenGraphTest.php
@@ -209,6 +209,29 @@ class OpenGraphTest extends WC_Unit_Test_Case {
 		$this->assertSame( array( 'EUR' ), $tags['product:price:currency'], 'An existing currency should be preserved without duplication.' );
 	}

+	/**
+	 * @testdox Should leave both brand aliases to a provider that supplies either one.
+	 * @testWith ["product:brand", "og:brand"]
+	 *           ["og:brand", "product:brand"]
+	 *
+	 * @param string $provider_property Provider's brand property.
+	 * @param string $other_property Other brand property.
+	 */
+	public function test_existing_brand_suppresses_fallback_aliases( string $provider_property, string $other_property ): void {
+		$brand = wp_insert_term( 'Store brand', 'product_brand' );
+		$this->assertIsArray( $brand );
+		$this->product->set_brand_ids( array( $brand['term_id'] ) );
+		$this->product->save();
+
+		$tags = $this->render_meta_tags( '' );
+		$this->assertSame( array( 'Store brand' ), $tags['product:brand'] ?? array() );
+		$this->assertSame( array( 'Store brand' ), $tags['og:brand'] ?? array() );
+
+		$tags = $this->render_meta_tags( '<meta property="' . $provider_property . '" content="Provider brand">' );
+		$this->assertSame( array( 'Provider brand' ), $tags[ $provider_property ] ?? array() );
+		$this->assertArrayNotHasKey( $other_property, $tags );
+	}
+
 	/**
 	 * @testdox Should allow disabling Open Graph output without changing existing metadata.
 	 */