[英]Integrating custom SMS API with woocommerce
因此,我一直致力於將自定義 SMS API 與 woocommerce 和 wc 供應商插件集成的項目。 不幸的是,我沒有為此找到任何特定的解決方案。 每個人都在談論一些實際支持現有網關的插件。 我想知道如果有人想將自己的 api 與 woocommerce 集成怎么辦!
最后,我想出了自己的代碼,如下所示。 代碼轉到您子主題中的 function.php。 FYKI,我不得不使用rawurlencode對文本消息進行編碼,因為某些電信公司需要編碼消息。
謝謝。
//DYNAMIC ORDER MSG TO CUSTOMER
add_action('woocommerce_order_status_processing', 'custom_msg_customer_process_order', 10, 3);
function custom_msg_customer_process_order ($order_id) {
//Lets get data about the order made
$order = new WC_Order($order_id);
//Now will fetch billing phone
$billing_phone = $order->get_billing_phone();
$billing_name = $order->get_billing_first_name();
$textmessage = rawurlencode("Dear $billing_name, Thank you for your order. Your order #$order_id is being processed. Please wait for confirmation call.");
// Now put HTTP SMS API URL
$url = "http://msms.THE_COMPANY.com/RequestSMS.php?user_name=YOUR_USER_NAME&pass_word=YOUR_PASSWORD&brand=YOUR_BRAND_NAME&type=1&destination=$billing_phone&sms=$textmessage";
// NOW WILL CALL FUNCTION CURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
return $order_id;
}
要將Datagen SMS API腳本集成到沒有任何插件的Wordpress Woocommerce中,只需將Funcation.php代碼添加到全球成千上萬的客戶中,相信Datagen可以向其客戶發送數百萬條消息。 單一的SMS API集成服務可以改變您的業務並將其推向新的高度。 有了它,您就可以在啟用SMS的任何應用程序,系統或網站上通過短代碼,長號等實現國際雙向雙向消息傳遞,從而在全球定位客戶。
無論何時在網站上購買商品,Dategen SMS API都會發送消息
每當在網站上進行購買時,Wordpress WooCommerce都會向客戶手機發送自動訂單更新。
如何在Wordpress woocommerce中集成SMS API
在設置此dataen API之前,請注意兩件事
auth Key
Sender ID
現在,您需要將此代碼添加到functions.php頁面
add_action('woocommerce_thankyou', 'send_sms_api', 10, 1);
function send_sms_api($billing_phone)
{
$results = $GLOBALS['wpdb']->get_results("SELECT * FROM wp_postmeta WHERE post_id = $billing_phone AND meta_key IN ('_billing_phone')", OBJECT);
$mobilenois=$results[0]->meta_value;
$auth = "Enter Your Auth Key Here "; // add auth Key Here
$mobileNumber = $mobilenois;
$senderId = "Enter Send ID Here"; // add Sender ID
$message = urlencode("Thannk you for order with us. "); // Add Message here
$postData = array(
'auth' => $auth,
'msisdn' => $mobileNumber,
'message' => $message,
'senderid' => $senderId,
);
$url='http://sms.datagenit.in/API/sms-api.php';
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postData
//,CURLOPT_FOLLOWLOCATION => true
));
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$output = curl_exec($ch);
if(curl_errno($ch))
{
echo 'error:' . curl_error($ch);
}
curl_close($ch);
$output;
}
https://datagenit.com/api-developer.php
免費技術支持:致電+ 91-9999-706-864或向我們發送電子郵件:hello@datagenit.com
我最近自己遇到了這個挑戰,我找到了一種使用插件從 WooCommerce 發送通知 SMS 消息的簡單方法,但我需要一些東西以自己的方式發送消息。
我最終使用了 Twilio 服務和他們的 API,我寫了這個教程來教你如何設置它,希望它有所幫助!
function wpcodetips_send_sms( $smsMessage , $contactNumber ){
// Change to your account SID
$accountSID = 'XXXXXXXXXXXXX';
// Change to your account Auth Key
$authKey = 'XXXXXXXXXXXXX';
// Change to your account trial number
$sendNumber = '+XXXXXXXXXXX';
// The Twilio API Url
$url = "https://api.twilio.com/2010-04-01/Accounts/".$accountSID."/Messages.json";
// The data being sent to the API
$data = array(
'From' => $sendNumber,
'To' => $contactNumber,
'Body' => $smsMessage
);
// Set the authorisation header
$headers = array( 'Authorization' => 'Basic ' . base64_encode($accountSID . ':' . $authKey));
// Send the POST request and store the response in a variable
$result = wp_remote_post($url, array( 'body' => $data, 'headers' => $headers));
// Return the response body to ensure it has worked
return json_decode($result['body'], true);
}
https://www.wpcodetips.com/wordpress-tutorials/how-to-send-an-sms-from-wordpress-programmatically/
不確定這是否對任何人有幫助,但我最近開設了一家 woocommerce 商店,店主在外地時無法整天查看電子郵件以獲取訂單。
因此,通過在這里混合 Hasan 和 Gary 的帖子,我將它們合並為一個,以便在有新訂單時使用 Twilio 通過 SMS 發出通知。
只需將以下內容添加到您的functions.php 並替換accountSID、authKey、SendNumber 和contactNumber 值。 當然,根據您的喜好更改消息。
也用像 ÅÄÖ 這樣的特殊字符對其進行了測試,結果奏效了。
//Send SMS Notification to admin
add_action('woocommerce_order_status_processing', 'send_woo_order_sms', 10, 3);
function send_woo_order_sms ($order_id){
//Get order data
$order = new WC_Order($order_id);
//Get first name from order
$billing_first_name = $order->get_billing_first_name();
//Get last name from order
$billing_last_name = $order->get_billing_last_name();
// Change to your Twilio account SID
$accountSID = 'xxxxxxxxxxxxxxxx';
// Change to your Twilio account Auth Key
$authKey = 'xxxxxxxxxxxxxxxx';
// Change to your Twilio account number
$sendNumber = '+xxxxxxxxxxxxxxxx';
//Change to your verified caller number (receiver of the sms)
$contactNumber = '+xxxxxxxxxxxxxxxx';
//Message to send
$smsMessage = "$billing_first_name $billing_last_name has just placed an order. See order #$order_id.";
// The Twilio API Url
$url = "https://api.twilio.com/2010-04-01/Accounts/".$accountSID."/Messages.json";
// The data being sent to the API
$data = array(
'From' => $sendNumber,
'To' => $contactNumber,
'Body' => $smsMessage
);
// Set the authorisation header
$headers = array( 'Authorization' => 'Basic ' . base64_encode($accountSID . ':' . $authKey));
// Send the POST request and store the response in a variable
$result = wp_remote_post($url, array( 'body' => $data, 'headers' => $headers));
return $order_id;
}
我想它可以很容易地更改為發送給客戶,而不是通過將 contactNumber 更改為計費電話。
$contactNumber = $order->get_billing_phone();
然而,這需要 Twilio 的付費計划。
Ufone 巴基斯坦短信與 woocommerce wordpress 集成
如果您正在尋找與 ufone pakistan sms api bsms ufone pakistan 服務提供商與 woocommerce wordpress 的集成,請在您的函數文件中使用以下代碼
sms api 集成 ufone bsms 與 wordpress woocommerce 感謝本頁上的作者將自定義 SMS API 與 woocommerce 集成
//add this line for calling your function on creation of order in woocommerce
add_action('woocommerce_order_status_processing', 'custom_func', 10, 3);
function custom_func ($order_id) {
$order_details = new WC_Order($order_id);
//fetch all required fields
$billing_phone = $order_details->get_billing_phone();
$billing_name = $order_details->get_billing_first_name();
$billing_last_name = $order_details->get_billing_last_name();
$total_bill = $order_details->get_total();
$textmessage = rawurlencode("Dear $billing_name, Thank you for your order. Your order #$order_id is being processed. Please wait for confirmation call Total Bill = $total_bill");
// Now put HTTP ufone BSMS API URL
$url = "https://bsms.ufone.com/bsms_v8_api/sendapi-0.3.jsp?id=msisdn&message=$textmessage&shortcode=SHORTCODE&lang=English&mobilenum=$billing_phone&password=password&messagetype=Nontransactional";
// NOW WILL CALL FUNCTION CURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
return $order_id;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.