sendinblue のトラッキング コード JavaScript があります。
セグメンテーションのためにこのサイトで「自動化」を開始したいのですが、そのためには、API を使用して自分のサイトから sendinblue にデータを送信する必要があります。
Wocommerce の「Thank You」ページでは、顧客が購入している製品のカテゴリを知り、このデータを 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>