PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

Mismatch value error, need assistance with schema

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.
12

Hi,

I've been getting Mismatched value errors in Google Merchant Center due to some errors in the output of prices and currency in schema.

The default currency on my site is USD.

I contacted Rank Math, to fix the errors, they said the Price variable in the CAD offer needs to be changed from default currency to CAD and they suggested I contact you on how to get the price for a specific currency in a function.

Here is the screenshot from their support pointing out the issue and suggested fix: https://imgur.com/a/6gcjTSb

Here is the Rank Math schema filter function:

add_filter( ‘rank_math/snippet/rich_snippet_product_entity’, function( $entity ) {
if ( ! is_product() ) {
return $entity;
}

$product = wc_get_product( get_the_ID() );
if ( ! $product->is_type( ‘variable’ ) ) {
return $entity;
}

$variations = $product->get_available_variations();
if ( ! empty( $variations ) ) {
$offers = [];
foreach ( $variations as $variation ) {
$price_valid_until = get_post_meta( $variation[‘variation_id’], ‘_sale_price_dates_to’, true );
$offers[] = [
‘@type’ => ‘Offer’,
‘description’ => strip_tags( $variation[‘variation_description’] ),
‘price’ => $variation[‘display_price’],
‘priceCurrency’ => get_woocommerce_currency(),
‘availability’ => $variation[‘is_in_stock’] ? ‘https://schema.org/InStock’ : ‘https://schema.org/OutOfStock’,
‘itemCondition’ => ‘NewCondition’,
‘priceValidUntil’ => $price_valid_until ? date_i18n( ‘Y-m-d’, $price_valid_until ) : ‘2025-12-31’,
‘url’ => $product->get_permalink(),
‘sku’ => $variation[‘sku’],
‘gtin’ => $variation[‘gtin’],
];
}
}

$entity[‘offers’] = $offers;

return $entity;
} );

// fix for google merchant centre crawlers picking up wrong currency for cad vs usd pages
// Based on source: https://support.rankmath.com/ticket/is-it-possible-to-set-multi-currencies-in-one-schema-in-a-woocommerce-product/
function ssc_schema_dual_offers( $entity ) {
global $product;
$price = $product->get_price();
$url_product = get_permalink( $product->get_id() );
$future = date(“Y-m-d”, strtotime(“+365 days”));
//if ( has_term( ‘example-category’, ‘product_cat’ ) ) { // (We have it limited to only one category in our store)
unset($entity[‘offers’]);
$entity[‘offers’] = [
[
‘@type’ => ‘Offer’,
‘price’ => $price,
‘priceCurrency’ => ‘USD’,
‘priceValidUntil’ => $future,
‘availability’ => ‘https://schema.org/InStock’,
‘itemCondition’ => ‘https://schema.org/NewCondition’,
‘url’ => $url_product . ‘?currency=USD’,
‘seller’ => [
‘@type’ => ‘Organization’,
‘@id’ => ‘https://www.inspirebeautyshop.com/’,
‘name’ => ‘Inspire Beauty’,
‘url’ => ‘https://www.inspirebeautyshop.com/’,
‘logo’ => ‘https://www.inspirebeautyshop.com/wp-content/uploads/2021/02/inspire_beauty.png’
],
‘priceSpecification’ => [
‘price’ => $price,
‘priceCurrency’ => ‘USD’,
‘valueAddedTaxIncluded’ => ‘false’
],
],
[
‘@type’ => ‘Offer’,
‘price’ => $price,
‘priceCurrency’ => ‘CAD’,
‘priceValidUntil’ => $future,
‘availability’ => ‘https://schema.org/InStock’,
‘itemCondition’ => ‘https://schema.org/NewCondition’,
‘url’ => $url_product . ‘?currency=CAD’,
‘seller’ => [
‘@type’ => ‘Organization’,
‘@id’ => ‘https://www.inspirebeautyshop.com/’,
‘name’ => ‘Inspire Beauty’,
‘url’ => ‘https://www.inspirebeautyshop.com/’,
‘logo’ => ‘https://www.inspirebeautyshop.com/wp-content/uploads/2021/02/inspire_beauty.png’
],
‘priceSpecification’ => [
‘price’ => $price,
‘priceCurrency’ => ‘CAD’,
‘valueAddedTaxIncluded’ => ‘false’
],
],
];
return $entity;
//}
};
add_filter( ‘rank_math/snippet/rich_snippet_product_entity’, ‘ssc_schema_dual_offers’, 999, 2 );

 

I hope you can help with the fix?

Thank you!

Natasha

 

Hello Natasha

Try  to  add  this  code  here - https://share.pluginus.net/image/i20230306114610.png and  https://share.pluginus.net/image/i20230306114645.png

if (class_exists('WOOCS')) {

global $WOOCS;

$curr = $WOOCS->current_currency

if($curr!='USD'){

$WOOCS->set_currency('USD');

}

}

