/**
  * Get custom curencies from custom post type and return the array of currencies for which the rates are set
  * 
  * @package Easy Digital Downloads - Currency Converter
  * @since 1.0.0
  */
 public function edd_currency_get_data()
 {
     global $edd_options;
     $exchange_rates = edd_currency_get_exchange_rates();
     $currency_data = $args = array();
     if ($this->edd_currency_check_open_exchange()) {
         if (isset($edd_options['exchange_rates_method']) && $edd_options['exchange_rates_method'] == 'custom_rates') {
             $args['meta_query'][] = array('key' => '_edd_currency_custom_rate', 'value' => '', 'compare' => '!=');
         }
         $args['order'] = 'ASC';
         $args['orderby'] = 'menu_order';
         $currency_data = $this->edd_currency_get_currency_post_data($args);
         // Code check for currency rate is empty
         foreach ($currency_data as $currency_key => $currency_value) {
             if (isset($currency_value['post_title']) && !empty($currency_value['post_title']) && !isset($exchange_rates[$currency_value['post_title']])) {
                 unset($currency_data[$currency_key]);
             }
         }
     }
     return $currency_data;
 }
/**
 * Check Base Currency Rate
 * 
 * Handles to check base currency rate
 * 
 * @package Easy Digital Downloads - Currency Converter
 * @since 1.0.0
 **/
function edd_currency_check_base_currency_has_rate()
{
    $check = false;
    $base_currency_code = edd_get_currency();
    $exchange_rates = edd_currency_get_exchange_rates();
    if (isset($exchange_rates[$base_currency_code])) {
        $check = true;
    }
    return apply_filters('edd_currency_check_base_currency_rate', $check);
}
 /**
  * Adding Hooks
  *
  * Adding proper hoocks for the public pages.
  *
  * @package Easy Digital Downloads - Currency Converter
  * @since 1.0.0
  */
 public function add_hooks()
 {
     global $edd_options;
     //check base currency has rate & is not admin side and calling ajax
     if (edd_currency_check_base_currency_has_rate() && !is_admin() || defined('DOING_AJAX') && DOING_AJAX) {
         $currency_data = $this->model->edd_currency_get_data();
         if (!empty($currency_data)) {
             // Check currencies data are not empty
             // mark up for popup
             add_action('wp_footer', array($this, 'edd_currency_list_popup'));
             // Add filter to add class in nav menu
             add_filter('nav_menu_css_class', array($this, 'edd_currency_nav_menu_css_class'), 10, 2);
             add_filter('page_css_class', array($this, 'edd_currency_page_css_class'), 10, 2);
         }
         $currency = edd_get_currency();
         // get edd base currency
         $stored_currency = edd_currency_get_stored_currency();
         // get cuurency which is set in the cookie
         $exchange_rates = edd_currency_get_exchange_rates();
         // get exchance rates array
         add_filter('edd_' . strtolower($currency) . '_currency_filter_before', array($this, 'edd_currency_change_before_format'), 10, 3);
         add_filter('edd_' . strtolower($currency) . '_currency_filter_after', array($this, 'edd_currency_change_after_format'), 10, 3);
         if (isset($edd_options['display_cart_notification']) && $edd_options['display_cart_notification'] == '1' && $stored_currency != $currency && $this->model->edd_currency_check_open_exchange() && isset($exchange_rates[$stored_currency])) {
             // Add message for checkout
             add_action('edd_before_purchase_form', array($this->render, 'edd_currency_checkout_message_content'));
         }
     }
     //add action to show currency popup markup
     add_action('wp_footer', array($this->render, 'edd_currency_saved_popup'));
     //add action to show detection prompt user message
     add_action('wp_footer', array($this->render, 'edd_currency_detection_popup'));
 }