Created
November 14, 2021 08:54
-
-
Save gorkamu/f552f68fc5ee68cfddc717c9a6b4ddf8 to your computer and use it in GitHub Desktop.
Custom FB Event
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(is_product()) { | |
global $product; | |
$price = round((float)$product->get_price(),2); | |
$category = ''; | |
foreach(get_the_terms( $id, 'product_cat' ) as $term) { | |
$category = $term->name; | |
} | |
?> | |
<script> | |
jQuery( document ).ready(function() { | |
jQuery('button[name="add-to-cart"]').on('click', function(e){ | |
console.log('click on display-customizer btn'); | |
fbq('track', 'AbrePersonalizador', { | |
"source": "woocommerce", | |
"content_name": "<?= $product->get_name(); ?>", | |
"content_ids": "['<?= $product->get_sku(); ?>']", | |
"content_type": "product", | |
"contents": '<?= json_encode([ | |
'id' => $product->get_sku(), | |
'quantity' => $product->get_stock_quantity() | |
]); ?>', | |
"content_category": "<?= $category; ?>", | |
"value": "<?= $price; ?>", | |
"currency": "<?= get_woocommerce_currency(); ?>" | |
}); | |
}); | |
}); | |
</script> | |
<?php | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment