Is it possible to get those values inside of function and use those outside of function here is my code:
If you put return $total at the very end of the function (right before the last curly brace), you should be able to use the result.
return $total