From 7d956ca797c7e9f6db9448997e74e6dbdbab92c3 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 8 May 2017 16:53:27 +0100 Subject: [PATCH] If prices are the same for all variations, use price not priceSpecification Closes #14848 --- includes/class-wc-structured-data.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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 ) );