2017-09-15 11 views
0

그래서 저는 woocommerce 및 wc 공급 업체 플러그인을 사용하여 사용자 정의 SMS API를 통합하는 프로젝트를 진행하고 있습니다. 불행히도, 나는 이것을위한 특별한 해결책을 찾지 못했습니다. 누구나 실제로 기존 게이트웨이를 지원하는 플러그인에 대해 이야기하고있었습니다. 나는 누군가가 자신의 api를 woocommerce와 통합하기를 원한다면 어떨까요?woocommerce와 사용자 정의 SMS API 통합

마지막으로 아래 주어진 코드를 작성했습니다. 코드는 자식 테마의 function.php로 이동합니다. FYKI, 나는 어떤 통신 업체가 인코딩 된 메시지를 필요로하므로 rawurlencode을 사용하여 텍스트 메시지를 인코딩해야했습니다.

감사합니다.

특별 감사에 : Integrating SMS api with woocommerce , Not sending messages

답변

0
//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; 
}