• Resolved amitramani

    (@amitramani)


    Hello
    Let me begin my congratulating you on creating this very valuable plugin. I have been using it for a while now and it works just as promised.

    However, after reviewing my Google Search Console (GSC), I noticed the following errors for every product :
    Missing field ‘availability’

    After digging deeper, I discovered that the “availability” field is being excluded by Lines 1197-1219 of file woocommerce-sea.php

                                    if ( $lowest === $highest ) {
    
                                            $markup_offer = array(
                                                    '@type' => 'Offer',
                                                    'price' => wc_format_decimal( $lowest, wc_get_price_decimals() ),
    				               	'priceValidUntil'    => $price_valid_until,
    					        'priceCurrency' => $shop_currency,
                                            );
    
                                    } 

    It seems like that is the only clause that is missing the “availability” field.

    If I disable the “woocommerce_structured_data_product_offer” filter by commenting out Line 1251 of the woocommerce-sea.php, all is well. i.e. Availability is added to the schema.

    I just wanted to bring this bug to your attention. Hope you can fix it in the next iteration.

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • 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

    Thread Starter amitramani

    (@amitramani)

    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'  => 'https://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!

    Thread Starter amitramani

    (@amitramani)

    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

    Thread Starter amitramani

    (@amitramani)

    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

    Thread Starter amitramani

    (@amitramani)

    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

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Plugin does not add “availability” field’ is closed to new replies.