我有一个来自 sendinblue 的跟踪代码 javascript。
我想在此站点中启动“自动化”以进行分段,为此,我必须使用其 API 将数据从我的站点发送到 sendinblue。
在 Wocommerce 的“谢谢”页面中,我需要知道客户正在购买的产品类别,并将此数据通过 JS 发送给 sendinblue。
我已将此代码放在functions.php中
add_action( 'woocommerce_thankyou', 'analisi' );
function analisi($order_id) {
$order = new WC_Order($order_id);
$items = $order->get_items();
foreach ($items as $item_id => $item_data)
{
//getting product object
$_product = wc_get_product($item_data['item_meta']['_product_id'][0]);
//getting all the product category
$pro_cat_array = wp_get_post_terms($_product->ID, 'product_cat');
$pro_cat = implode(',', $pro_cat_array);
//storing all the line item as a string form
$product_js[] = '{category:"' . $pro_cat . '"}';
}
?>
<!-- Paste Tracking Code Under Here -->
<script language="text/javascript">
sendinblue.track('categoria_acquisto', {
'categoria':'[<?= implode(',', $product_js) ?>]';
});
</script>
<?php
}
?>
当我模拟订单并查看 HTML 代码时,数组(用于发送的类别)为空。
<script language="text/javascript">
sendinblue.track('categoria_acquisto', {
'categoria':'[{category:""}]';
});
</script>