• Resolved Erik Molenaar

    (@erikmolenaar)


    Hi,

    I found this great snippet to add order profit to the GTM4WP dataLayer:

    https://gist.github.com/mattiasghodsian/b473d5cd7762fd9d8588fb5122033f51

    However it fails trying to retrieve order data from the dataLayer:

    $orderID    = $dataLayer['ecommerce']['purchase']['actionField']['id'];
    $orderItems = $dataLayer['ecommerce']['purchase']['products'];

    Resulting in error because this array seems to be empty:

    <strong>Notice:</strong> Undefined index: ecommerce

    My question is:

    Is it possible to retrieve the orderID and orderItems from the dataLayer with this filter? So I can make this snippet work?

    Looking forward to your reply. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Thomas Geiger

    (@duracelltomi)

    Hi,

    This script should work as far as I can see.
    Have you also included the if ( is_order_received_page() ){ condition?
    Are you using and plugin that customizes the order received page?

    Thread Starter Erik Molenaar

    (@erikmolenaar)

    Hi Thomas,

    I have set up a fresh install at https://dev2.erikmolenaar.nl of:

    Wordpress 5.7.1
    Woocommerce 5.2.2
    GTM4WP 1.12.2

    And I am still getting the same error, $dataLayer is just empty.

    Screenshot: https://www.screencast.com/t/dxUxj0loNC

    Is this filter ‘gtm4wp_compile_datalayer’ still available? Or has something changed in one of the recent versions of your plugin?

    Thank you and have a great weekend.

    Thread Starter Erik Molenaar

    (@erikmolenaar)

    This is solved, the code snippet was missing a required priority setting ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Accessing DL within filter ‘gtm4wp_compile_datalayer’’ is closed to new replies.