From 4098b3c7b90fe916c90d180a7c4bf8d6a37cc58a Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 17 Jul 2025 16:52:49 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2=D1=8B=D0=B9=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B6=D0=B8=D0=BC=20=D0=BC=D0=B5=D1=82=D1=80=D0=B8?= =?UTF-8?q?=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global-functions/multisite-functions.php | 259 ++++++++++-------- 1 file changed, 147 insertions(+), 112 deletions(-) diff --git a/wp-content/themes/cosmopet/global-functions/multisite-functions.php b/wp-content/themes/cosmopet/global-functions/multisite-functions.php index 3aba101..e263ce4 100644 --- a/wp-content/themes/cosmopet/global-functions/multisite-functions.php +++ b/wp-content/themes/cosmopet/global-functions/multisite-functions.php @@ -76,148 +76,185 @@ function custom_canonical_url() { } /** - * Добавление событий контрибуции для FP Pixel - * только на боевом сайте АЕ - * */ -if($site_env->site_mode == 'production' and $site_env->site_region == 'ae') { - /* Передача просто по url */ + * Добавление событий контрибуции для FP Pixel + * только на боевом сайте АЕ + */ +// if ($site_env->site_mode == 'production' && $site_env->site_region == 'ae') { + + // Проверка на тестовый режим для метрик + 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'); function add_facebook_pixel_events() { - // 1. Событие AddToCart (Добавление в корзину) + if (is_gp_test_mode()) return; + + global $product; + + // 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; + $order = wc_get_order($order_id); + if (!$order || ($order->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() - ]; - } - ?> - - cart ? WC()->cart->get_total('edit') : 0; - ?> - - get_currency(); ?>', + 'value': get_total(); ?>, + 'items': + } + }); + }); + + get_status() !== 'processing' && $order->get_status() !== 'completed') - return; // Отправляем только для оплаченных заказов + 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(), + 'id' => $product->get_id(), + 'name' => $product->get_name(), + 'price' => $product->get_price(), 'quantity' => $item->get_quantity() ]; } - // Получаем валюту заказа $currency = $order->get_currency(); ?>