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();
?>