提问者:小点点

将自定义SMS API与woocommerce集成


所以我一直在做一个项目,将自定义SMS API与woocommerce和wc供应商插件集成在一起。不幸的是,我没有找到任何特别的解决方案。每个人都在谈论一些实际上支持现有网关的插件。我想知道如果有人想将自己的api与woocommerce集成,该怎么办!

最后,我提出了自己的代码,如下所示。代码开始运行。在您的子主题中使用php。FYKI,我不得不使用rawurlencode对文本消息进行编码,因为一些电信公司需要编码消息。

非常感谢。

特别感谢:将SMS api与woocommerce集成,不发送消息


共3个答案

匿名用户

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

匿名用户

我最近也遇到了这个挑战,我找到了一个简单的方法,通过插件从WooCommerce发送通知短信,但我需要一些东西以我自己的方式发送消息。

我最终使用了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通过短信发出通知。

只需将以下内容添加到您的函数中。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=$order-

然而,这需要在Twilio制定一个付费计划。