Skip to content

Commit

Permalink
Adding event filtering. Only AddToCart events should be deferred in c…
Browse files Browse the repository at this point in the history
…ase `cart redirect after add` option is active.
  • Loading branch information
message-dimke committed May 2, 2024
1 parent d1b345c commit c6147aa
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions facebook-commerce-pixel-event.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,13 @@ public function get_event_script( $event_name, $params, $method = 'track' ) {
* @param string $method Name of the pixel's fbq() function to call.
*/
public function inject_event( $event_name, $params, $method = 'track' ) {
// If we have add to cart redirect enabled, we must defer the events to render them the next page load.
$should_defer = 'yes' === get_option( 'woocommerce_cart_redirect_after_add', 'no' );
if ( WC_Facebookcommerce_Utils::isWoocommerceIntegration() ) {
$code = $this->get_event_code( $event_name, self::build_params( $params, $event_name ), $method );
if ( $should_defer ) {

// If we have add to cart redirect enabled, we must defer the AddToCart events to render them the next page load.
$is_redirect = 'yes' === get_option( 'woocommerce_cart_redirect_after_add', 'no' );
$is_add_to_cart = 'AddToCart' === $event_name;
if ( $is_redirect && $is_add_to_cart ) {
WC_Facebookcommerce_Utils::add_deferred_event( $code );
} else {
WC_Facebookcommerce_Utils::wc_enqueue_js( $code );
Expand Down

0 comments on commit c6147aa

Please sign in to comment.