id = 'currency_countries';
$this->desc = __( 'Countries', 'currency-switcher-woocommerce' );
parent::__construct();
add_action( 'admin_init', array( $this, 'process_buttons' ) );
}
/**
* process_buttons.
*
* @version 2.0.0
* @since 2.0.0
*/
function process_buttons( $settings ) {
if ( isset( $_GET['alg_auto_assign_countries_to_currencies'] ) && check_admin_referer( 'alg_auto_assign_countries_to_currencies' ) ) {
// Auto Assign Countries
foreach ( alg_get_enabled_currencies( false ) as $currency ) {
if ( '' != $currency ) {
$currency_countries = alg_get_currency_countries();
update_option( 'alg_currency_switcher_currency_countries_' . $currency, $currency_countries[ $currency ] );
}
}
wp_safe_redirect( remove_query_arg( 'alg_auto_assign_countries_to_currencies' ) );
exit();
} elseif ( isset( $_GET['alg_reset_currencies_countries'] ) && check_admin_referer( 'alg_reset_currencies_countries' ) ) {
// Reset Countries
foreach ( alg_get_enabled_currencies( false ) as $currency ) {
if ( '' != $currency ) {
update_option( 'alg_currency_switcher_currency_countries_' . $currency, array() );
}
}
wp_safe_redirect( remove_query_arg( 'alg_reset_currencies_countries' ) );
exit();
}
}
/**
* get_currency_countries_settings.
*
* @version 2.16.0
* @since 2.0.0
* @todo check if "geolocate" option in WooCommerce is really required, if so - fix the message
* @todo (maybe) fix/expand description for "alg_wc_currency_switcher_currency_countries_options"
*/
public static function get_currency_countries_settings( $settings ) {
$desc = '';
if ( ! in_array( get_option( 'woocommerce_default_customer_address' ), array( 'geolocation_ajax', 'geolocation' ) ) ) {
$desc = ' ' . '' . sprintf(
__( 'Important: "Default Customer Location" is not set to "Geolocate" or "Geolocate (with page caching support)" in WooCommerce > Settings > General.', 'currency-switcher-woocommerce' ),
admin_url( 'admin.php?page=wc-settings&tab=general' ) )
. '';
}
if ( get_option( 'wpwham_currency_switcher_version' ) !== 'legacy' ) {
$desc .= '
';
}
$all_currencies = get_woocommerce_currencies();
$settings = array_merge( $settings, array(
array_merge(
array(
'title' => __( 'Set Currency by Country', 'currency-switcher-woocommerce' ),
'type' => 'alg_title',
'desc' => __( 'If enabled, automatically set the currency to match the country your visitor is in (based on the client\'s IP address).', 'currency-switcher-woocommerce' )
. '