-
I am using global product schema for all my products, I use variable %wc_price% to set the price in the schema. However, I got a notification (invalid price format) in google search console, I checked the code of the schema and found that the price code is writen like this
“price”: “$4,318”,
The product price is 4,318 but I don’t know why this ($), but it seems it causes a problem.
I searched for here at the support forum and saw a similar problem and the rank math support agent suggest to use the below filter then use variable %price%, instead of %wc_price%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;
I applied the filter code and replaced the variable, but got a new weird problem. I see that the price of the products are not the same as actual
For example)
a product with price: 1,120
but it appears at the schema code as:
“price”: “1,491.00”,I don’t where is the problem, but I think it is related to the hook filter I used, it might be designed specifically for a certain reason and client si it didn’t work with me.
I hope you can help me fix it
Thanks
The ticket ‘The woocommerce product schema give me inaccurate price for when set it up’ is closed to new replies.