/** * Enqueue Public Scripts and Styles * * Handles to enqueue scripts and styles for public side * * @package Easy Digital Downloads - Currency Converter * @since 1.0.0 */ public function edd_currency_public_scripts() { global $edd_options, $post; wp_register_script('edd-currency-public-script', EDD_CURRENCY_URL . 'includes/js/edd-currency-public.js', array('jquery'), null); wp_localize_script('edd-currency-public-script', 'EDDCurrency', array('detected_currency' => edd_currency_get_detected_currency())); wp_enqueue_script('edd-currency-public-script'); wp_register_style('edd-currency-public-style', EDD_CURRENCY_URL . 'includes/css/edd-currency-public.css', array(), null); wp_enqueue_style('edd-currency-public-style'); }
/** * Show Currency Detection Message * * Handles to show currency detection * message to end user * * @package Easy Digital Downloads - Currency Converter * @since 1.0.0 **/ public function edd_currency_detection_popup() { global $edd_options; //check prompt user detection is activated or not if (isset($edd_options['prompt_user_detection']) && !empty($edd_options['prompt_user_detection']) && !isset($_COOKIE['edd-currency-detected'])) { $currency_detected = edd_currency_get_detected_currency(); if (!empty($currency_detected)) { $currencies = edd_currency_get_currency_list(); if (isset($currencies[$currency_detected])) { $detected_currency = $currencies[$currency_detected]; } else { $detected_currency = ''; } //check detected currency has rate if (!empty($detected_currency)) { ?> <div class="edd-currency-detection-prompt-popup"> <div class="edd-currency-dection-close"> <strong><a title="<?php _e('Close', 'eddcurrency'); ?> " href="javascript:void(0);" class="edd-currency-close-popup"><?php _e('X', 'eddcurrency'); ?> </a></strong> </div> <div class="edd-currency-detection-popup-msg-wrap"> <?php _e('Hi! We have detected your currency as', 'eddcurrency'); echo '<span class="edd-currency-detection-popup-msg"> '; esc_html_e($detected_currency['symbol'] . ' ' . $detected_currency['label'] . ' ' . $detected_currency['code'], 'eddcurrency'); echo '</span>'; _e('. Is this correct?', 'eddcurrency'); ?> </div> <div class="edd-currency-detected-buttons"> <button type="button" class="edd-currency-detect-button edd-currency-button-convert-yes"><?php _e('Yes', 'eddcurrency'); ?> </button> <button type="button" class="edd-currency-detect-button edd-currency-button-convert-no"><?php _e('No', 'eddcurrency'); ?> </button> </div> <?php $this->edd_currency_select_message(); ?> </div> <?php } //end if to check detected currency has rate } //end if to check detected currency is not empty } //end if to check prompt user detection is enabled or not }
/** * Get Stored Currency in Cookies * * Handles to return stored currency in Cookies * * @package Easy Digital Downloads - Currency Converter * @since 1.0.0 **/ function edd_currency_get_stored_currency() { global $edd_options; //get stored currency in backend settings page $stored_currency = edd_currency_get_base_currency(); //check if cookie is set or not if (isset($_COOKIE['edd-currency'])) { $stored_currency = $_COOKIE['edd-currency']; } else { if (isset($edd_options['currency_detection']) && !empty($edd_options['currency_detection']) && empty($edd_options['prompt_user_detection']) && !isset($_COOKIE['edd-currency-detected'])) { $currency_detected = edd_currency_get_detected_currency(); //check detected currency is not empty if (!empty($currency_detected)) { $stored_currency = $currency_detected; } //end it to check detected currency is not empty } } $currency_list = edd_currency_get_currency_list(); //check if sotred currency has rate if (!isset($currency_list[$stored_currency])) { $stored_currency = edd_get_currency(); } return apply_filters('edd_currency_get_saved_currency', $stored_currency); }