Hello. We apologize for the inconvenience you are facing with the %wc_price% variable in the global template causing Google errors due to the currency symbol.
The %wc_price% variable includes the currency symbol by default, which can lead to issues with Google’s structured data requirements. To resolve this problem and ensure compliance with Google’s guidelines, you can follow these steps:
-
Instead of using %wc_price% in your global template, you can manually enter the price without the currency symbol to avoid the “Invalid floating point number in property ‘price'” error.
-
If you need to display the price without the currency symbol in your WooCommerce product schema, you can customize the schema markup to exclude the currency symbol when using the %wc_price% variable.
If you encounter any further difficulties or need assistance with customizing the schema markup, please feel free to provide more details or screenshots, and we will be glad to assist you further.
Sources:
How to Use Product Schema for WooCommerce Products » Rank Math
Google Search Console Missing Field Warning » Rank Math
tôi sử dụng Việt nam đồng “đ” VND và nó cũng báo đơn vị tiền tệ không hợp lệ
Hello,
That variable is not to be used in the Schema because it outputs the currency of the price as well.
To avoid that error, we recommend using the WooCommerce Product Schema which adds all the data of the products automatically and in a formatted way:
https://rankmath.com/kb/woocommerce-product-schema/
However, if you still want to use a price variable in the schema, you may use this filter to register a new variable without the symbol:
add_action( 'rank_math/vars/register_extra_replacements', function(){
rank_math_register_var_replacement(
'price', [
'name' => esc_html__( 'Price', 'rank-math' ),
'description' => esc_html__( 'Output the price of the product', 'rank-math' ),
'variable' => 'price',
'example' => price_callback(),
],
'price_callback'
);
});
function price_callback() {
$product = wc_get_product(get_queried_object_id());
$price = '0';
if( $product ) {
$price_vat = wc_get_price_including_tax( $product );
$price = number_format($price_vat, 2);
}
return $price;
}
You can use one of the methods mentioned here to add the filter to the website: https://rankmath.com/kb/filters-hooks-api-developer/
After that, you can switch to the variable %price%
in the Schema to get the correct values.
Hope that helps.
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.