Render GTIN in Product structured data (#50087)

* Add GTIN in structured data

* Changelog

* Add changefile(s) from automation for the following project(s): woocommerce

* Delete plugins/woocommerce/changelog/50087-tweak-add-gtin-ld-json

* Add changefile(s) from automation for the following project(s): woocommerce

* Lint

* Delete plugins/woocommerce/changelog/50087-tweak-add-gtin-ld-json

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Miguel Pérez Pellicer 2024-08-20 16:57:23 +02:00 committed by GitHub
parent c9aa65a22f
commit a883856171
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: tweak
Add GTIN in structured data

View File

@ -214,6 +214,12 @@ class WC_Structured_Data {
$markup['sku'] = $product->get_id();
}
// Add GTIN only if it's a valid number.
$gtin = $product->get_global_unique_id();
if ( $gtin && is_numeric( $gtin ) ) {
$markup['gtin'] = $gtin;
}
if ( '' !== $product->get_price() ) {
// Assume prices will be valid until the end of next year, unless on sale and there is an end date.
$price_valid_until = gmdate( 'Y-12-31', time() + YEAR_IN_SECONDS );