diff --git a/includes/class-wc-structured-data.php b/includes/class-wc-structured-data.php index 5d751a0b684..d471d02277f 100644 --- a/includes/class-wc-structured-data.php +++ b/includes/class-wc-structured-data.php @@ -217,14 +217,18 @@ class WC_Structured_Data { if ( $product->is_type( 'variable' ) ) { $prices = $product->get_variation_prices(); - $markup_offer['priceSpecification'] = array( - 'price' => wc_format_decimal( $product->get_price(), wc_get_price_decimals() ), - 'minPrice' => wc_format_decimal( current( $prices['price'] ), wc_get_price_decimals() ), - 'maxPrice' => wc_format_decimal( end( $prices['price'] ), wc_get_price_decimals() ), - 'priceCurrency' => $currency, - ); + if ( current( $prices['price'] ) === end( $prices['price'] ) ) { + $markup_offer['price'] = wc_format_decimal( $product->get_price(), wc_get_price_decimals() ); + } else { + $markup_offer['priceSpecification'] = array( + 'price' => wc_format_decimal( $product->get_price(), wc_get_price_decimals() ), + 'minPrice' => wc_format_decimal( current( $prices['price'] ), wc_get_price_decimals() ), + 'maxPrice' => wc_format_decimal( end( $prices['price'] ), wc_get_price_decimals() ), + 'priceCurrency' => $currency, + ); + } } else { - $markup_offer['price'] = wc_format_decimal( $product->get_price(), wc_get_price_decimals() ); + $markup_offer['price'] = wc_format_decimal( $product->get_price(), wc_get_price_decimals() ); } $markup['offers'] = array( apply_filters( 'woocommerce_structured_data_product_offer', $markup_offer, $product ) );