Price mismatch in JSON-LD data due to tax

#427990
  • Resolved Easypeasy
    Rank Math free

    Hi,
    there is a price mismatch due to taxes. There was already an issue about this on Github: https://github.com/woocommerce/woocommerce/issues/18852

    There is also a workaround for this problem:
    function priceWithTaxesSEO( $markup, $product ) {
    if ( is_product() ) {
    $precioConIVA = (float)$markup['offers'][0]['price'] + ( (float)$markup['offers'][0]['price'] * 0.21 );
    $precioConIVA = number_format($precioConIVA, 2, '.', '');

    $markup['offers'][0]['price'] = $precioConIVA;
    $markup['offers'][0]['priceSpecification']['price'] = $precioConIVA;
    // Especifica si el impuesto al valor agregado (IVA) aplicable está incluido en la especificación de precio o no.
    $markup['offers'][0]['priceSpecification']['valueAddedTaxIncluded'] = 'true';
    }

    return $markup;
    }
    add_filter( 'woocommerce_structured_data_product', 'priceWithTaxesSEO', 100, 2 );

    Since Rank Math overwrites the structured data, this workaround does not work.
    Can you please tell me how to override the behavior of Rank Math?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hello,

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

    Rank Math doesn’t override the data structure from Woocommerce as we have our own JSON-ld schema.

    Does your filter work when you deactivate our plugin? Let us know. We are here to help.

    Hi Jeremy,
    yes it works if I deactivate rank math. That’s why I thought rank math is overriding the data

    Hello,

    I apologize for the confusion.

    When you insert a Woocommerce Product schema or a custom Product schema via Rank Math, the default schema from Woocommerce will be removed so this will require you to edit the individual product and remove any existing Woocommerce Product schema or Product schema generated by Rank Math.

    After doing so, the default Woocommerce schema will be generated and you can make use of that filter code.

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Hi,
    is there a way to hook into the WooCommerce Product schema?
    I have the following in mind:

    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
    	if ( is_product() ) {
    		$priceWithVAT = (float)$entity['offers'][0]['price'] + ( (float)$entity['offers'][0]['price'] * 0.19 );
    		$priceWithVAT = number_format($priceWithVAT, 2, '.', '');
    
    		$entity['offers'][0]['price'] = $priceWithVAT;
    		$entity['offers'][0]['priceSpecification']['price'] = $priceWithVAT;
    		//Specifies whether the applicable value added tax (VAT) is included in the price specification or not.
    		$entity['offers'][0]['priceSpecification']['valueAddedTaxIncluded'] = 'true';
    	}
    	return $entity;
    } );

    But this is actually not working.
    Would be great if I could get this to work with the WooCommerce Product schema. Maybe you have a hint for me, where my error lies?

    Got it working:

    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
    	//The Structured Data shows the net price for Google, etc. This code shows the gross price (19% VAT)
    	//https://github.com/woocommerce/woocommerce/issues/18852
    	$priceWithVAT = (float)$entity['offers']['price'] + ( (float)$entity['offers']['price'] * 0.19 );
    	$priceWithVAT = number_format($priceWithVAT, 2, '.', '');
    
    	$entity['offers']['price'] = $priceWithVAT;
    	$entity['offers']['priceSpecification']['price'] = $priceWithVAT;
    	//Specifies whether the applicable value added tax (VAT) is included in the price specification or not.
    	$entity['offers']['priceSpecification']['valueAddedTaxIncluded'] = 'true';
    
    	return $entity;
    });

    Thanks!

    Hello,

    I am glad that you are able to find a workaround and thanks for sharing your code here.

    If you have further issues with our plugin, let us know. we are here to help.

    Thank you.

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

You must be logged in to reply to this ticket.