Example to build datalayer for Google Enhanced Ecommerce

<script>
window.dataLayer = window.dataLayer || [];

var products = [];
<?php foreach($order_products as $key => $item): ?>
products.push({
	'name': '<?=$item->name?>',
    'id': '<?=$item->product_id?>',
    'price': '<?=round($item->price, 0)?>',
    'brand': 'WIIB',
    'category': 'Health',
    'quantity': <?=$item->quantity?>,
    'coupon': '' 
});
<?php endforeach; ?>

dataLayer.push({
  'ecommerce': {
    'purchase': {
      'actionField': {
        'id': '<?=$order->transaction_id?>',                         // Transaction ID. Required for purchases and refunds.
        'affiliation': 'WIIB',
        'revenue': '<?=round($order->amount, 0)?>',                     // Total transaction value (incl. tax and shipping)
        'tax':'<?=$order->amount*0.05?>',
        'shipping': '<?=$order->shipping_fee?>'
      },
      'products': products
    }
  }, 
  'event': 'transactionComplete'
});
</script>

Reference: