diff --git a/wp-content/themes/cosmopet/global-functions/multisite-functions.php b/wp-content/themes/cosmopet/global-functions/multisite-functions.php
index 60c0108..be962a2 100644
--- a/wp-content/themes/cosmopet/global-functions/multisite-functions.php
+++ b/wp-content/themes/cosmopet/global-functions/multisite-functions.php
@@ -2,15 +2,13 @@
/* Start | Работа с проверкой мультисайтовости и стендов */
global $site_env;
-$site_env = new SiteEnvironment(); // глобальный объект выполняющий проверку по домену
-class SiteEnvironment
-{
+$site_env = new SiteEnvironment();
+class SiteEnvironment {
public string $site_mode;
public string $site_region;
public bool $is_gp_test_mode;
- public function __construct(string $host = null)
- {
+ public function __construct(string $host = null) {
$map = [
'cosmopet.ru' => ['mode' => 'production', 'region' => 'ru'],
'cosmopet.ae' => ['mode' => 'production', 'region' => 'ae'],
@@ -18,275 +16,65 @@ class SiteEnvironment
'cosmopet-test-ru.cp.good-production.xyz' => ['mode' => 'develope', 'region' => 'ru'],
'cosmopet-test-ae.cp.good-production.xyz' => ['mode' => 'develope', 'region' => 'ae'],
];
-
$host = strtolower($host ?: $_SERVER['SERVER_NAME']);
$config = $map[$host] ?? ['mode' => 'develope', 'region' => 'unknown'];
-
$this->site_mode = $config['mode'];
$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) {
global $site_env;
-
- $twig->addGlobal('site_region', $site_env->site_region);
- $twig->addGlobal('site_mode', $site_env->site_mode);
- $twig->addGlobal('header_scripts', get_field('header_scripts', 'option')); // со страницы "Общих настроек контента ACF"
+ $twig->addGlobal('site_env', $site_env);
+ $twig->addGlobal('header_scripts', get_field('header_scripts', 'option'));
return $twig;
});
/* End | Работа с проверкой мультисайтовости и стендов */
+add_filter('woocommerce_currency_symbol', function($currency_symbol, $currency) {
+ return $currency === 'AED' ? 'AED' : $currency_symbol;
+}, 10, 2);
-
-add_filter('woocommerce_currency_symbol', 'change_aed_currency_symbol', 10, 2);
-
-function change_aed_currency_symbol($currency_symbol, $currency) {
- if ($currency == 'AED') {
- $currency_symbol = 'AED';
- }
- return $currency_symbol;
-}
-
-// Отключаем канонические ссылки и hreflang от Yoast SEO
add_filter('wpseo_canonical', '__return_false');
-add_filter('wpseo_opengraph_url', '__return_false'); // Отключаем OG URL
-add_filter('wpseo_add_x_default_hreflang', '__return_false'); // Отключаем hreflang от Yoast
-add_filter('wpseo_disable_adjacent_rel_links', '__return_true'); // Отключаем соседние rel-ссылки
+add_filter('wpseo_opengraph_url', '__return_false');
+add_filter('wpseo_add_x_default_hreflang', '__return_false');
+add_filter('wpseo_disable_adjacent_rel_links', '__return_true');
-// Добавляем каноническую ссылку
-add_action('wp_head', 'custom_canonical_url', 5);
-function custom_canonical_url() {
+add_action('wp_head', function() {
if (!is_admin()) {
- // Защищаем от дублирования
static $canonical_added = false;
- if ($canonical_added) {
- return;
- }
+ if ($canonical_added) return;
$canonical_added = true;
-
- // Формируем текущий URL без лишних параметров
- $current_url = trailingslashit(home_url($_SERVER['REQUEST_URI']));
- // Удаляем возможные параметры запроса, если они не нужны
- $current_url = strtok($current_url, '?');
+ $current_url = strtok(trailingslashit(home_url($_SERVER['REQUEST_URI'])), '?');
echo '' . "\n";
}
-}
-
-/**
- * Добавление событий контрибуции для FP Pixel
- * Только на боевом сайте AE, с учетом тестового режима через site_env->is_gp_test_mode
- */
-
-if (isset($site_env) && $site_env->site_mode === 'production' && $site_env->site_region === 'ae' && !$site_env->is_gp_test_mode) {
-
- add_action('wp_footer', 'add_facebook_pixel_events');
- function add_facebook_pixel_events() {
- global $site_env, $product;
-
- if ($site_env->is_gp_test_mode) return;
-
- // 1. ViewContent
- if (is_product() && $product && $product->get_price() > 0) {
- ?>
-
- cart && WC()->cart->get_cart_contents_count() > 0) {
- ?>
-
-
-
- cart && WC()->cart->get_cart_contents_count() > 0) {
- $currency = get_woocommerce_currency();
- $cart_total = WC()->cart->get_total('edit');
- ?>
-
- get_status() !== 'processing' && $order->get_status() !== 'completed')) return;
-
- $items = [];
- foreach ($order->get_items() as $item) {
- $product = $item->get_product();
- $items[] = [
- 'item_id' => $product->get_id(),
- 'item_name' => $product->get_name(),
- 'price' => $product->get_price(),
- 'quantity' => $item->get_quantity()
- ];
- }
- ?>
-
- site_mode === 'production' && $site_env->site_region === 'ae') {
+ $show_pixel = true;
}
-
- add_action('woocommerce_thankyou', 'send_purchase_to_metrika');
- function send_purchase_to_metrika($order_id) {
- global $site_env;
- if ($site_env->is_gp_test_mode) return;
-
- if (!$order_id) return;
-
- $order = wc_get_order($order_id);
- if ($order->get_status() !== 'processing' && $order->get_status() !== 'completed') return;
-
- $items = [];
- foreach ($order->get_items() as $item) {
- $product = $item->get_product();
- $items[] = [
- 'id' => $product->get_id(),
- 'name' => $product->get_name(),
- 'price' => $product->get_price(),
- 'quantity' => $item->get_quantity()
- ];
- }
-
- $currency = $order->get_currency();
- ?>
-
- site_mode === 'develope' && $site_env->site_region === 'ae') {
+ $show_pixel = true;
}
-}
-
+
+ if ($show_pixel && !$site_env->is_gp_test_mode) {
+ $context = [
+ 'pixel_event_type' => 'AddToCart', // или определите логику
+ 'currency' => get_woocommerce_currency(),
+ // добавьте другие переменные при необходимости
+ ];
+ \Timber\Timber::render('templates/head-pixel-functions.twig', $context);
+ }
+});
-// Отключаем кэширование для страниц товаров
add_action('template_redirect', function() {
if (is_product()) {
header('Cache-Control: no-cache, no-store, must-revalidate');
diff --git a/wp-content/themes/cosmopet/templates/head-pixel-functions.twig b/wp-content/themes/cosmopet/templates/head-pixel-functions.twig
new file mode 100644
index 0000000..555752b
--- /dev/null
+++ b/wp-content/themes/cosmopet/templates/head-pixel-functions.twig
@@ -0,0 +1,135 @@
+{# header_scripts_pixel.twig #}
+
+{# Проверка переменных перед рендерингом #}
+{% if pixel_event_type == 'ViewContent' and product %}
+
+{% endif %}
+
+{% if pixel_event_type == 'InitiateCheckout' %}
+
+{% endif %}
+
+{% if pixel_event_type == 'AddToCart' %}
+
+{% endif %}
+
+{% if pixel_event_type == 'AddPaymentInfo' %}
+
+{% endif %}
+
+{% if pixel_event_type == 'Purchase' and order %}
+
+
+
+{% endif %}
diff --git a/wp-content/themes/cosmopet/templates/layout.twig b/wp-content/themes/cosmopet/templates/layout.twig
index 2d83f3b..1744fbc 100644
--- a/wp-content/themes/cosmopet/templates/layout.twig
+++ b/wp-content/themes/cosmopet/templates/layout.twig
@@ -10,6 +10,7 @@
{% if site_mode == 'production' %}
{{ header_scripts }}
{% endif %}
+