Checkout Page Php Function

I would like your help with a problem that i have when i'm trying to execute a php function in the checkout page.
I have the code below which is added on the file:

The code and the function is running fine without any errors. The problem is that every time a customer change the payment or the shipping method, the function runs again and again after the ajax load.
Is there any other .tpl file that i can add my script in order to be executed only once, or maybe any way to stop if from running again after ajax calls?


{if !$smarty.const.AJAX_REQUEST}


Thank you a lot eComLabs, that worked perfectly!