• Resolved Daniele

    (@dabesa)


    Dear support,

    I”m testing GTM Kit, the add-to-cart event is fired when I click “add to cart” from the product single page.

    But it’s not fired when a product is added to cart from an archive page.
    In this case the “add to cart” button point straight to the URL like /?add-to-cart=<product ID>

    How can we trigger the add-to-cart event in this case?

    Thank you!
    Daniele

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Torben Lundsgaard

    (@torbenlundsgaard)

    Do you mean on a product category? Can you the URL so I can have a look at the specific page?

    Thread Starter Daniele

    (@dabesa)

    Hi Torben,

    How can I privately send you the URL?

    Thanks

    Plugin Author Torben Lundsgaard

    (@torbenlundsgaard)

    You can use this contact form: https://gtmkit.com/about/

    Plugin Author Torben Lundsgaard

    (@torbenlundsgaard)

    The problem is most likely that your theme does not contain the standard WooCommerce hooks. In product lists GTM Kit is using the WooCommerce hook woocommerce_after_shop_loop_item and if this hook is not present in your theme GTM Kit is not able to add the necessary datalayer data.

    If for some reason you can’t add the woocommerce_after_shop_loop_item hook but have another hook you can use that hook with the following code:

    use TLA_Media\GTM_Kit\Integration\WooCommerce;
    
    function custom_gtmkit_hooks() {
    
    	add_action( '<<INSERT ACTION HOOK>>', [
    		WooCommerce::instance(),
    		'product_list_loop_add_to_cart_tracking'
    	] );
    
    }
    
    if ( ! wp_installing() && ! wp_doing_ajax() && ! is_admin() ) {
    	add_action( 'plugins_loaded', 'custom_gtmkit_hooks' );
    }
    Plugin Author Torben Lundsgaard

    (@torbenlundsgaard)

    @dabesa Have you tried my sugestion?

    Plugin Author Torben Lundsgaard

    (@torbenlundsgaard)

    Closing this as resolved

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Add-to-cart from archive pages’ is closed to new replies.