|
|
@ -5,8 +5,9 @@ global $site_env; |
|
|
|
$site_env = new SiteEnvironment(); // глобальный объект выполняющий проверку по домену |
|
|
|
$site_env = new SiteEnvironment(); // глобальный объект выполняющий проверку по домену |
|
|
|
class SiteEnvironment |
|
|
|
class SiteEnvironment |
|
|
|
{ |
|
|
|
{ |
|
|
|
public string $mode; |
|
|
|
public string $site_mode; |
|
|
|
public string $region; |
|
|
|
public string $site_region; |
|
|
|
|
|
|
|
public bool $is_gp_test_mode; |
|
|
|
|
|
|
|
|
|
|
|
public function __construct(string $host = null) |
|
|
|
public function __construct(string $host = null) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -23,12 +24,15 @@ class SiteEnvironment |
|
|
|
|
|
|
|
|
|
|
|
$this->site_mode = $config['mode']; |
|
|
|
$this->site_mode = $config['mode']; |
|
|
|
$this->site_region = $config['region']; |
|
|
|
$this->site_region = $config['region']; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Логика тестового режима |
|
|
|
|
|
|
|
$this->is_gp_test_mode = (isset($_GET['gp-test']) && $_GET['gp-test'] == '1') || (is_user_logged_in() && current_user_can('administrator')); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
add_filter('timber/twig', function (\Twig\Environment $twig) { |
|
|
|
add_filter('timber/twig', function (\Twig\Environment $twig) { |
|
|
|
global $site_env; |
|
|
|
global $site_env; |
|
|
|
|
|
|
|
|
|
|
@ -77,26 +81,16 @@ function custom_canonical_url() { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Добавление событий контрибуции для FP Pixel |
|
|
|
* Добавление событий контрибуции для FP Pixel |
|
|
|
* только на боевом сайте АЕ |
|
|
|
* Только на боевом сайте AE, с учетом тестового режима через site_env->is_gp_test_mode |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
// if ($site_env->site_mode == 'production' && $site_env->site_region == 'ae') { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Проверка на тестовый режим для метрик |
|
|
|
if (isset($site_env) && $site_env->site_mode === 'production' && $site_env->site_region === 'ae' && !$site_env->is_gp_test_mode) { |
|
|
|
function is_gp_test_mode() { |
|
|
|
|
|
|
|
if (isset($_GET['gp-test']) && $_GET['gp-test'] == '1') { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (is_user_logged_in() && current_user_can('administrator')) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
add_action('wp_footer', 'add_facebook_pixel_events'); |
|
|
|
add_action('wp_footer', 'add_facebook_pixel_events'); |
|
|
|
function add_facebook_pixel_events() { |
|
|
|
function add_facebook_pixel_events() { |
|
|
|
if (is_gp_test_mode()) return; |
|
|
|
global $site_env, $product; |
|
|
|
|
|
|
|
|
|
|
|
global $product; |
|
|
|
if ($site_env->is_gp_test_mode) return; |
|
|
|
|
|
|
|
|
|
|
|
// 1. ViewContent |
|
|
|
// 1. ViewContent |
|
|
|
if (is_product() && $product && $product->get_price() > 0) { |
|
|
|
if (is_product() && $product && $product->get_price() > 0) { |
|
|
@ -237,7 +231,8 @@ function custom_canonical_url() { |
|
|
|
|
|
|
|
|
|
|
|
add_action('woocommerce_thankyou', 'send_purchase_to_metrika'); |
|
|
|
add_action('woocommerce_thankyou', 'send_purchase_to_metrika'); |
|
|
|
function send_purchase_to_metrika($order_id) { |
|
|
|
function send_purchase_to_metrika($order_id) { |
|
|
|
if (is_gp_test_mode()) return; |
|
|
|
global $site_env; |
|
|
|
|
|
|
|
if ($site_env->is_gp_test_mode) return; |
|
|
|
|
|
|
|
|
|
|
|
if (!$order_id) return; |
|
|
|
if (!$order_id) return; |
|
|
|
|
|
|
|
|
|
|
@ -288,7 +283,8 @@ function custom_canonical_url() { |
|
|
|
</script> |
|
|
|
</script> |
|
|
|
<?php |
|
|
|
<?php |
|
|
|
} |
|
|
|
} |
|
|
|
// } |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Отключаем кэширование для страниц товаров |
|
|
|
// Отключаем кэширование для страниц товаров |
|
|
|
add_action('template_redirect', function() { |
|
|
|
add_action('template_redirect', function() { |
|
|
|