我正在尝试根据当前订单的结算位置更改WooCommerce通知电子邮件中的电子邮件页脚内容。这样做的原因是,如果订单来自新西兰,澳大利亚或欧洲的人,我需要显示不同的经销商业务详情。
我有一个存储用户当前区域的cookie。这是使用此服务设置的:http://ipinfo.io/
functions.php文件代码:
add_action( 'init', 'location_setcookies' );
function gng_setcookies() {
if(isset($_COOKIE['country_set'])) {
$country_set = $_COOKIE['country_set'];
if($country_set == true) {
$cur_country = $_COOKIE['cur_country'];
$cur_region = $_COOKIE['cur_region'];
}
} else {
$country = file_get_contents("http://ipinfo.io/{$_SERVER['REMOTE_ADDR']}/country");
$cur_country = trim($country);
setcookie( 'country_set', 'false', time() + 3600, COOKIEPATH, COOKIE_DOMAIN );
if($cur_country == "NZ") {
setcookie( 'cur_country', $cur_country, time() + 3600, COOKIEPATH, COOKIE_DOMAIN );
setcookie( 'cur_region', 'NZ', time() + 3600, COOKIEPATH, COOKIE_DOMAIN );
$cur_region = "NZ";
} elseif ($cur_country == "AU") {
setcookie( 'cur_country', $cur_country, time() + 3600, COOKIEPATH, COOKIE_DOMAIN );
setcookie( 'cur_region', 'AU', time() + 3600, COOKIEPATH, COOKIE_DOMAIN );
$cur_region = "AU";
} elseif ($cur_country == "AT" || "BE" || "BG" || "CY" || "CZ" || "DK" || "EE" || "FI" || "FR" || "DE" || "GR" || "HU" || "IE" || "IT" || "LV" || "LT" || "LU" || "MT" || "NL" || "PL" || "PT" || "RO" || "SK" || "SI" || "ES" || "SE" || "GB") {
setcookie( 'cur_country', $cur_country, time() + 3600, COOKIEPATH, COOKIE_DOMAIN );
setcookie( 'cur_region', 'EU', time() + 3600, COOKIEPATH, COOKIE_DOMAIN );
$cur_region = "EU";
} else {
setcookie( 'cur_country', 'NZ', time() + 3600, COOKIEPATH, COOKIE_DOMAIN );
setcookie( 'cur_region', 'NULL', time() + 3600, COOKIEPATH, COOKIE_DOMAIN );
$cur_region = "NULL";
}
}
}
add_filter( 'cur_region_val', 'return_cur_region_val' );
function return_cur_region_val( $arg = '' ) {
if(isset($_COOKIE['country_set'])) {
$cur_region = $_COOKIE['cur_region'];
return $cur_region;
} else {
$country = file_get_contents("http://ipinfo.io/{$_SERVER['REMOTE_ADDR']}/country");
$cur_country = trim($country);
if($cur_country == "NZ") {
return "NZ";
} elseif ($cur_country == "AU") {
return "AU";
} elseif ($cur_country == "AT" || "BE" || "BG" || "CY" || "CZ" || "DK" || "EE" || "FI" || "FR" || "DE" || "GR" || "HU" || "IE" || "IT" || "LV" || "LT" || "LU" || "MT" || "NL" || "PL" || "PT" || "RO" || "SK" || "SI" || "ES" || "SE" || "GB") {
return "EU";
} else {
return "NULL";
}
}
}
我已尝试使用Cookie值来确定应显示哪些电子邮件页脚内容但它无法按预期工作。
email-footer.php代码:
$cur_region = apply_filters( 'cur_region_val', '' );
if($cur_region == 'NZ') {
echo '<p>New Zealand Business Details</p>';
} elseif($cur_region == 'AU') {
echo '<p>Australian Business Details</p>';
} elseif($cur_region == 'EU') {
echo '<p>Europe Business Details</p>';
}
有人可以指出我正确的方向。我假设我需要使用WooCommernce挂钩或以某种方式使用订单对象来检索当前订单的结算位置。
编辑:我打算使用订单发货地点,但我认为最好使用订单结算地点或我的Cookie值。由于