order_total without currency symbol in Twig receipt template

sblombergsblomberg Member
in Help edited January 2014
Hey FoxyCart support,

I would like to be able to access the order total in my receipt template without the currency symbol. I found this forum post from last year that lists a Javascript solution, but that unfortunately doesn't help me as I need the variable at page run time.

The reason JS doesn't work is that I'm loading an affiliate script with a <script> element. Here's the script integration instructions I'm attempting to implement. Here's what my script looks like thus far:
<script id="_sspx2" 
data-rid="REDACTED" 
data-key2="REDACTED" 
data-tx="^^order_id^^" 
data-amount="{{ order_total }}" 
data-currency="USD" 
data-email="{{ email }}" 
data-pub="{{ sspx }}" 
src="//dfhmmkrdfueer.cloudfront.net/generic/sale.1.0.2.min.js" 
async 
defer></script>

Everything's working except the data-amount, as that attribute requires order total without the currency symbol. {{ order_total }} doesn't work because it includes the dollar sign as well.

I've attempted using the Twig slice function to return everything except the first character like so:
{{ order_total[1:] }}

However, doing so doesn't let me save my receipt template, as it returns this error: Filter "slice" is not allowed

Any other Twig variables/filters/functions I can use to get the order total without currency symbol?

Thanks!
Comments
  • fc_adamfc_adam FoxyCart Team
    @sblomberg,

    Good question. In an upcoming version we'll default all currency values to their raw amount without any formatting with currency symbols etc - but for now you need to use the 'replace' twig function: https://forum.foxycart.com/discussion/7014/need-to-display-quantity-total-in-email#Item_8
  • Thanks much Adam - I was able to use the Twig 'replace' filter as recommended to remove the dollar sign and thousands comma from the order_total. Here's the code I used for anyone else who may find it useful:

    {% set my_total = order_total|replace({'$': '', ',': ''}) %}
    

    Once the variable is set, it's accessed like so in the FoxyCart template:

    {{ my_total }}
    
Sign In or Register to comment.