Using wp_enqueue_script on scripts that contain PHP

If you’re outputting the script in the footer, you can call wp_localize_script at any point after your script is enqueued but before the script is output on wp_footer priority 20.

function wp_enqueue_woocommerce_style(){
    wp_enqueue_script(
        'chroma_js',
        get_template_directory_uri() . '/js/chroma.js',
        '',
        '1.1',
        true
    );
}
add_action( 'wp_enqueue_scripts', 'wp_enqueue_woocommerce_style' );

function wp_localize_woocommerce_style(){
    $array = array(
        'var1' => $var1,
        'var2' => $var2
    );
    wp_localize_script( 'chroma_js', 'php_vars', $array );
}
add_action( 'wp_footer', 'wp_localize_woocommerce_style', 0 );