Hi amitramani,
The snippet of code you copied and pasted is the default normal WooCommerce structured data which is far from optimal. The code was giving a hint already:
// Just use the old WooCommerce buggy setting
We build an Elite feature in our plugin that actually improves the standard WooCommerce structured data:
https://adtribes.io/woocommerce-structured-data-bug/
Depending on the product type the structured data we insert then looks like this:
$markup_offer = array(
'@type' => 'AggregateOffer',
'lowPrice' => wc_format_decimal( $lowest, wc_get_price_decimals() ),
'highPrice' => wc_format_decimal( $highest, wc_get_price_decimals() ),
'priceCurrency' => $shop_currency,
'itemCondition' => 'https://schema.org/'.$json_condition.'',
'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,
),
'url' => $link
);
All the best,
Eva
Hello
Thank you for the fast response. It appears that Woocommerce (version 3.7.0) has corrected the problem.
I double checked the default WooCommerce code (https://github.com/woocommerce/woocommerce/blob/master/includes/class-wc-structured-data.php#L261). As you can see below, the Woocommerce codes adds the “availability” feed to all the variations.
$markup_offer += array(
'priceCurrency' => $currency,
'availability' => 'http://schema.org/' . ( $product->is_in_stock() ? 'InStock' : 'OutOfStock' ),
'url' => $permalink,
'seller' => array(
'@type' => 'Organization',
'name' => $shop_name,
'url' => $shop_url,
),
);
$markup['offers'] = array( apply_filters( 'woocommerce_structured_data_product_offer', $markup_offer, $product ) );
}
Also, notice that your plugin is overwriting the “availability” field because it uses the ‘woocommerce_structured_data_product_offer’ filter.
I hope that you will review this and make the appropriate changes to your plugin and release an update.
I look forward to it! Thank you for a very valuable plugin!
Hello @evavangelooven
I did not hear back from you. Any advise ?
Thanks
Hi,
My apologies for the late reply we somehow missed this issue. I believe we have actually made the change you requested shortly after you raised this issue.
This is the piece of code in our plugin that is used:
// Just use the old WooCommerce buggy setting
if ( '' !== $product->get_price() ) {
$price_valid_until = date( 'Y-12-31', current_time( 'timestamp', true ) + YEAR_IN_SECONDS );
if ( $product->is_type( 'variable' ) ) {
$prices = $product->get_variation_prices();
$lowest = reset( $prices['price'] );
$highest = end( $prices['price'] );
if ( $lowest === $highest ) {
$markup_offer = array(
'@type' => 'Offer',
'price' => wc_format_decimal( $lowest, wc_get_price_decimals() ),
'priceValidUntil' => $price_valid_until,
'priceCurrency' => $shop_currency,
);
} else {
$markup_offer = array(
'@type' => 'AggregateOffer',
'lowPrice' => wc_format_decimal( $lowest, wc_get_price_decimals() ),
'highPrice' => wc_format_decimal( $highest, wc_get_price_decimals() ),
'priceValidUntil' => $price_valid_until,
'priceCurrency' => $shop_currency,
'availability' => 'https://schema.org/' . ( $product->is_in_stock() ? 'InStock' : 'OutOfStock' ),
'seller' => array(
'@type' => 'Organization',
'name' => $shop_name,
'url' => $shop_url,
),
);
}
} else {
if ( $product->is_on_sale() && $product->get_date_on_sale_to() ) {
$price_valid_until = date( 'Y-m-d', $product->get_date_on_sale_to()->getTimestamp() );
}
$permalink = get_permalink( $product->get_id() );
$markup_offer = array(
'@type' => 'Offer',
'price' => wc_format_decimal( $product->get_price(), wc_get_price_decimals() ),
'priceValidUntil' => $price_valid_until,
'priceCurrency' => $shop_currency,
'availability' => 'https://schema.org/' . ( $product->is_in_stock() ? 'InStock' : 'OutOfStock' ),
'url' => $permalink,
'seller' => array(
'@type' => 'Organization',
'name' => $shop_name,
'url' => $shop_url,
),
);
}
}
As you can see the availability part is in. The only pages were it is not is on variable pages where the price of all variants is the same. Would that happen to be the case you are referring too? In all other instances it should work just fine.
All the best,
Eva
Hi Eva
Sorry for the late reply.
Yes, in my case, the variations of a product are all the same price. Therefore, the availability field would not be added. For example, if a shirt is available in 3 sizes and 2 colors, all 6 variations have the same price.
Is that something you plan to address in the plugin?
Hi,
We found that in Google Serps our Woocommerce product pages stopped displaying the “In stock/Out of stock” message.
When we tested an example product page in Google structured data testing tool we found that there were warnings in the Offers -> availability and Offers -> URL fields. These warning disappeared when we when the Product Feed Pro for Woocommerce plugin was disabled. We’ve temporarily keeping the plugin disabled to see if the “In stock/Out of stock” messages reappear in Google. Do you have more information about this issue?
Just to mention that all our products have the same prices for all variations to the Woocommerce problem is not an issue for us.
Thanks
Hello @jdtravel
Have you tried disabling the “woocommerce_structured_data_product_offer” filter by commenting out Line 1251 of the woocommerce-sea.php?
You can do this without editing the woocommerce-sea.php by simply disabling the “woocommerce_structured_data_product_offer” filter in your functions.php.
Thanks
Amit
Hi jdtravel,
When you have disabled our structured data feature (https://adtribes.io/woocommerce-structured-data-bug/) the plugin doesn’t do anything with the existing availability structured data snippet. It uses the default WooCommerce structured data in those cases.
Best,
Eva