Categories
order-notifications sms-notifications tips tutorials

How to add custom SMS Gateways to Ultimate SMS Notifications ?

Are you a WordPress developer, a web agency or more looking for a way to send SMS to customers buying on the WooCommerce store you’ve just built ?

In order to add a new SMS Gateway to the plugin Ultimate SMS & WhatsApp Notifications for WooCommerce, you must have knowledge in writing WordPress plugins.

If you’re just starting, here is the official WordPress guideline explaining how to get started with a WordPress plugin ?

Once you grab the basics of WordPress programming, we can go to the next step.

Into your installed theme functions.php or a custom plugin you’re creating,
add the following code to get the basic hooks to make it work :

<?php

// This hook remove the API Key fields into the WP dashboard.
add_filter('woo_usn_edit_sms_gateways_fields_html','__return_false');

add_action('admin_enqueue_scripts', function(){
    // enqueue a custom js file in other to manipulate easily the fields.
    wp_enqueue_script(
        'your-script-js-name',
        plugin_dir_url( __DIR__ ) . 'script.js',
        array(
            'jquery',
            'jquery-ui-tooltip',
            'wp-hooks'
        ),
        uniqid(), // for preventing it from being cached.
        false
    );
});

/**
* @param mixed $success Success code passed to the function
* @param mixed $data    Data passed by AJAX to the function
*/
add_filter('woo_usn_save_credentials_status', function( $success, $data ) {
    // do your things here by using the data shared to the function
    return $success; // you must return 0 for failed or 1 for success
}, 50, 2 );


/**
* @param mixed $success Success code passed to the function
* @param mixed $api_choosed    API Name choosed you defined
*/
add_filter('woo_usn_delete_credentials_status', function( $success, $api_choosed ) {
    // do your things here by using the data shared to the function
    return $success; // you must return 0 for failed or 1 for success
}, 50, 2 );


/**
* @param mixed $status Status code.
* @param mixed $sms_api SMS API.
* @param mixed $phone_number Phone Number
* @param mixed $message_to_send    Message to send.
*/
add_filter( 'woo_usn_send_sms_to_customer' , function( $status, $sms_api, $phone_number, $message_to_send  ) {
    // you can put your code here, then send the sms to your custom sms api and do whatever other operations you would like to do.
    return $status; // you must return 200 if the sms send is successfull, 400 if he failed.
}, 10, 4 );

In order to manage the fields concerning your SMS Gateways into the dashboard, you will need to create a new JS file and add the following code :

(function ($) {
    "use strict";
    $(document).ready(function () {

        // send data to the backend php
        wp.hooks.addFilter('woo_usn_save_gateways_data', 'woo_usn', function( d ){ 
            return { 
                'api_choosed'  : 'your_api_name_here',
                'first_api_key' : 'IUYIUYYU', // you must get the fields entered from the settings page
                'second_Api_key' : 'jkhHKHKKJGK', // you must provide the fields entered from the settings page
                // you can add any aditional data that is needed to make the connection to your api successfull
            };
        });

        // delete data from the backend php
        wp.hooks.addFilter('woo_usn_delete_gateways_data', 'woo_usn', function( d ){ 
            return { 
            'api_choosed' : 'your_api_name_here'
            };
        });
    });
})(jQuery);

Once you’ve rigorously followed the steps, you can test using the Send Test SMS block to confirm your custom integration is working. If you don’t know where the Send test SMS block is, follow this tutorial to find where it is :

Once you’ve followed the step mentioned, you can send orders notifications, bulk SMS and more using your custom SMS Gateways.

Find the full code of this article on our repository.

If you are still encountering other issues, feel free to leave us a message to our live chat.


Leave a Reply

Your email address will not be published. Required fields are marked *

Comment moderation is enabled. Your comment may take some time to appear.