add variable to actions/functions across different files (woocommerce)

Not really.

Anything that loads a template in WordPress is ultimately an include() or require() and only the variables in the caller function scope (and global scope of course) are passed on to the included file:

function foo() {
    $bar = 1;
    include( '/path/to/template.php' );
}

$baz = 2;
foo();

// template.php:
echo $bar; // 1
echo $baz; // undefined

So to make something like you described work, you’ll have to change the behavior of Core’s load_template() function which performs the actual require(). But there are other ways. Here are a couple:

Global scope (nobody likes global scope):

$GLOBALS['myvar'] = 1; // will be accessible from anywhere

Static class properties:

class My_Class {
    public static $myvar;
}

My_Class::$myvar = 1;

My_Class::$myvar will be accessible in your templates, provided that you declared the class and changed the static variable prior to loading your template. It’s almost like using the global scope but cleaner.

Hope that helps!