/**
  * Front-end display of widget.
  *
  * @param array $widget_args Widget arguments.
  * @param array $instance Saved values from database.
  * @see WP_Widget::widget()
  */
 public function widget($widget_args, $instance = array())
 {
     $this->load_css();
     $this->load_js();
     if (!is_array($widget_args)) {
         $widget_args = array();
     }
     $widget_args = array_merge($instance, $widget_args);
     $widget_type = get_value('widget_type', $widget_args, self::TYPE_DROPDOWN);
     $widget_template_name = $this->get_widget_template($widget_type);
     $widget_template_file = WC_Aelia_Tax_Display_By_Country::instance()->get_template_file($widget_template_name);
     // Debug
     //var_dump($widget_template_name, $widget_template_file);
     if (empty($widget_template_file)) {
         $this->display_invalid_widget_type_error($widget_type);
     } else {
         $widget_args['title'] = apply_filters('wc_aelia_tdbc_billing_country_selector_widget_title', get_value('title', $widget_args));
         $widget_args['countries'] = apply_filters('wc_aelia_tdbc_billing_country_selector_widget_countries', $this->WC()->countries->get_allowed_countries());
         $selected_country = get_value('selected_country', $widget_args);
         if (empty($selected_country)) {
             $widget_args['selected_country'] = WC_Aelia_Tax_Display_By_Country::instance()->get_billing_country();
         }
         // Display the Widget
         include $widget_template_file;
     }
 }
        // If we are on checkout page and the billing country is requested for
        // current user, retrieve the one he (eventually) selected
        if ($meta_key === 'billing_country' && (defined('WOOCOMMERCE_CHECKOUT') || is_checkout()) && $user_id === wp_get_current_user()->ID) {
            return $this->get_billing_country();
        }
        return $value;
    }
    /**
     * Sets hooks to register shortcodes.
     */
    protected function set_shortcodes_hooks()
    {
        // Shortcode to render the billing country selector
        add_shortcode('aelia_tdbc_billing_country_selector_widget', array('Aelia\\WC\\TaxDisplayByCountry\\Billing_Country_Selector_Widget', 'render_billing_country_selector'));
    }
    /**
     * Registers a widget class.
     *
     * @param string widget_class The class to register.
     * @param bool stop_on_error Indicates if the function should raise an error
     * if the Widget Class doesn't exist or cannot be loaded.
     * @return bool True, if the Widget was registered correctly, False otherwise.
     */
    protected function register_widget($widget_class, $stop_on_error = true)
    {
        register_widget($widget_class);
        return true;
    }
}
$GLOBALS[WC_Aelia_Tax_Display_By_Country::$plugin_slug] = WC_Aelia_Tax_Display_By_Country::factory();