Snippet not working

#674934
  • Resolved Andrew Lautenbach
    Rank Math free

    Hello guys!

    im working on a function that changes the price if a product is connected to the page, but even if i hardcode ‘2.00’ for the price it doesn’t change the value of this specific meta data tag:
    <meta property=”product:price:amount” content=”%price%”>

    It does show up in the Schema data which is great. Do u guys know what i do wrong?


    add_filter( 'rank_math/snippet/rich_snippet_product_entity', 'strl_product_meta' );
    function strl_product_meta( $entity ) {

    if ( empty( $entity['offers'] ) ) {
    return $entity;
    }

    $post_id = get_the_ID();
    if ( empty( $post_id ) ) {
    return;
    }
    $regular_price = 2; // strl_price_regular_callback( $post_id );
    $sale_price = 1.50; // strl_price_regular_callback( $post_id );

    if ( empty( $regular_price ) && empty( $sale_price ) ) {
    return;
    }
    $entity['offers']['price'] = ! empty( $sale_price ) ? $sale_price : $regular_price;
    $entity['offers']['priceCurrency'] = 'EUR';

    return $entity;
    }

    Meta data in Rank Math

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

    I’m sorry to hear that you’re experiencing issues with the snippet not working as expected. It seems like you’re trying to modify the price of a product in the Schema data using the rank_math/snippet/rich_snippet_product_entity filter.

    Looking at your code, it seems like you’re correctly using the filter to modify the price and currency of the product. However, there are a couple of things that might be causing the issue:

    1. The &amp; in your code should be replaced with && for the logical AND operator.
    2. It’s possible that the filter priority might be conflicting with other filters or plugins.

    Here’s a modified version of your code with the &amp; replaced and a specific priority added to the filter:

    add_filter( 'rank_math/snippet/rich_snippet_product_entity', 'strl_product_meta', 10 );
    function strl_product_meta( $entity ) {
    
        if ( empty( $entity['offers'] ) ) {
            return $entity;
        }
    
        $post_id = get_the_ID();
        if ( empty( $post_id ) ) {
            return $entity;
        }
        $regular_price = 2; // strl_price_regular_callback( $post_id );
        $sale_price    = 1.50; // strl_price_regular_callback( $post_id );
    
        if ( empty( $regular_price ) && empty( $sale_price ) ) {
            return $entity;
        }
        $entity['offers']['price']         = ! empty( $sale_price ) ? $sale_price : $regular_price;
        $entity['offers']['priceCurrency'] = 'EUR';
    
        return $entity;
    }

    Please replace your existing code with this modified version and check if it resolves the issue. If the problem persists, please feel free to reach out to our support team for further assistance.

    I hope this helps! If you have any more questions or need further assistance, please don’t hesitate to ask.

    Sources:
    Rank Math SEO Filters and Hooks for Developers – Rank Math
    How to Fix Aggregate Rating Error » Rank Math
    Setting a Custom Brand for Your WooCommerce Store with Rank Math » Rank Math
    How to Make Your Theme Rank Math Compatible » Rank Math

    Hello,

    Please confirm if the filter shared by RankBot worked. If it didn’t, we might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.

    Please do take a complete backup of your website before sharing the information with us.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    We really look forward to helping you.

    Thanks Jaideep,

    The domain is IP protected so we would need an that first, after which i’ll give u a temporary login url.

    Is that okay?

    Hello,

    Thank you for your patience.

    Our team is distributed around the world and we use dynamic IPs, so even if you whitelist one particular IP now when we get back to the ticket our IP might already have changed.

    So, whitelisting a particular IP won’t help much.

    In this case, you can whitelist or open access to countries India, Portugal, and the Philippines to investigate this issue on your site.

    Looking forward to helping you.

    Unfortunately that will not be possible, let’s try it another way.

    Is there any way to programmatically change the Open Graph properties, filled in by Rank Math?

    <meta property=”product:price:amount” content=”0.99″>
    <meta property=”product:price:currency” content=”EUR”>

    backend

    Hello,

    You can modify and use the following filter to change the OpenGraph properties: https://rankmath.com/kb/filters-hooks-api-developer/#change-specific-social-meta

    Here is an example of how to modify the code:

    add_filter( "rank_math/opengraph/facebook/product_price_amount", function( $product_price ) {
        global $product;
        if (! is_product() ) {
            return;
        }
        $product_price = wc_get_price_including_tax( $product );
        return $product_price;
    });

    Also, the Advanced Schema Editor is only available in the PRO version, while your account’s subscription status is Free. Please share the email of your PRO account so we can merge it with this one.

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

    Even though we don’t use WooCommerce, that last filters works, wonderful!
    Thanks for the support!

    Hello,

    We are glad to hear that this issue has been resolved. Thank you for letting us know. This ticket will be closed now, but you can always open a new one if you have any other questions or concerns. We are here to help you with anything related to Rank Math.

    We appreciate your patience and cooperation throughout this process.

    Thank you for choosing Rank Math.

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

The ticket ‘Snippet not working’ is closed to new replies.