Thank you for your assistance!

I inserted the code but I'm getting an error, see screenshot: https://imgur.com/a/38Kjg52 (please see line 264).

Try  this  code:

if (class_exists('WOOCS')) {

    global $WOOCS;

    $curr = $WOOCS->current_currency;

    if($curr!='USD'){

        $WOOCS->set_currency('USD');

    }

}

I added that code but the currency switcher on the site stopped working. I couldn't switch to any other currency but default currency. I've removed the code.

Hello

oK!  try  to  add  this  code -  https://share.pluginus.net/image/i20230307112219.png and https://share.pluginus.net/image/i20230307112303.png

if (class_exists('WOOCS')) {

    global $WOOCS;

    if($curr != $WOOCS->current_currency){

        $WOOCS->set_currency($curr);

    }

}

please don't delete the old code

Thank you! I will add the code in an hour. I have one question, when you say ‘don’t delete the old code’ what does that mean? Should I also add the code from message #2 and/or #4? Or do you mean the original code from message #1 (which is still there)?

I added the code, and added the code from yesterday (code from Message #4). The currency converter works, but I just ran a url through schema validator and I am still getting wrong value for currency.

For example, this product url: https://www.inspirebeautyshop.com/product/mara/algae-retinol-face-oil/?attribute_pa_size=15ml-travel-size&currency=CAD

Published price on website for that product variation is $85 CAD and $66 USD.

But on the schema markup its $66 CAD and $66 USD (it's taking the value from the default USD price for CAD).

Here is screenshot of schema validator: https://imgur.com/a/imsgxea

I won't delete the codes from message #4 and #6.

 

Hello

Please paste your license key here - https://share.pluginus.net/image/i20230222134241.png -> https://share.pluginus.net/image/i20230222134511.png

they said the Price variable in the CAD offer needs to be changed from default currency to CAD  - I did not understand, do you need several currencies or one?

I pasted the license key.

I have 2 shopping feeds, CAD and USD.

Default currency on my website is USD.

I am getting Mismatched value errors in Merchant Center, see screenshot: https://imgur.com/a/jIJhyZY

Schema is outputting the US price for both USD and CAD offers, which is incorrect price and currency.

The feeds are working correctly, it the schema that is outputting the wrong value, currency and sometime wrong variant product.

I contacted rank math, and they told me to contact you (see first message).

I reverted the code back to what it was in message #1, let me know if you want me to put the codes back from message #4 and #6?

 

Please renew your  support

Then this code is basically wrong. For different currencies you insert the same price -  https://c2n.me/4i0AhtY.png

Do you have experience in programming?

I renewed the support, I think license key the same?

I don't have experience in programming. I hired a developer to try fix the Mismatch value errors. He couldn't fix it, I then found this article on your support forum from someone also using Rank Math with the same schema issue: https://pluginus.net/support/topic/fix-for-google-merchant-feeds-mismatched-value-wrong-currency-in-schema-when-using-rankmath-seo-plugin/

The developer added that code, but it didn't fix the issue. I contacted Rath Math, and then they told me to contact you. Can you help me fix this? I have over 200 disapproved products with mismatched value errors in Merchant Center, I need to fix it.

The errors I see in schema: it's inserting the same price for both currencies, and it's also inserting the lowest variation price for variable products.

Thank you!

 

hello

Ok! Code customization is not included in support

Try  to  change  your code:

1)  https://share.pluginus.net/image/i20230309104516.png

if (class_exists('WOOCS')) {

global $WOOCS;

$curr = $WOOCS->current_currency;

if($curr!=>$WOOCS->default_currency;){

$WOOCS->reset_currency();

}

}

2) https://share.pluginus.net/image/i20230309104606.png

$price_usd = $price;
$price_cad = $price;
if (class_exists('WOOCS')) {
$currencies = $WOOCS->get_currencies();
if(isset($currencies['USD'])){
$price_usd = $price_usd * $currencies['USD']['rate'];
}
if(isset($currencies['CAD'])){
$price_cad = $price_cad * $currencies['CAD']['rate'];
}
}

3) https://share.pluginus.net/image/i20230309104736.png

4) https://share.pluginus.net/image/i20230309105028.png

if (class_exists('WOOCS')) {

global $WOOCS;

if($curr != $WOOCS->current_currency){

$WOOCS->set_currency($curr);

}

}

Hi, thank you so much for your help!

I added the code, but I'm getting a syntax error, see screenshot: https://imgur.com/a/4IRS9A6

OK!  Try  this  code

if (class_exists('WOOCS')) {

global $WOOCS;

$curr = $WOOCS->current_currency;

if($curr!=>$WOOCS->default_currency){

$WOOCS->reset_currency();

}

}

I put the code in but now I'm getting syntax error for the same line, but for '>'

See screenshot: https://imgur.com/a/Et3kh2r

