phpwordpresswoocommercegoogle-merchant-center

WooCommerce structured data (schema) price modification (net/gross)


I have a problem with the data retrieved by Google Merchant in the structured data on my page the price is net price, I would like the gross price with VAT to be displayed there.

On the product page the price is the gross price but in the structured data the price is the net price, I would like the gross price with VAT to be displayed there.

What I mean by this is the price given in "offers" -> "price".

enter image description here

Is there an easy way to replace this price with the gross price regardless of region? (Changing the WooCommerce settings to provide the gross price is not an option for me).


Solution

  • I already have the answer to my question, I found it on GitHub in this thread. The author of the code is user Cherrerotinoco, and thanks are due to him.

    I have also pasted its code below:

    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 );