Dá uma vista de olhos:
http://www.php.net/manual/en/book.geoip.phpUma solução escrita agora rapidamente. Basicamente a ideia é colocares todos os anúncios separados numa pasta chamada
ads (podes também definir esta pasta, criando uma opção no WP).
Por exemplo para um mesmo anúncio chamado
sidebar criarias um ficheiro
sidebar_pt.php, outro
sidebar_br.php e ainda um
sidebar_default.php. Se o visitante for de Portugal, a função carrega o 1º, se do Brasil o 2º, senão carrega o default.
Onde queres que os anúncios te apareçam, basta chamares no tema:
show_ad_by_country( 'sidebar' );
show_ad_by_country( 'footer' );
O argumento que passares à função será o prefixo do ficheiro (sidebar_pt.php/footer_pt.php).
<?php
if( !function_exists( 'show_ad_by_country' ) ){
/**
* Shows a given ad depending on the geolocation
* of the user. All the ads should be placed within
* an independent file that has the following
* format {prefix}_{2 letter ISO}.php
*
* @param String $prefix The file prefix
* @return boolean
*/
function show_ad_by_country($prefix = ''){
// The geoip library is required
if( !in_array( 'geoip', get_loaded_extensions() ) ){
return false;
}
// Get the client's IP and country
$client_ip = $_SERVER['REMOTE_ADDR'];
$country = geoip_country_code_by_name( $client_ip );
// Define the ads location
if( !( $location = get_option( 'showad_files_location' ) ) ){
$location = get_stylesheet_directory() . '/ads';
}
// Try to load the file
$file = $location . '/' . $prefix . '_' . strtolower( $country ) . '.php';
$default = $location . '/' . $prefix . '_default.php';
if( file_exists( $file ) ){
include $file;
return true;
} elseif ( file_exists ( $default ) ){
include $default;
return true;
}
return false;
}
}
Não testei o código, mas deve estar a funcionar. Também podes fazer o mesmo através de Javascript - qualquer browser decente também te oferece a localização do utilizador (se bem que é um pouco mais "intrusivo", porque tens de pedir autorização ao mesmo).