我尝试将我的订单的交易ID插入到“ woocommerce_payment_complete”挂钩中。 我需要它来将其存储在我的CRM中。
在挂钩中,我可以在日志中看到我得到了WcOrder对象。我可以提供一些信息,例如运输,交货等。 但是“ transaction_id”仍然为空。
当我查看确认电子邮件或后台的订单信息时,我可以看到交易ID已填满...
您对可能发生的事情有任何了解吗?
这是我在钩子上做的代码
function SPA_payment_complete( $order_id ) {
$order = wc_get_order( $order_id );
$user = $order->get_user();
$user_datas = $user->data;
$user_ID = $order->user_id;
$transaction_id = $order->get_transaction_id();
$detail_user = get_user_by('id', $user_ID);
$tel = $order->get_billing_phone();
$adresse = $order->get_billing_address_1();
$adresse2 = $order->get_billing_address_2();
$cp =$order->get_billing_postcode();
$ville = $order->get_billing_city();
$nompre = $order->get_billing_last_name().' '.$order->get_billing_first_name();
// custom function to call my webservice
$result = WS_REF_setPerso($nompre, $adresse, $adresse2, $cp, $ville, $tel, $user_datas->user_email);
$items = $order->get_items();
$lignes = array();
foreach ($items as $item) {
$item_id = $item->get_id();
$item_data = $item->get_data();
$product = $item->get_product();
$id_product = $item['product_id'];
$code_refu = get_field('code_refugylis', $id_product);
$l = array();
$l['operat'] = urlencode($code_refu);
$l['montan'] = urlencode($item->get_total());
$l['libelle'] = refugilys_clean($item_data['name'].' ('.$item->get_quantity().'*)');
$l['famille'] = urlencode($product->get_type());
$lignes[] = $l;
}
$order_shipping_total = $order->get_shipping_total();
if ($order_shipping_total > 0){
$l = array();
$l['operat'] = urlencode('870');
$l['montan'] = urlencode($order_shipping_total);
$l['libelle'] = 'Frais de port internet';
$l['famille'] = urlencode('PORT');
$lignes[] = $l;
}
$string_items = json_encode($lignes);
// custom function to call my webservice
$result = WS_REF_setCommande($idRefugylis, $transaction_id, $string_items);
}
add_action( 'woocommerce_payment_complete', 'SPA_payment_complete' );