Is it possible to set multi-currencies in one schema in a WooCommerce product?

#428205
Viewing 3 replies - 1 through 3 (of 3 total)
  • Nigel
    Rank Math business

    Hello,

    Thank you for contacting Rank Math for help with setting the schema price for multi currency product schema.

    Rank Math use currency set in your WooCommerce options by default. To set an alternative currency based on a currency switcher setting or query parameter, you will have to create a custom filter to edit. The filter would need to be based of the following code snippet:

    
    /**
     * Filter to change the product schema data.
     * @param array $entity Snippet Data
     * @return array
     */
    add_filter( "rank_math/snippet/rich_snippet_product_entity", function( $entity ) {
     return $entity;
    });
    

    In the snippet above you would need to get the currency name and meta value from your multicurrency plugin, then replace the Rank Math price which is in the $entity variable.

    Hope that helps. Please let us know if you have questions.

    Hi Nigel and Rank Math Team,

    Thanks for your reply.
    Adding the Snippet to make a multi-currency product schema is really a good idea.
    Could you please explain a little bit more with examples of how to write the $entity? Should $entity be an array or others? Is the below right?

    $entity = array(
    ‘currency_code’ => ‘EUR’, //or some multicurrency plugin function to get the currency 3-letter code
    ‘currency_value’=> ‘0.99’, //or some multicurrency plugin function to get the currency value
    );

    Any instructions for the $entity?

    Many thanks

    Hello,

    Looking at the suggested implementation that was referenced in the Google Support thread you would need to convert the current offer to an array and include multiple offers, one for which currency of your products.

    This would also change considerably if you are using variable products which already include the offers array but likely not with the multiple currencies but the variations.

    Regarding the simple products, after converting the offer to an array all the data for each offer would need to be added to the offer from the data in the product.

    If you have a staging website you can var_dump() the entity on that filter and check how the output is generated for the Schema markup.

    Here’s a very simple example that you can use as a basis for this:

    
    add_filter( "rank_math/snippet/rich_snippet_product_entity", function( $entity ) {
    	unset($entity['offers']);
    	$entity['offers'] = [];
    	$entity['offers'] = [
    		[
    			'@type' => 'Offer',
    			'price' => 120,
    			'priceCurrency' => 'USD'
    		],
    		[
    			'@type' => 'Offer',
    			'price' => 120,
    			'priceCurrency' => 'EUR'
    		]
    	];
    	return $entity;
    });
    

    Don’t hesitate to get in touch if you have any other questions.

    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.

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

The ticket ‘Is it possible to set multi-currencies in one schema in a WooCommerce product?’ is closed to new replies.