Skip to content

Add support for SalePrice in JSON-LD schema for structured data #52105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 24, 2024

Conversation

zhyian
Copy link
Contributor

@zhyian zhyian commented Oct 17, 2024

Submission Review Guidelines:

Changes proposed in this Pull Request:

Closes #51997.

This update adds the SalePrice(https://schema.org/SalePrice) property in the JSON-LD schema for structured data. The regular price is moved under ListPrice(https://schema.org/ListPrice) property.

This enhancement aligns with recent changes to Google's structured data guidelines for merchant listings, providing more flexibility for representing sale prices. This allows merchants to more effectively showcase discounts and offers in search results.

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Add a product.
  2. Set a sale price.
  3. Save and open the product permalink.
  4. View page source code, search for application/ld+json.
  5. Copy this script HTML element and check it with Schema Markup Validator
  6. Ensure both(sale and regular) prices are added
image

Changelog entry

  • Automatically create a changelog entry from the details below.
  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Changelog Entry Comment

Comment

Add SalePrice property in JSON-LD schema for structured data.

@github-actions github-actions bot added plugin: woocommerce Issues related to the WooCommerce Core plugin. type: community contribution labels Oct 17, 2024
@woocommercebot woocommercebot requested review from a team and coreymckrill and removed request for a team October 17, 2024 09:30
Copy link
Contributor

Hi ,

Apart from reviewing the code changes, please make sure to review the testing instructions and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

@zhyian zhyian changed the title [WIP] Add support for SalePrice in JSON-LD schema for structured data Add support for SalePrice in JSON-LD schema for structured data Oct 17, 2024
@zhyian zhyian marked this pull request as ready for review October 17, 2024 11:15
@coreymckrill coreymckrill requested review from a team and Aljullu and removed request for coreymckrill and a team October 17, 2024 20:33
Copy link
Contributor

@Aljullu Aljullu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening this PR, @zhyian, this looks really well! Just one question: is there any reason you aren't adding the SalePrice property to variable products on sale? Variable products where all variations have the same prices, could benefit from this as well, I think.

@zhyian
Copy link
Contributor Author

zhyian commented Oct 22, 2024

Thanks @Aljullu for the feedback! Initially, I thought using the lowPrice property would be sufficient, but your suggestion makes sense. I've updated the code accordingly.

@tyrann0us thank you!

Copy link
Contributor

@Aljullu Aljullu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates, @zhyian! I just noticed one edge case in variables products:

  1. Set up two variations, one with regular price of 6 and no sale. Another one with regular price of 10 and sale price of 8.
  2. Check the page in the validator.
  3. Notice the price of 6 is presented as the SalePrice.

My understanding is that it shouldn't, even though it's the lowest price, 6 doesn't belong to a sale so it shouldn't be a SalePrice.

@zhyian
Copy link
Contributor Author

zhyian commented Oct 23, 2024

Thank you, @Aljullu, for pointing that out! Great catch - I’ve made the necessary fix. Please take a look.

Copy link
Contributor

@Aljullu Aljullu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good on my end now! Thanks for your work, @zhyian! 👏

@Aljullu Aljullu merged commit 840ad69 into woocommerce:trunk Oct 24, 2024
90 of 94 checks passed
@github-actions github-actions bot added this to the 9.5.0 milestone Oct 24, 2024
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Oct 24, 2024
@Stojdza Stojdza added needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. status: analysis complete Indicates if a PR has been analysed by Solaris and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels Oct 24, 2024
@ivantipov
Copy link

ivantipov commented Jan 30, 2025

Hi @zhyian, this update removed the sale price from Yandex search results, only showing the full price – the SalePrice property doesn't come through in the schema for regular products. Looking at the 9.6.0 source it's only applied to variable products – don't know what happened there as your commit seems to include them all.

Thanks

Capture d’écran 2025-01-30 à 12 10 32

@Aljullu
Copy link
Contributor

Aljullu commented Jan 31, 2025

@ivantipov what you are experiencing might be related to another PR (maybe #52871?) so I think it's better if you open a separate issue about this. It would be useful if you can do conflict testing with other plugins before, and then share some steps to reproduce with WooCommerce core that help us reproduce the same issue.

I tested with https://webmaster.yandex.com/tools/microtest/, and it's true that when a regular product is on sale we don't include "priceType": "https://schema.org/SalePrice", but that's what's recommended by Google:

Don't mark the current, offer price with a priceType property.

It's also aligned with what Shopify does, if I'm not wrong.

@ivantipov
Copy link

ivantipov commented Jan 31, 2025

Thanks – just added the bug report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. plugin: woocommerce Issues related to the WooCommerce Core plugin. status: analysis complete Indicates if a PR has been analysed by Solaris type: community contribution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Product JSON-LD only shows sale price when product is on sale, omitting regular price
5 participants