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

I checked everything is correct - Your rate for all currencies is 1

So  11*1 = 11    11USD = 11CAD

All product on the site have fixed prices in every currency (see screenshot: https://imgur.com/a/tt5TJR3). Prices in different currencies are not calculated by a rate on the site, unless the rate is 1 x fixed price?

Example:

https://www.inspirebeautyshop.com/product/indie-lee/brightening-cleanser/?attribute_pa_size=300ml-jumbo&currency=CAD

Published price on website is $88 CAD

https://www.inspirebeautyshop.com/product/indie-lee/brightening-cleanser/?attribute_pa_size=300ml-jumbo&currency=USD

Published price on website is $68 USD

Schema is outputting $11 CAD and $11 USD for that CAD product variation: https://imgur.com/a/E99ljvu

It's outputting the same price for CAD and USD, and it choosing the wrong variation price (it's choosing the travel size US price instead of jumbo size price).

How do I fix?

Should I be changing any of the FOX WOOCS settings so that schema outputs the fixed price instead of the default US price for all currencies?

Here's screenshots of the FOX WOOCS settings, Individual fixed price rules for each product is enabled.

https://imgur.com/a/wh5S4v2

https://imgur.com/a/13amn23

 

 

Hello Natasha

All product on the site have fixed prices  - Well then of course all my code doesn't matter. You can delete this

try  to  change  code - https://c2n.me/4i2NZNm.png

if (class_exists('WOOCS')) {
global $WOOCS;
$curr = $WOOCS->current_currency
if($curr!='USD'){
$WOOCS->set_currency('USD');
}
$price_usd = $product->get_price();
$WOOCS->set_currency('CAD');
$price_cad = $product->get_price();
$WOOCS->set_currency($curr);
}

Thank you so much for your help and sorry for the late reply.

I added the code, but I'm getting an error, see screenshot: https://imgur.com/a/SanvLtu

Also there's one line of code that is in my original code, but not in yours, see screenshot (line 303): https://imgur.com/a/tfSHeS4 and compare to to your code: https://c2n.me/4i2NZNm.png   Should I delete that line as well? (I tried deleting it, but still got the other error above).

Hello

I delete that line as well? - Yes

Please try  yhis  code:

if (class_exists('WOOCS')) {
global $WOOCS;
$curr = $WOOCS->current_currency;
if($curr!='USD'){
$WOOCS->set_currency('USD');
}
$price_usd = $product->get_price();
$WOOCS->set_currency('CAD');
$price_cad = $product->get_price();
$WOOCS->set_currency($curr);
}

Thank you! I added the code and was able to save it without errors. But when I ran a url through schema validator it's still outputting the same price for both USD and CAD, and choosing wrong variation.

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

This is the url I tested with schema validator: https://www.inspirebeautyshop.com/product/suntegrity/5in1-face-sunscreen-spf30-tinted/?attribute_pa_shade-suntegrity=golden-light&attribute_pa_grams=2-oz&currency=CAD

Here's the code:

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!='USD'){
$WOOCS->set_currency('USD');
}
$price_usd = $product->get_price();
$WOOCS->set_currency('CAD');
$price_cad = $product->get_price();
$WOOCS->set_currency($curr);
}
$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'
],
],
];
return $entity;
//}
};
add_filter( 'rank_math/snippet/rich_snippet_product_entity', 'ssc_schema_dual_offers', 999, 2 );

 

 

 

Hello

Ok! Please  drop  me  wp-admin+FTP access - https://share.pluginus.net/image/i20230222134241.png -> https://share.pluginus.net/image/i20230222134615.png

Ok thanks. I dropped the logins. The code from yesterday is still there, I didn't delete it.

Hello

Please  do a test

Thank you for all you help.

I tested and it's now outputting a different price for USD and CAD (not same price for both currencies like before), but for some reason it still outputs the wrong variation price (it choses the lowest price).

The biggest problem though, I'm getting 'critical error' on all single product pages (not on product pages that have variations).

Here's screenshot of the woocommerce error log: https://imgur.com/a/Ron3sj1

According to the error log, the critical error is coming from this line: https://imgur.com/a/kx7N2lk

I've reverted the code back to the original code (and kept a copy of the code you added).

Hello

The problem is with this function -  $product->get_price();    - Perhaps you have third party code that overrides this function (using a hook)

it still outputs the wrong variation price (it choses the lowest price). - This has nothing to do with my plugin, this function displays such a price

Does the old code work for simple products?

Hi thank you for your help.

I don't get the critical error on simple product pages with the old code. Schema also outputs the same price for both currencies for both simple products and variation products with the old code (same problem with both types of product but the new code seemed to fix the schema for variations products, but not the simples products).

Here's a simple product url: https://www.inspirebeautyshop.com/product/noto-botanics/hydra-highlighter-stick/?currency=CAD

Here's screenshot of schema validator (using old code): https://imgur.com/a/y7x3E0w

Hello

Please  do a test

12