Tom*_*son 6 netsuite woocommerce
我正在尝试通过我编写的外部 api 将 woocommerce 订单发送到 netsuite。我是 woocommerce 的新手,并没有完全了解如何添加此功能。
我已将以下代码添加到public_html/wp-content/themes/reverie-master/ 中的functions.php 文件中
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
}
}
Run Code Online (Sandbox Code Playgroud)
我已经测试了这段代码的首当其冲的部分,只是在另一个站点中与 woocommerce 无关的部分,我可以看到显示在 NetSuite 中的数据。但是,当我通过我的商店下订单并付款时,我没有看到数据进入 NetSuite。我在正确的位置有这个代码吗?有什么我想念的吗?
更新 我安装了插件代码片段并在那里添加了代码。将其设置为随处运行代码段。仍然没有运气。
小智 1
看起来您在第一个链接上有双引号
改变
add_action( 'woocommerce_payment_complete'', 'wdm_send_order_to_ext');
到
add_action( 'woocommerce_payment_complete', 'wdm_send_order_to_ext');
除了使用curl - 您始终可以使用WordPress 中的构建wp_remote_post()功能
还要确保您在测试时已WP_DEBUG设置为truein wp-config.php。
| 归档时间: |
|
| 查看次数: |
1993 次 |
| 最近记录: |