If prices are the same for all variations, use price not priceSpecification

Closes #14848
This commit is contained in:
Mike Jolley 2017-05-08 16:53:27 +01:00
parent 89b28fd656
commit 7d956ca797
1 changed files with 11 additions and 7 deletions

View File

@ -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 ) );