Variation Product InStock Issue

#30677
  • I am having a big issue with variation products InStock OutOfStock values.

    Example; I have a product with 3 sizes in the following order:

    Small – 0 Out of Stock
    Medium – 8 In Stock
    Large – 6 In Stock

    On google when searching for this product, it will display under the snippet that the product is out of stock.

    But only one size is out of stock and I guess because it’s the first variation it just shows whole product out of stock.

    This is really bad for click rate, what can I do to fix this?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hello,

    Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.

    Would you mind sharing a copy of the product links affected by this via the sensitive data section so that we can do additional testing?

    Looking forward to helping you. Thank you.

    ​​​​​​​

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Hi There,

    I had a look at your page and saw the issue.

    Could you try to extend the schema to include the variable product information?

    You can use this filter to extend the schema:

    https://rankmath.com/kb/filters-hooks-api-developer/#extend-json-ld-data

    /**
     * Collect data to output in JSON-LD.
     *
     * @param array  $unsigned An array of data to output in json-ld.
     * @param JsonLD $unsigned JsonLD instance.
     */
    add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
    	return [];
    }, 10, 2);

    In the meantime, we will also see if there is a way to handle this in a better way.

    Appreciate your patience in this matter.

    Does this make all products show in stock?

    Oh never mind that just a start of the code, I have no idea what to put in for it to be fixed? Could you make a code snippet that just makes all my products show in stock?

    Hello,

    Thank you for contacting Rank Math.

    You can make use of the following code on your theme’s functions.php file to check if the product is a variable product:

    /**
     * Filter to add Brand Name for Products.
     *
     * @param array $entity Snippet Data
     * @return array
     */
    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
        global $product;
        if ( $product->is_type( 'variable' ) ) {
            $entity['offers']['availability'] = 'https://schema.org/InStock';
        }
        
        return $entity;
    });

    Looking forward to helping you. Thank you.

    ​​​​​​​

    So just to clarify, that code makes it show all variable products as in stock?

    Todd
    Rank Math free

    Hi,

    Yes, it does.

    You can test it after adding the code here:
    https://search.google.com/structured-data/testing-tool/u/0/

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 8 replies - 1 through 8 (of 8 total)

The ticket ‘Variation Product InStock Issue’ is closed to new replies.