How to call a function from functions.php with ajax?

You mean need to display the custom code your ajax add to cart button right? . add this below code your current active function.php file

add_action( 'wp_ajax_woocommerce_before_add_to_cart_button', 'hello_world', 10);
add_action( 'wp_ajax_nopriv_woocommerce_before_add_to_cart_button', 'hello_world', 10);
add_action( 'woocommerce_before_add_to_cart_button', 'hello_world', 10);
function hello_world() {
$var1 = 'Hello World!';
echo $var1;
echo "The time is " . date("h:i:sa");
}