GTM不识别我的dataLayer,但控制台呢?

So I have a dataLayer created that works just fine when using the console in Chrome:

The dataLayer in Chrome console.

In Google Tag Manager, this dataLayer doesn't exist. Why?

The code I've used is below:

<script>

<?php
    global $woocommerce;
    $items = $woocommerce->cart->get_cart();
    $dataLayer = [];
    foreach($items as $item => $values) { 
         $_product = $values['data']->post;
?>

<?php
         $dataLayer[] = [
    'itemUnitID' => $_product->ID,
              'itemUnitPrice' => get_post_meta($values['product_id'] , '_price', true),
              'itemQuantity' => $values[quantity]


         ];

     }; 

?>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push(<?php echo json_encode($dataLayer); ?>);

</script>

So basically the code is shooting a dataLayer, but I can't use any of those values in Google Tag Manager as GTM doesn't even recognize the dataLayer in the first place. Why is that?