Pennies from ^^order_total^^ in the receipt

nealsharmonnealsharmon Member
in Help edited February 2013
How can I get the order total in pennies? $10.50 becomes 1050

I need it for Optimizely tracking, which requires an integer that is in pennies.
<script>
window.optimizely = window.optimizely || [];
window.optimizely.push(['trackEvent', 'new_orabrush_revenue', ^^order_total^^]);
</script>

Anyone know how to make this calculation in twig?

This is invalid...which I got from twig documentation.
<script>
window.optimizely = window.optimizely || [];
window.optimizely.push(['trackEvent', 'new_orabrush_revenue', {{ ^^order_total^^ * 100 }}]);
</script>
Comments
  • fc_adamfc_adam FoxyCart Team
    @nealsharmon,

    You're very close. Try this instead:
    {{ order_total * 100 }}
    
  • That gave me 0
  • The dollar sign is included in order_total. How do I get it without the dollar sign?
  • fc_adamfc_adam FoxyCart Team
    @nealsharmon,

    Oh you're right - that is returning with the currency sign.

    I'll dig into if we have a way to get just the raw number within Twig, but for now you can achieve this with javascript:
    <script type="text/javascript">
    jQuery(document).ready(function() {
      window.optimizely = window.optimizely || [];
      window.optimizely.push(['trackEvent', 'new_orabrush_revenue', (fc_json.total_price * 100 )]);
    });
    </script>
    
  • Thank you. That worked.
  • lukeluke FoxyCart Team
    Thanks for bringing this up. I've been thinking about it more and more for not only Twig, but also our API in that some people need raw numbers and others need formatted strings for display and some people need both. We haven't yet landed on a solution, but we're definitely keeping it in mind.
  • Awesome. Really appreciate it Luke
Sign In or Register to comment.