Skip to content

Instantly share code, notes, and snippets.

@gorkamu
Created November 14, 2021 08:54
Show Gist options
  • Save gorkamu/f552f68fc5ee68cfddc717c9a6b4ddf8 to your computer and use it in GitHub Desktop.
Save gorkamu/f552f68fc5ee68cfddc717c9a6b4ddf8 to your computer and use it in GitHub Desktop.
Custom FB Event
<?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