ฉันกำลังพยายามส่งคำสั่ง woocommerce ไปยัง netsuite ผ่าน API ภายนอกที่ฉันเขียน ตอนนี้ฉันกำลังใช้ woocommerce และยังไม่ทราบวิธีเพิ่มฟังก์ชันนี้อย่างสมบูรณ์
ฉันได้เพิ่มโค้ดต่อไปนี้ลงในไฟล์ function.php ใน public_html/wp-content/themes/reverie-master/
add_action( 'woocommerce_payment_complete'', 'wdm_send_order_to_ext');
function wdm_send_order_to_ext( $order_id ){
// get order object and order details
$order = new WC_Order( $order_id );
$email = $order->billing_email;
$phone = $order->billing_phone;
//Create the data object
$orderData = array(
'customer_email' => $email,
'customer_phone' => $phone
);
$apiData = array(
'caller' => 'woocommerce',
'json' => $orderData,
'key' => 'MY_SECRET_KEY'
);
$jsonData =json_encode($orderData);
$url = "";
$api_mode = 'sandbox';
if($api_mode == 'sandbox'){
// sandbox URL example
$url = "https://forms.netsuite.com/app/site/hosting/scriptlet.nl?script=XXX&deploy=X&compid=XXXXXXX_SB1&h=XXXXXXXXXXXXXXXX";
}
else{
// production URL example
$url = "";
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($jsonData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec ($ch);
curl_close ($ch);
// the handle response
if (strpos($response,'ERROR') !== false) {
print_r($response);
} else {
// success
}
}
ฉันได้ทดสอบความหนักหน่วงของโค้ดนี้แล้ว เฉพาะส่วนที่ไม่เกี่ยวข้องกับ woocommerce ในไซต์อื่น และฉันสามารถดูข้อมูลที่ปรากฏใน NetSuite ได้ อย่างไรก็ตาม เมื่อฉันไปที่ร้านค้าและสั่งซื้อและชำระเงิน ฉันไม่เห็นข้อมูลเข้ามาใน NetSuite ฉันมีรหัสนี้ในตำแหน่งที่ถูกต้องหรือไม่? มีบางอย่างที่ฉันขาดหายไปหรือไม่?
อัปเดต ฉันติดตั้งข้อมูลโค้ดปลั๊กอินและเพิ่มโค้ดที่นั่นแทน ตั้งค่าเป็น Run snippet ทุกที่ ยังไม่มีโชคเลย