Facebook Pixel Problem with LAYOUT (Single Product)

Hi Themeco, big problem for us with our Facebook Campaigns.

When a Layout is assigned to a Single Product, the ViewContent event is not fired from facebook pixel.
This means no retargeting is possible.
When the layout is deactivated and reverted to woocommerce’s standard one, the ViewContent is fired.

The Facebook-for-woocommerce plugin injects the following code via hooks:

// ViewContent for individual products
			add_action( 'woocommerce_after_single_product', [ $this, 'inject_view_content_event' ] );
			add_action( 'woocommerce_after_single_product', [ $this, 'maybe_inject_search_event' ] );

			add_action( 'woocommerce_after_shop_loop', [ $this, 'inject_view_category_event' ] );

			add_action( 'pre_get_posts',                             [ $this, 'inject_search_event' ] );
			add_filter( 'woocommerce_redirect_single_search_result', [ $this, 'maybe_add_product_search_event_to_session' ] );

The problem is, woocommerce_after_single_product hook is missing if a custom layout is assigned, so no ViewContent code is injected and no event is tracked.

We temporary solved this overwriting files in the plugin and using woocommerce_after_add_to_cart_form (which is present in our single product layout, thanks to the “Add to Cart Form” element) instead of woocommerce_after_single_product.

Is there a way to avoid applying a layout, with it “removing” the standard woocommerce hooks?
Or is there a way to add hooks to a custom Layout in Pro?
Thanks!

UPDATE: Same thing happens with Google Analytics 4 - the view_item event is not fired when custom layout is assigned

Hi @Draxdes,

Thanks for reaching out.
As you have already solved the issue with some temporary fixes, I am not able to replicate it. I also checked the URL with the layout and found the ViewContent code in it. To further investigation, I would request you to please copy your live site to a staging server and remove the temporary adjustments you made in your live site and share credentials so we could troubleshoot freely without breaking your live site.

Thanks

Hi @tristup,
credentials updated and adjustments removed.

Thanks

Hi @Draxdes,

I can confirm that Pro doesn’t fire woocommerce_after_single_product or woocommerce_before_single_product.

For now you can do something like this in functions.php of a child theme.

add_action('cs_layout_after_single', function() {
  if ( is_singular( 'product' ) ) {
    do_action( 'woocommerce_after_single_product' );
  }
});

For the next Pro launch I’ve updated it to trigger the WooCommerce hooks for better plugin integration. This will be in Pro 4.3.0 which is scheduled to be released early April. Once you update, you can remove that compatibility code above because otherwise the hook will run twice.

1 Like

Thanks @alexander !!

Hi @Draxdes,

You are most welcome.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.