elementor hide button if input empty

PHP
/* Hide Elementor buttons if their input is empty */
/* Perfect for using with templates and loops! */

// Add to the end of your theme's functions.php file
// Or, if you have one, add to your child theme's functions.php file

// Hook to allow Elementor to modify data
add_filter('elementor/widget/render_content',
    function ($content, $widget) {
        $settings = $widget->get_settings_for_display();
      
     	 // Determine if the button type has been set
        if (isset($settings['button_type'])) {
            // Retrieve input data from the button widget.
            $link = $widget->get_settings_for_display("link");
            $text = $widget->get_settings_for_display("text");

              // Render nothing if the URL or Text is empty.
              if (empty($link['url']) || empty($text)) {
                  return '';
            }
        }

        // If button has URL & Text inputs, render content as usual.
        return $content;
    }, 10, 3);
Source

Also in PHP: