Skip to content

Commit

Permalink
Merge pull request woocommerce#14931 from woocommerce/fix/14854
Browse files Browse the repository at this point in the history
Hide offers from structured markup when blank
  • Loading branch information
claudiosanches authored May 8, 2017
2 parents 257594a + c7e9a4c commit ec5df64
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions includes/class-wc-structured-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,34 +200,36 @@ public function generate_product_data( $product = null ) {
return;
}

$markup_offer = array(
'@type' => 'Offer',
'priceCurrency' => $currency,
'availability' => 'https://schema.org/' . $stock = ( $product->is_in_stock() ? 'InStock' : 'OutOfStock' ),
'sku' => $product->get_sku(),
'image' => wp_get_attachment_url( $product->get_image_id() ),
'description' => $product->get_description(),
'seller' => array(
'@type' => 'Organization',
'name' => $shop_name,
'url' => $shop_url,
),
);

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() ),
if ( '' !== $product->get_price() ) {
$markup_offer = array(
'@type' => 'Offer',
'priceCurrency' => $currency,
'availability' => 'https://schema.org/' . $stock = ( $product->is_in_stock() ? 'InStock' : 'OutOfStock' ),
'sku' => $product->get_sku(),
'image' => wp_get_attachment_url( $product->get_image_id() ),
'description' => $product->get_description(),
'seller' => array(
'@type' => 'Organization',
'name' => $shop_name,
'url' => $shop_url,
),
);
} else {
$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 ) );
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,
);
} else {
$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 ) );
}

if ( $product->get_rating_count() ) {
$markup['aggregateRating'] = array(
Expand Down

0 comments on commit ec5df64

Please sign in to comment.