Hello

Try  it please

if (class_exists('WOOCS')) {

global $WOOCS;

$curr = $WOOCS->current_currency;

if($curr!=$WOOCS->default_currency){

$WOOCS->reset_currency();

}

}

Thank you! I added all the codes and I am able to save it.

I ran this url through schema validator: https://www.inspirebeautyshop.com/product/indie-lee/brightening-cleanser/?attribute_pa_size=300ml-jumbo&currency=CAD and schema is still showing the USD price for both USD and CAD. It's also still showing the price for the wrong product variation (it showing the lowest variation price, instead of the highest).

See screenshot: https://imgur.com/a/4R1LsRc

Please  drop  me  your  custom code

Here's the custom code with the code you asked me to add:

 

add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
    if ( ! is_product() ) {
            return $entity;
    }
    $product = wc_get_product( get_the_ID() );
    if ( ! $product->is_type( 'variable' ) ) {
            return $entity;
    }
    $variations = $product->get_available_variations();
    if ( ! empty( $variations ) ) {
            $offers = [];
            foreach ( $variations as $variation ) {
                    $price_valid_until = get_post_meta( $variation['variation_id'], '_sale_price_dates_to', true );
                    $offers[] = [
                            '@type'           => 'Offer',
                            'description'     => strip_tags( $variation['variation_description'] ),
                            'price'           => $variation['display_price'],
                            'priceCurrency'   => get_woocommerce_currency(),
                            'availability'    => $variation['is_in_stock'] ? 'https://schema.org/InStock' : 'https://schema.org/OutOfStock',
                            'itemCondition'   => 'NewCondition',
                            'priceValidUntil' => $price_valid_until ? date_i18n( 'Y-m-d', $price_valid_until ) : '2025-12-31',
                            'url'             => $product->get_permalink(),
                            'sku'             => $variation['sku'],
                            'gtin'             => $variation['gtin'],
                    ];
            }
    }
    $entity['offers'] = $offers;
    return $entity;
} );
// fix for google merchant centre crawlers picking up wrong currency for cad vs usd pages
function ssc_schema_dual_offers( $entity ) {
global $product;
if (class_exists('WOOCS')) {
global $WOOCS;
$curr = $WOOCS->current_currency;
if($curr!=$WOOCS->default_currency){
$WOOCS->reset_currency();
}
}
$price = $product->get_price();
$price_usd = $price;
$price_cad = $price;
if (class_exists('WOOCS')) {
$currencies = $WOOCS->get_currencies();
if(isset($currencies['USD'])){
$price_usd = $price_usd * $currencies['USD']['rate'];
}
if(isset($currencies['CAD'])){
$price_cad = $price_cad * $currencies['CAD']['rate'];
}
}
$url_product = get_permalink( $product->get_id() );
$future = date("Y-m-d", strtotime("+365 days"));
//if ( has_term( 'example-category', 'product_cat' ) ) { // (We have it limited to only one category in our store)
unset($entity['offers']);
$entity['offers'] = [
[
'@type' => 'Offer',
'price' => $price_usd,
'priceCurrency' => 'USD',
'priceValidUntil' => $future,
'availability' => 'https://schema.org/InStock',
'itemCondition' => 'https://schema.org/NewCondition',
'url' => $url_product . '?currency=USD',
'seller' => [
'@type' => 'Organization',
'@id' => 'https://www.inspirebeautyshop.com/',
'name' => 'Inspire Beauty',
'url' => 'https://www.inspirebeautyshop.com/',
'logo' => 'https://www.inspirebeautyshop.com/wp-content/uploads/2021/02/inspire_beauty.png'
],
'priceSpecification' => [
'price' => $price_usd,
'priceCurrency' => 'USD',
'valueAddedTaxIncluded' => 'false'
],
],
[
'@type' => 'Offer',
'price' => $price_cad,
'priceCurrency' => 'CAD',
'priceValidUntil' => $future,
'availability' => 'https://schema.org/InStock',
'itemCondition' => 'https://schema.org/NewCondition',
'url' => $url_product . '?currency=CAD',
'seller' => [
'@type' => 'Organization',
'@id' => 'https://www.inspirebeautyshop.com/',
'name' => 'Inspire Beauty',
'url' => 'https://www.inspirebeautyshop.com/',
'logo' => 'https://www.inspirebeautyshop.com/wp-content/uploads/2021/02/inspire_beauty.png'
],
'priceSpecification' => [
'price' => $price_cad,
'priceCurrency' => 'CAD',
'valueAddedTaxIncluded' => 'false'
],
],
];
if (class_exists('WOOCS')) {
global $WOOCS;
if($curr != $WOOCS->current_currency){
$WOOCS->set_currency($curr);
}
}
return $entity;
//}
};
add_filter( 'rank_math/snippet/rich_snippet_product_entity', 'ssc_schema_dual_offers', 999, 2 );
12