Skip to content

Instantly share code, notes, and snippets.

@TimBHowe
Created January 31, 2018 13:53
Show Gist options
  • Save TimBHowe/40f7fe01db0e6546d9403a19fbaf34f1 to your computer and use it in GitHub Desktop.
Save TimBHowe/40f7fe01db0e6546d9403a19fbaf34f1 to your computer and use it in GitHub Desktop.
Include this file or add this function to the functions.php file to fire the Facebook Pixel 'AddToCart' event on the 'woocommerce_after_cart' action.
<?php
// Add function to fix some for the event tracking issues from the facebook for WooCommerce 1.7.5 update.
add_action( 'woocommerce_init', 'wc_facebook_tracking_fixes' );
function wc_facebook_tracking_fixes(){
// Get the facebook integration class.
$facebook = WooCommerce::instance()->integrations->get_integrations()['facebookcommerce'];
// Add add to cart event tracking to allow for WooCommerce redirect to cart after adding product.
add_action('woocommerce_after_cart', array($facebook->events_tracker, 'inject_add_to_cart_event'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment