Commit f14d46621d for woocommerce
commit f14d46621d699b8f38065e0807afc21fb5870089
Author: Brian <brian@brianhaas.li>
Date: Thu Feb 12 12:48:46 2026 +0100
Fix: Variable product price with tax is not match in Schema (#61662)
* fix variable product price doesnt not match the one visible on product page
* fix simple products, add core contributors inputs
* fix to use existing variable
* proposal @Aljullu
* Add changefile(s) from automation for the following project(s): woocommerce
* fix linting errors
* use variable $tax_display_mode instead
* fix lint errors
* fix spaces
* Update phpstan-baseline.neon
---------
Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
diff --git a/plugins/woocommerce/changelog/61662-patch-9 b/plugins/woocommerce/changelog/61662-patch-9
new file mode 100644
index 0000000000..bdd18990d8
--- /dev/null
+++ b/plugins/woocommerce/changelog/61662-patch-9
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Show variable product price in schema based on woocommerce_tax_display_shop setting so the visual prices matches the schema price
\ No newline at end of file
diff --git a/plugins/woocommerce/includes/class-wc-structured-data.php b/plugins/woocommerce/includes/class-wc-structured-data.php
index 923f6c57c7..dcdcbeeda9 100644
--- a/plugins/woocommerce/includes/class-wc-structured-data.php
+++ b/plugins/woocommerce/includes/class-wc-structured-data.php
@@ -234,8 +234,10 @@ class WC_Structured_Data {
$price_valid_until = gmdate( 'Y-12-31', time() + YEAR_IN_SECONDS );
if ( $product->is_type( ProductType::VARIABLE ) ) {
- $lowest = $product->get_variation_price( 'min', false );
- $highest = $product->get_variation_price( 'max', false );
+ $lowest = $product->get_variation_price( 'min', true );
+ $highest = $product->get_variation_price( 'max', true );
+
+ $variation_prices = $product->get_variation_prices( true );
if ( $lowest === $highest ) {
$markup_offer = array(
@@ -245,7 +247,7 @@ class WC_Structured_Data {
'@type' => 'UnitPriceSpecification',
'price' => wc_format_decimal( $lowest, wc_get_price_decimals() ),
'priceCurrency' => $currency,
- 'valueAddedTaxIncluded' => wc_prices_include_tax(),
+ 'valueAddedTaxIncluded' => 'incl' === get_option( 'woocommerce_tax_display_shop' ),
'validThrough' => $price_valid_until,
),
),
@@ -255,12 +257,12 @@ class WC_Structured_Data {
'@type' => 'AggregateOffer',
'lowPrice' => wc_format_decimal( $lowest, wc_get_price_decimals() ),
'highPrice' => wc_format_decimal( $highest, wc_get_price_decimals() ),
- 'offerCount' => count( $product->get_variation_prices()['price'] ),
+ 'offerCount' => count( $variation_prices['price'] ),
);
if ( $product->is_on_sale() ) {
- $lowest_child_sale_price = $product->get_variation_sale_price( 'min', false );
- foreach ( $product->get_variation_prices()['sale_price'] as $variation_id => $variation_price ) {
+ $lowest_child_sale_price = $product->get_variation_sale_price( 'min', true );
+ foreach ( $variation_prices['sale_price'] as $variation_id => $variation_price ) {
if ( $variation_price === $lowest_child_sale_price ) {
break;
}
@@ -278,7 +280,7 @@ class WC_Structured_Data {
'priceType' => 'https://schema.org/SalePrice',
'price' => wc_format_decimal( $lowest_child_sale_price, wc_get_price_decimals() ),
'priceCurrency' => $currency,
- 'valueAddedTaxIncluded' => wc_prices_include_tax(),
+ 'valueAddedTaxIncluded' => 'incl' === get_option( 'woocommerce_tax_display_shop' ),
'validThrough' => $sale_price_valid_until ?? $price_valid_until,
),
);
@@ -312,7 +314,7 @@ class WC_Structured_Data {
'@type' => 'UnitPriceSpecification',
'price' => wc_format_decimal( $min_price, wc_get_price_decimals() ),
'priceCurrency' => $currency,
- 'valueAddedTaxIncluded' => wc_prices_include_tax(),
+ 'valueAddedTaxIncluded' => 'incl' === $tax_display_mode,
'validThrough' => $price_valid_until,
);
if ( $product->is_on_sale() && $min_price !== $min_sale_price ) {
@@ -340,17 +342,21 @@ class WC_Structured_Data {
'@type' => 'UnitPriceSpecification',
'price' => wc_format_decimal( $min_sale_price, wc_get_price_decimals() ),
'priceCurrency' => $currency,
- 'valueAddedTaxIncluded' => wc_prices_include_tax(),
+ 'valueAddedTaxIncluded' => 'incl' === $tax_display_mode,
'validThrough' => $sale_price_valid_until ?? $price_valid_until,
)
);
}
} else {
+ $tax_display_mode = get_option( 'woocommerce_tax_display_shop' );
+ $regular_price = 'incl' === $tax_display_mode
+ ? wc_get_price_including_tax( $product, array( 'price' => $product->get_regular_price() ) )
+ : wc_get_price_excluding_tax( $product, array( 'price' => $product->get_regular_price() ) );
$unit_price_specification = array(
'@type' => 'UnitPriceSpecification',
- 'price' => wc_format_decimal( $product->get_regular_price(), wc_get_price_decimals() ),
+ 'price' => wc_format_decimal( $regular_price, wc_get_price_decimals() ),
'priceCurrency' => $currency,
- 'valueAddedTaxIncluded' => wc_prices_include_tax(),
+ 'valueAddedTaxIncluded' => 'incl' === $tax_display_mode,
'validThrough' => $price_valid_until,
);
if ( $product->is_on_sale() ) {
@@ -366,6 +372,9 @@ class WC_Structured_Data {
);
if ( $product->is_on_sale() ) {
+ $sale_price = 'incl' === $tax_display_mode
+ ? wc_get_price_including_tax( $product, array( 'price' => $product->get_sale_price() ) )
+ : wc_get_price_excluding_tax( $product, array( 'price' => $product->get_sale_price() ) );
if ( $product->get_date_on_sale_to() ) {
$sale_price_valid_until = gmdate( 'Y-m-d', $product->get_date_on_sale_to()->getTimestamp() );
}
@@ -376,9 +385,9 @@ class WC_Structured_Data {
$markup_offer['priceSpecification'],
array(
'@type' => 'UnitPriceSpecification',
- 'price' => wc_format_decimal( $product->get_sale_price(), wc_get_price_decimals() ),
+ 'price' => wc_format_decimal( $sale_price, wc_get_price_decimals() ),
'priceCurrency' => $currency,
- 'valueAddedTaxIncluded' => wc_prices_include_tax(),
+ 'valueAddedTaxIncluded' => 'incl' === $tax_display_mode,
'validThrough' => $sale_price_valid_until ?? $price_valid_until,
)
);
diff --git a/plugins/woocommerce/phpstan-baseline.neon b/plugins/woocommerce/phpstan-baseline.neon
index 1242a5475a..871034c4db 100644
--- a/plugins/woocommerce/phpstan-baseline.neon
+++ b/plugins/woocommerce/phpstan-baseline.neon
@@ -15627,7 +15627,7 @@ parameters:
-
message: '#^Call to an undefined method WC_Product\:\:get_variation_prices\(\)\.$#'
identifier: method.notFound
- count: 2
+ count: 1
path: includes/class-wc-structured-data.php
-
@@ -15841,7 +15841,7 @@ parameters:
path: includes/class-wc-structured-data.php
-
- message: '#^Offset ''price'' on array\{priceValidUntil\: string, availability\: ''https\://schema\.org…'', url\: mixed, seller\: array\{''@type''\: ''Organization'', name\: mixed, url\: mixed\}, ''@type''\: ''AggregateOffer'', lowPrice\: mixed, highPrice\: mixed, offerCount\: int\<0, max\>, \.\.\.\}\|array\{priceValidUntil\: string, availability\: ''https\://schema\.org…'', url\: mixed, seller\: array\{''@type''\: ''Organization'', name\: mixed, url\: mixed\}, ''@type''\: ''Offer'', priceSpecification\: array\{0\: array\{''@type''\: ''UnitPriceSpecificat…'', price\: mixed, priceCurrency\: mixed, valueAddedTaxIncluded\: mixed, validThrough\: string, priceType\?\: ''https\://schema\.org…''\}, 1\?\: array\{''@type''\: ''UnitPriceSpecificat…'', price\: mixed, priceCurrency\: mixed, valueAddedTaxIncluded\: mixed, validThrough\: string, priceType\?\: ''https\://schema\.org…''\}\}\} in empty\(\) does not exist\.$#'
+ message: '#^Offset ''price'' on array\{priceValidUntil\: string, availability\: ''https\://schema\.org…'', url\: mixed, seller\: array\{''@type''\: ''Organization'', name\: mixed, url\: mixed\}, ''@type''\: ''AggregateOffer'', lowPrice\: mixed, highPrice\: mixed, offerCount\: int\<0, max\>, \.\.\.\}\|array\{priceValidUntil\: string, availability\: ''https\://schema\.org…'', url\: mixed, seller\: array\{''@type''\: ''Organization'', name\: mixed, url\: mixed\}, ''@type''\: ''Offer'', priceSpecification\: array\{0\: array\{''@type''\: ''UnitPriceSpecificat…'', price\: mixed, priceCurrency\: mixed, valueAddedTaxIncluded\: bool, validThrough\: string, priceType\?\: ''https\://schema\.org…''\}, 1\?\: array\{''@type''\: ''UnitPriceSpecificat…'', price\: mixed, priceCurrency\: mixed, valueAddedTaxIncluded\: bool, validThrough\: string, priceType\?\: ''https\://schema\.org…''\}\}\} in empty\(\) does not exist\.$#'
identifier: empty.offset
count: 1
path: includes/class-wc-structured-data.php