The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

Retrieving the shipping amount in the receipt template

nealsharmonnealsharmon Member
in Help edited March 2013
<script type="text/javascript" charset="utf-8">

  window.optimizely = window.optimizely || [];

  window.optimizely.push(['trackEvent', 'new_orabrush_revenue', (fc_json.total_price * 100 )]);
 
</script>

I am doing the above to track revenue in pennies but I need the shipping amount as well. How do I get it?
Comments
  • sparkwebsparkweb Member, Integration Developer, FoxyShop, Order Desk
    Try this (assuming version 1.0+ because it's using twig):
    <script type="text/javascript" charset="utf-8">
     
      var my_order_total = "{{ order_total }}"; //twig
      my_order_total = my_order_total.replace("$", "");
      
      window.optimizely = window.optimizely || [];
     
      window.optimizely.push(['trackEvent', 'new_orabrush_revenue', (parseFloat(my_order_total) * 100 )]);
     
    </script>
    
    
  • perfect....thank you
  • OK, I just figured out that this gets fired even when people are viewing their receipt, not just when the transaction occurs. How do I make sure it gets fired only once?
  • fc_adamfc_adam FoxyCart Team
    @nealsharmon,

    Wrap all of that in an 'if first_receipt_display' twig statement like this:
    {% if first_receipt_display %}
    <script type="text/javascript" charset="utf-8">
     
      var my_order_total = "{{ order_total }}"; //twig
      my_order_total = my_order_total.replace("$", "");
     
      window.optimizely = window.optimizely || [];
     
      window.optimizely.push(['trackEvent', 'new_orabrush_revenue', (parseFloat(my_order_total) * 100 )]);
     
    </script>
    {% endif %}
    


    That should only add that code into your receipt if this is the first time the receipt is displayed - as in straight after the transaction is completed.
  • Thanks Adam
Sign In or Register to comment.