drupaldrupal-modules

How to display product.variation_price without currency in Drupal Commerce?


I need to display product price in the template commerce-product.html.twig

The variable {{ product.variation_price }} is rendered as currency and number e.g. USD700

And I can't understand how to display only number without currency?


Solution

  • Well, I've just found the answer by myself.

    If a product has only one variation, we can get its price as number in Twig like:

    {% set price_number = product.variation_price['#items'].0.number %}
    

    Now, according to Displaying prices we can print it without fraction part like:

    {{ price_number|number_format(0) }}