@Omar_one and
@BrockleyJohn
I think i reach the end of the rabbit hole and found a princess telling me it goes futher..
When in the product_info.php pages this code below works correct with /actions/add_product.php.
My Meta Pixel helper shows the AddToCart event + 2 others i added after adding item to cart.
For index.php pages showing add to cart buttons for products it does not work, example i cannot get $product->get('name') from any index pages though $pid and qty =1 is passed through the session (buy_now.php button)
Extract of my header tag:
Code: Select all
if (isset($_SESSION['facebook_pixel_add_to_cart']) && !empty($_SESSION['facebook_pixel_add_to_cart']['products_id'])) {
$pid = (int)$_SESSION['facebook_pixel_add_to_cart']['products_id'];
$qty = (int)$_SESSION['facebook_pixel_add_to_cart']['quantity'];
if (isset($pid)) {
$product_id = $pid;
$product_name = $product->get('name');
if ($product->get('is_special') == 1) {
$facebook_price = $product->format_raw('specials_new_products_price');
} else {
$facebook_price = $product->format_raw();
}
$currency_code = $_SESSION['currency'];
$category_name = $category_tree->get($current_category_id, 'name');
$pixel .= <<<EOD
<script>
fbq('track', 'AddToCart', {
content_name: '{$product_name}',
content_category: '{$category_name}',
content_ids: ['{$product_id}'],
content_type: 'product',
value: {$facebook_price},
currency: '{$currency_code}',
quantity: {$qty}
});
</script>
EOD;
}
unset($_SESSION['facebook_pixel_add_to_cart']);
}
Do we need to manually do the additional sql for index pages or am i missing something?