How to display different blocks for mobile and desktops

You’re using the right function to detect the current user agent, otherwise there is another php library you can solicit called : Mobile-detect which help to detect the user agent device and the OS as well :
https://github.com/serbanghita/Mobile-Detect

Mobile_Detect is a lightweight PHP class for detecting mobile devices (including tablets). It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.

And they have already an existing plugin for wordpress :
https://wordpress.org/plugins/tinywp-mobile-detect/

Mobile Detect for WordPress – WordPress has a built-in function (wp_is_mobile()) to detect mobile devices. There is (at least) one catch, though. It considers iPad (iPad pro, and any tablet) as a mobile. So, this 3rd party module changes the way wp_is_mobile() works with the help of Mobile Detect PHP library! Made by Pothi Kalimuthu