|
|
|
@ -167,96 +167,97 @@ if($site_env->site_mode == 'production' and $site_env->site_region == 'ae') { |
|
|
|
|
currency: currency |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// Событие для Google Analytics |
|
|
|
|
window.dataLayer = window.dataLayer || []; |
|
|
|
|
window.dataLayer.push({ |
|
|
|
|
'event': 'add_to_cart', |
|
|
|
|
'ecommerce': { |
|
|
|
|
'currency': currency, |
|
|
|
|
'value': parseFloat(priceElement) * quantity, |
|
|
|
|
'items': [{ |
|
|
|
|
'item_id': productId, |
|
|
|
|
'item_name': productName, |
|
|
|
|
'price': parseFloat(priceElement), |
|
|
|
|
'quantity': quantity |
|
|
|
|
}] |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
// Событие для Google Analytics |
|
|
|
|
window.dataLayer = window.dataLayer || []; |
|
|
|
|
window.dataLayer.push({ |
|
|
|
|
'event': 'add_to_cart', |
|
|
|
|
'ecommerce': { |
|
|
|
|
'currency': currency, |
|
|
|
|
'value': parseFloat(priceElement) * quantity, |
|
|
|
|
'items': [{ |
|
|
|
|
'item_id': productId, |
|
|
|
|
'item_name': productName, |
|
|
|
|
'price': parseFloat(priceElement), |
|
|
|
|
'quantity': quantity |
|
|
|
|
}] |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
</script> |
|
|
|
|
<?php |
|
|
|
|
}); |
|
|
|
|
</script> |
|
|
|
|
<?php |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 2. Событие Purchase (Покупка) |
|
|
|
|
if (is_wc_endpoint_url('order-received')) { |
|
|
|
|
$order_id = absint(get_query_var('order-received')); |
|
|
|
|
if (!$order_id) 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() |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
?> |
|
|
|
|
<script> |
|
|
|
|
document.addEventListener('DOMContentLoaded', function() { |
|
|
|
|
fbq('track', 'Purchase', { |
|
|
|
|
value: <?php echo $order->get_total(); ?>,
|
|
|
|
|
currency: '<?php echo $order->get_currency(); ?>',
|
|
|
|
|
content_ids: [<?php echo implode(',', array_column($items, 'item_id')); ?>],
|
|
|
|
|
content_type: 'product' |
|
|
|
|
}); |
|
|
|
|
// 2. Событие Purchase (Покупка) |
|
|
|
|
if (is_wc_endpoint_url('order-received')) { |
|
|
|
|
$order_id = absint(get_query_var('order-received')); |
|
|
|
|
if (!$order_id) 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() |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
?> |
|
|
|
|
<script> |
|
|
|
|
document.addEventListener('DOMContentLoaded', function() { |
|
|
|
|
fbq('track', 'Purchase', { |
|
|
|
|
value: <?php echo $order->get_total(); ?>,
|
|
|
|
|
currency: '<?php echo $order->get_currency(); ?>',
|
|
|
|
|
content_ids: [<?php echo implode(',', array_column($items, 'item_id')); ?>],
|
|
|
|
|
content_type: 'product' |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
window.dataLayer = window.dataLayer || []; |
|
|
|
|
window.dataLayer.push({ |
|
|
|
|
'event': 'purchase', |
|
|
|
|
'ecommerce': { |
|
|
|
|
'currency': '<?php echo $order->get_currency(); ?>',
|
|
|
|
|
'value': <?php echo $order->get_total(); ?>,
|
|
|
|
|
'items': <?php echo json_encode($items); ?> |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
window.dataLayer = window.dataLayer || []; |
|
|
|
|
window.dataLayer.push({ |
|
|
|
|
'event': 'purchase', |
|
|
|
|
'ecommerce': { |
|
|
|
|
'currency': '<?php echo $order->get_currency(); ?>',
|
|
|
|
|
'value': <?php echo $order->get_total(); ?>,
|
|
|
|
|
'items': <?php echo json_encode($items); ?> |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
</script> |
|
|
|
|
<?php |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
</script> |
|
|
|
|
<?php |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 3. Событие AddPaymentInfo |
|
|
|
|
if (is_checkout() && !is_wc_endpoint_url('order-received')) { |
|
|
|
|
$currency = get_woocommerce_currency(); |
|
|
|
|
$cart_total = WC()->cart ? WC()->cart->get_total('edit') : 0; |
|
|
|
|
?> |
|
|
|
|
<script> |
|
|
|
|
document.addEventListener('DOMContentLoaded', function() { |
|
|
|
|
fbq('track', 'AddPaymentInfo', { |
|
|
|
|
value: <?php echo $cart_total; ?>,
|
|
|
|
|
currency: '<?php echo $currency; ?>'
|
|
|
|
|
}); |
|
|
|
|
// 3. Событие AddPaymentInfo |
|
|
|
|
if (is_checkout() && !is_wc_endpoint_url('order-received')) { |
|
|
|
|
$currency = get_woocommerce_currency(); |
|
|
|
|
$cart_total = WC()->cart ? WC()->cart->get_total('edit') : 0; |
|
|
|
|
?> |
|
|
|
|
<script> |
|
|
|
|
document.addEventListener('DOMContentLoaded', function() { |
|
|
|
|
fbq('track', 'AddPaymentInfo', { |
|
|
|
|
value: <?php echo $cart_total; ?>,
|
|
|
|
|
currency: '<?php echo $currency; ?>'
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
window.dataLayer = window.dataLayer || []; |
|
|
|
|
window.dataLayer.push({ |
|
|
|
|
'event': 'add_payment_info', |
|
|
|
|
'ecommerce': { |
|
|
|
|
'currency': '<?php echo $currency; ?>',
|
|
|
|
|
'value': <?php echo $cart_total; ?> |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
window.dataLayer = window.dataLayer || []; |
|
|
|
|
window.dataLayer.push({ |
|
|
|
|
'event': 'add_payment_info', |
|
|
|
|
'ecommerce': { |
|
|
|
|
'currency': '<?php echo $currency; ?>',
|
|
|
|
|
'value': <?php echo $cart_total; ?> |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
</script> |
|
|
|
|
<?php |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
</script> |
|
|
|
|
<?php |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Отключаем кэширование для страниц товаров |
|
|
|
|
add_action('template_redirect', function() { |
|
|
|
|
if (is_product()) { |
|
|
|
|