Created by
Oscar García Arenas
last modified
| <?php
/**
* Currency Switcher template
*
* This template can be overridden by copying it to yourtheme/woocommerce-product-price-based-on-countries/currency-switcher.php.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WCPBC/Templates
* @version 2.7.1
*/
if ( ! defined( 'ABSPATH' ) || empty( $options ) ) {
exit; // Exit if accessed directly.
}
if ( ! function_exists( 'wcpbc_currency_switcher_script' ) ) {
/**
* Add inline script to handle the currency switcher.
*/
function wcpbc_currency_switcher_script() {
?>
<form method="post" class="wcpbc-widget-currency-switcher" id="wcpbc-widget-currency-switcher-form" style="display: none;">
<input type="hidden" name="wcpbc-manual-country" value="" />
</form>
<script>
jQuery(document).ready(function(){
jQuery(document).on('click', '.wcml_currency_switcher a', function(e) {
e.preventDefault();
if (jQuery(this).is(':disabled') || jQuery(this).parent().hasClass('wcml-cs-active-currency') || jQuery(this).hasClass('wcml-cs-active-currency')) {
return false
} else {
var value = jQuery(this).data('value');
if ( value ) {
jQuery('#wcpbc-widget-currency-switcher-form input[name="wcpbc-manual-country"]').val(value);
jQuery('#wcpbc-widget-currency-switcher-form').submit();
}
}
});
});
</script>
<?php
}
add_action( 'wp_footer', 'wcpbc_currency_switcher_script', 5 );
}
?>
<div class="wcml-dropdown-click product wcml_currency_switcher js-wcml-dropdown-click">
<ul>
<li class="wcml-cs-active-currency">
<a class="js-wcml-dropdown-click-toggle wcml-cs-item-toggle"><?php echo esc_html( $options[ $selected_country ] ); ?></a>
<ul class="wcml-cs-submenu js-wcml-dropdown-click-submenu" style="visibility: hidden;">
<?php foreach ( $options as $key => $value ) : ?>
<li><a href="#" data-value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $value ); ?></a></li>
<?php endforeach; ?>
</ul>
</li>
</ul>
</div>
|