UPDATE:
Latest setup outputs ID's but not comma separated. They appear like 1-item individual arrays 😕 like "ID1""ID2" instead of, "ID1,ID2".
Also, HTML markup updated. Used same syntax for the "contents:..." bit, and here it outputs correctly...
PHP:
public function initContent() { parent::initContent(); $order = new Order((int)($this->id_order)); $products = $order->getProducts(); $product_ids = array(); foreach ($products as $product) $product_ids[] = (int)$product['id_product']; $this->context->smarty->assign(array( '$products' => $products, 'id_order' => $this->id_order, 'is_guest' => $this->context->customer->is_guest, 'HOOK_ORDER_CONFIRMATION' => $this->displayOrderConfirmation(), 'HOOK_PAYMENT_RETURN' => $this->displayPaymentReturn() )); $array = explode(', ',$product_ids); if ($this->context->customer->is_guest) { $this->context->smarty->assign(array( 'id_order' => $this->id_order, '$products' => $products, 'reference_order' => $this->reference, 'id_order_formatted' => sprintf('#%06d', $this->id_order), 'email' => $this->context->customer->email )); /* If guest we clear the cookie for security reason */ $this->context->customer->mylogout(); } ...
HTML:
{literal} <script> fbq('track', 'Purchase', { content_ids: {/literal}{foreach from=$products item="product"}{literal} {/literal}'{$product_ids}'{literal} {/literal}{/foreach}{literal}, content_type: 'product', value: {/literal}'{$_value}'{literal}, currency: 'RON', contents: [ {/literal}{foreach from=$products item="product"}{literal} { id: {/literal}'{$product.product_id}'{literal}, quantity: {/literal}'{$product.product_quantity}'{literal}, item_price: {/literal}'{$product.total_wt}'{literal} } {/literal}{/foreach}{literal} ], }); </script>