我正在嘗試向Wordpress添加一個短信API,它使用Woocommerce掛鉤發送訂單確認消息。經過一番研究,我發現下面的代碼here,它的工作原理是一樣的。提供如何將javascript api添加到wordpress function.php
add_action('woocommerce_payment_complete', 'custom_process_order', 10, 1);
function custom_process_order($order_id) {
//Lets get data about the order made
$order = new WC_Order($order_id);
//Now will fetch customer/buyer id here
$customer_id = $order->user_id;
//now finally we fetch phone number
$billing_phone = get_user_meta($customer_id, 'billing_phone', true);
// Now put your HTTP SMS API URL . I PUT WHICH WE ARE USING
$jsonurl = "http://tsms.thirdeyegoa.com/api/sendmsg.php?user=USERNAME&pass=PASSWORD&sender=MYSENDERID&phone=".$billing_phone."&priority=ndnd&stype=normal&text=MY MESSAGE TO CUSTOMER.";
// NOW WILL CALL FUNCTION CURL
$json = curl($jsonurl);
return $order_id;
}
的API代碼我收到的短信網關是
// Include provided Java Script
<script language="javascript" src="https://domainapi.js" type="text/javascript"> </script>
<script language="javascript">
// Replace your API key at below line
var apikey = 'ABCDEFGH1234567890abcdefghQWERTY123=';
// Form your data object
var mail_details = { email : '[email protected]', msgid : '82', listname : '', prefix : '', firstname : 'John', middlename : '', lastname : 'Doe', telephone : '', address : '', city : '', state : '', pincode : '', country : '', mobile : '9999999999', designation : '', company : '', companyphone : '', birthdate : '', anniversary : '', extra1 : '', extra2 : '' }
call_api(apikey, 'sendSingleSMS', mail_details, function(response) { document.getElementById('show').innerHTML=response; });</script>
請告訴我如何這個API在WordPress的上述腳本集成。
請解釋一下您更多的問題。您只需將代碼粘貼到functions.php中並提供javascript代碼,而我沒有看到任何2個文件一起工作? –
嗨,感謝您的關注....我試圖添加[this](http://docs.juvlon.com/api/sendTransSms.html#sendSingleSMS)api到我的Woocommerce商店,當訂單是完成。你能告訴我我該怎麼做? @QuỳnhNguyễn – user3475163
這是短信網關文檔的建議。請檢查[此api文檔](http://docs.juvlon.com/api/sendTransSms.html#sendSingleSMS)@LoicTheAztec – user3475163