Woocommerce Product Schema Type %wc_price%

#197768
Viewing 7 replies - 1 through 7 (of 7 total)
  • Hello,

    Thank you for contacting the support, and sorry for any inconvenience that might have been caused due to that.

    Can you please share the affected URL with us so we can further check it on our end?

    We are looking forward to helping you.

    Thank you Jeremy
    This is one of the pages

    Thank you very much

    Hello,

    Thanks for getting back.

    Please copy the code given below and paste it into your theme’s/child theme’s functions.php file

    add_filter( "rank_math/snippet/rich_snippet_product_entity", function( $entity ) {
        $entity['offers']['price'] = preg_replace('/[^0-9\-]/', '', $entity['offers']['price']);
        return $entity;
    });

    This will remove the currency symbol from the price field of the schema and you will not get that warning in the Rich Results Test.

    Hope this helps. Let us know if you need any further assistance.

    Thanks Jaideep Asrani

    After adding this code to the theme, the tested price becomes 36139900 instead of 1399.00

    Thank you very much.

    Hello,

    Thanks for getting back.

    If that code isn’t working for you then you can use the code given below to create a new variable to fetch the price:

    add_action( 'rank_math/vars/register_extra_replacements', function(){
        rank_math_register_var_replacement(
            'simple_price',
            [
                'name'        => esc_html__( 'Product price without currency sign.', 'rank-math' ),
                'description' => esc_html__( 'Product price of the current product without currency sign', 'rank-math' ),
                'variable'    => 'simple_price',
                'example'     => 'get_price_no_currency()',
            ],
        'get_price_no_currency'
        );
    });
    function get_price_no_currency() {
        $product = wc_get_product();
        $price = $product->get_price();
        return $price;
    }

    By adding this code snippet in your theme’s funcstions.php file you get access to a custom variable called %simple_price% that outputs the price of your product without the currency sign and can be used in your Schema or in your meta description.

    Hope this helps.

    Don’t hesitate to get in touch if you require any further assistance.

    Thank you very much.

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

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

You must be logged in to reply to this ticket.