Commit 18729f95cc7 for woocommerce
commit 18729f95cc7f9a1028d6bc298c58542be732363e
Author: Bero <1199991+bgrgicak@users.noreply.github.com>
Date: Wed Nov 4 09:57:45 2026 +0100
Add locale to shop Open Graph metadata (#70536)
* Add Open Graph metadata to the shop page
* Fix Open Graph class closing brace
* Fix Open Graph metadata on coming soon pages
* Generate shop descriptions from page content
* Test shop metadata with share links
* Fix markup in shop Open Graph titles
* Add locale to shop Open Graph metadata
* Add coverage for shop Open Graph locale
diff --git a/plugins/woocommerce/changelog/add-shop-open-graph-locale b/plugins/woocommerce/changelog/add-shop-open-graph-locale
new file mode 100644
index 00000000000..4cf8fb9069f
--- /dev/null
+++ b/plugins/woocommerce/changelog/add-shop-open-graph-locale
@@ -0,0 +1,4 @@
+Significance: patch
+Type: enhancement
+
+Include the store language in shared shop link metadata.
diff --git a/plugins/woocommerce/src/Internal/StructuredData/ShopOpenGraphTags.php b/plugins/woocommerce/src/Internal/StructuredData/ShopOpenGraphTags.php
index 3879eaf1ae1..926c727f59f 100644
--- a/plugins/woocommerce/src/Internal/StructuredData/ShopOpenGraphTags.php
+++ b/plugins/woocommerce/src/Internal/StructuredData/ShopOpenGraphTags.php
@@ -35,6 +35,10 @@ class ShopOpenGraphTags {
array( 'og:description' => wc_trim_string( $description ) ),
array( 'og:site_name' => get_bloginfo( 'name' ) ),
);
+ $locale = get_locale();
+ if ( preg_match( '/^[a-z]{2,3}_[A-Z]{2}$/', $locale ) ) {
+ $tags[] = array( 'og:locale' => $locale );
+ }
$image_id = get_post_thumbnail_id( $page );
$image = $image_id ? wc_get_container()->get( OpenGraphImageTags::class )->get_tags( $image_id, null, true ) : array();
diff --git a/plugins/woocommerce/tests/php/src/Internal/StructuredData/OpenGraphTest.php b/plugins/woocommerce/tests/php/src/Internal/StructuredData/OpenGraphTest.php
index a9964e1280f..6eac90e111e 100644
--- a/plugins/woocommerce/tests/php/src/Internal/StructuredData/OpenGraphTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/StructuredData/OpenGraphTest.php
@@ -356,9 +356,14 @@ class OpenGraphTest extends WC_Unit_Test_Case {
}
/**
- * @testdox Should add shop and category metadata and preserve a provider's image.
+ * @testdox Should add shop and category metadata and preserve a provider's image and locale.
+ * @testWith ["en_US", ["en_US"]]
+ * ["hr", []]
+ *
+ * @param string $locale Site locale.
+ * @param string[] $expected_locale Expected locale values.
*/
- public function test_shop_metadata(): void {
+ public function test_shop_metadata( string $locale, array $expected_locale ): void {
$shop_id = self::factory()->post->create(
array(
'post_type' => 'page',
@@ -373,6 +378,12 @@ class OpenGraphTest extends WC_Unit_Test_Case {
$shop_url = get_permalink( $shop_id );
$this->assertIsString( $shop_url );
$this->go_to( $shop_url );
+ add_filter(
+ 'locale',
+ static function () use ( $locale ) {
+ return $locale;
+ }
+ );
$tags = $this->render_meta_tags( '<meta property="og:type" content="article">' );
@@ -381,15 +392,17 @@ class OpenGraphTest extends WC_Unit_Test_Case {
$this->assertSame( array( $shop_url ), $tags['og:url'] );
$this->assertSame( array( 'Fresh coffee.' ), $tags['og:description'] );
$this->assertSame( array( 'Test store' ), $tags['og:site_name'] );
+ $this->assertSame( $expected_locale, $tags['og:locale'] ?? array() );
$this->assertSame( array( wp_get_attachment_url( (int) $this->product->get_image_id() ) ), $tags['og:image'] );
$this->assertSame( array( '1200' ), $tags['og:image:width'] );
$this->assertSame( array( '800' ), $tags['og:image:height'] );
$this->assertSame( array( 'Product photo' ), $tags['og:image:alt'] );
$this->assertSame( array( 'summary_large_image' ), $tags['twitter:card'] );
- $tags = $this->render_meta_tags( '<meta property="og:image" content="https://example.org/provider.jpg"><meta property="og:image:width" content="600">' );
+ $tags = $this->render_meta_tags( '<meta property="og:image" content="https://example.org/provider.jpg"><meta property="og:image:width" content="600"><meta property="og:locale" content="fr_FR">' );
$this->assertSame( array( 'https://example.org/provider.jpg' ), $tags['og:image'] );
$this->assertSame( array( '600' ), $tags['og:image:width'] );
+ $this->assertSame( array( 'fr_FR' ), $tags['og:locale'] );
$this->assertArrayNotHasKey( 'og:image:height', $tags );
$this->assertSame( array( 'summary_large_image' ), $tags['twitter:card'] );