I have this free plugin for notifying users via SMS when there is an Order Status change/Order Note in WooCommerce, it is working well with the current API Integrated in codes below, So i need to twist it with another SMS Provider API and also i need when a user place a new order should also get SMS Notification
Below is the Simple Codes of a Plugin (CODE 1)
<?php
/**
* Plugin Name: Techipress SMS Notifier
* Plugin URI: https://github.com/omukiguy/techiepress-sms-notifier
* Author: Techipress
* Author URI: https://github.com/omukiguy/techiepress-sms-notifier
* Description: Send SMS Notifications from Woocommerce Order Notes and Order Status Changes.
* Version: 0.0.1
*/
// Event of a new email for the order - change in status
add_action( 'woocommerce_order_status_changed', 'techiepress_send_sms_on_new_order_status', 10, 4 );
// Event of the order note
add_action( 'woocommerce_new_customer_note_notification', 'techiepress_send_sms_on_new_order_notes', 10, 1 );
function techiepress_send_sms_on_new_order_status( $order_id, $old_status, $new_status, $order ) {
// Get the order Object
$my_order = wc_get_order( $order_id );
$firstname = $my_order->get_billing_first_name(); // firstname
$phone = $my_order->get_billing_phone(); // Phone
$shopname = get_option( 'woocommerce_email_from_name');
$default_sms_message = "Thank you $firstname for shopping with $shopname. Your Order #$orderid is $new_status";
techiepress_send_sms_to_customer( $phone, $default_sms_message, $shopname );
}
function techiepress_send_sms_on_new_order_notes( $email_args ) {
$order = wc_get_order( $email_args['order_id'] );
$note = $email_args['customer_note'];
$phone = $order->get_billing_phone(); // Phone
$shopname = get_option( 'woocommerce_email_from_name');
techiepress_send_sms_to_customer( $phone, $note, $shopname );
}
function techiepress_send_sms_to_customer( $phone="NULL", $default_sms_message, $shopname ) {
if ( 'NULL' === $phone ) {
return;
}
$msgdata = array(
'method' => 'SendSms',
'userdata' => array(
'username' => 'Liz',
'password' => 'Plugin',
),
'msgdata' => array(
array(
'number' => $phone,
'message' => $default_sms_message,
'senderid' => $shopname,
)
)
);
$url="http://sms.sukumasms.com/api/v1/json/";
$arguments = array(
'method' => 'POST',
'body' => json_encode( $msgdata ),
);
$response = wp_remote_post( $url, $arguments );
if ( is_wp_error( $response ) ) {
$error_message = $response->get_error_message();
return "Something went wrong: $error_message";
}
}
This below is an API of a new SMS Provider For Post Request
Method-1: Using POST Request (CODE 2)
Post Request JSON Format
{
"api_id": yourapiid,
"api_password": yourapipassword,
"sms_type": T,
"encoding": T,
"sender_id": ASMSC,
"phonenumber": 255714900900,
"templateid": null,
"textmessage":test message,
"V1": null,
"V2": null,
"V3": null,
"V4": null,
"V5": null,
"ValidityPeriodInSeconds": 60,
"uid":"xyz",
"callback_url":"https://example.com/",
"pe_id":NULL,
"template_id":NULL
}
There Sample GET Format look like this
https://api.sprintsmsservice.com/api/SendSMS?api_id=APIUSERNAME&api_password=APIPASSWORD&sms_type=T&encoding=T&sender_id=ChonryOTP&phonenumber=255714892151&textmessage=test
And i think this is there URL
https://api.sprintsmsservice.com/api/SendSMS
So I’m seeking for a help on how to remove existing API in the Plugin Codes (CODE 1) and intergrate with a new SMS Provider API (CODE 2) as I’m not an expert with PHP and WooCommerce so any help will be appreciated
You need to sign in to view this answers