Woocommerce add_to_cart non-register visitor not working

I did two tests on my dev site

add_action( "wp_loaded", function() {
    var_dump(WC()->cart->add_to_cart(1353));
});

and

add_action( "wp_footer", function() {
    var_dump(WC()->cart->add_to_cart(1353));
});

Both var_dump a hash, but only the first one actually adds a product to the cart, the second prints the hash but does not add anything.

What is happening is that in the second test some content is already sent to browser and WooCommerce is unable to set a cart cookie.

If you will make sure you are running the add_to_cart() method before content is sent to the browser (for example run it in wp_loaded action) then your code should work fine.