Price is Still showing on SERP as Schema

#90110
  • Resolved Desmond Ng
    Rank Math free

    As my client is a distributor, he wants to allow only logged in users can see the product price. However on searching on Google, he can find a lot of products that have the price included, this is detrimental to his and his installer’s business. How can I make it so that all the schema works, just not to show the price.

    This was shared by your side before.

    /**
     * Filter to mod product schema.
     *
     * @param array $entity Snippet Data
     * @return array
     */
    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
        if ( isset( $entity['offers']['availability'] ) ) { 
    		unset( $entity['offers']['availability']);
    	}
        if ( isset( $entity['offers']['highPrice'] ) ) { 
    		unset( $entity['offers']['highPrice']);
    	}
        return $entity;
    });
Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    Please try this code:

    /**
     * Filter to Short-circuit Schema if a 3rd party is interested in generating their own data.
     * Replace $schmea_type with schema name like article, review, etc.
     * @param array $entity Snippet Data
     * @return array
     */
    add_filter( "rank_math/snippet/rich_snippet_product_entity", function( $entity ) {
     unset($entity['offers']['price']);
     return $entity;
    });

    With that said, price is a mandatory field for the Schema so you will see errors when a price is not provided.

    Moreover, you can just disable the Product Schema if you do not wish for the rich snippets to appear for your results.

    Hello, Even If I disable price, the other snippets should still help right? Such as stock availability

    If I were to bulk update, how can I do so? I have over 500 products.Is it the same as selecting the No Snippet?

    I see in the plugin, it is possible to edit the fields in the Pro version, Means moving forward I don’t have to use the code anymore?

    Hello,

    Since you want to show these details only to your logged in members, I would recommend disabling the Product Schema on all your products. You can use this filter to do that:

    /**
     * Filter to Short-circuit Schema if a 3rd party is interested in generating their own data.
     * Replace $schmea_type with schema name like article, review, etc.
     * @param bool  $value true/false Default false
     * @param array $parts Post Data
     * @param array $data  Schmea Data
     * 
     * @return bool
     */
    add_filter( "rank_math/snippet/rich_snippet_product", function( $value, $parts, $data ) {
    	return true;
    }, 10, 3 );

    Please put that in your theme’s functions.php file.

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

    Hi Uzair, But the schema is supposed to show snippet on SERP right? It doesn’t have anything to do if a user is logged in or not. And if I were to turn off product schema, can’t I just use the disable button in the settings?

    Still waiting for your response for my other questions:
    1. If I were to bulk update, how can I do so? I have over 500 products.Is it the same as selecting the No Snippet?
    2.
    Based on the sneak peek shared by Bhanu, it is possible to edit the fields in the Pro version, Means moving forward I don’t have to use the code anymore?

    Hello,

    And if I were to turn off product schema, can’t I just use the disable button in the settings?

    Yes you can. The code allows to remove this in all of your products without having to go on each product one by one,

    If I were to bulk update, how can I do so? I have over 500 products.Is it the same as selecting the No Snippet?
    Adding the provided filter should update all your products. There is currently no option to bulk update the snippet for all your existing products.

    The no snippet option affects the preview snippet data, not the rich snippet. Enabling this will remove the meta description preview for all the pages you will create henceforth unless changed.
    Based on the sneak peek shared by Bhanu, it is possible to edit the fields in the Pro version, Means moving forward I don’t have to use the code anymore?

    Not to let much out but the Schema generator option will allow you to customize your schema markup accordingly without much hustle.

    Looking forward to helping you. Thank you.

    ​​​​​​

    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 5 replies - 1 through 5 (of 5 total)

The ticket ‘Price is Still showing on SERP as Schema’ is closed to new replies.