【问题标题】:Integrating custom SMS API with woocommerce将自定义 SMS API 与 woocommerce 集成
【发布时间】:2018-02-24 16:49:28
【问题描述】:

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

最后,我想出了下面给出的自己的代码。代码转到您的子主题中的 function.php。仅供参考,我不得不使用 rawurlencode 对文本消息进行编码,因为某些电信公司需要编码消息。

谢谢。

特别感谢:Integrating SMS api with woocommerce , Not sending messages

【问题讨论】:

    标签: php wordpress api woocommerce sms


    【解决方案1】:

    不确定这是否对任何人有帮助,但我最近开设了一家 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 = $order->get_billing_phone();

    然而,这需要 Twilio 的付费计划。

    【讨论】:

      【解决方案2】:

      Ufone 巴基斯坦短信与 woocommerce wordpress 集成

      如果您正在寻找与 ufone pakistan sms api bsms ufone pakistan 服务提供商与 woocommerce wordpress 的集成,请在您的函数文件中使用以下代码

      短信 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;
      }
      

      【讨论】:

        【解决方案3】:

        我自己最近遇到了这个挑战,我找到了一种使用插件从 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/

        【讨论】:

          【解决方案4】:
          //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;
          }
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2022-06-10
            • 1970-01-01
            • 2015-06-26
            • 2018-10-29
            • 2020-02-11
            • 2021-05-16
            • 2016-06-20
            • 1970-01-01
            相关资源
            最近更新 更多