<a href="https://console.cloud.google.com/apis/credentials">Get Your Api Credentials Here</a> <a href="https://calendar.google.com/calendar">Get your Calender ID</a> <?php include_once("wp-load.php"); function get_calender_events() { $params = array(); /*Get current date*/ $current_date = date('Y-m-d H:i:s'); /*Convert it to google calendar's rfc_format */ $rfc_format = date("c", strtotime($current_date)); $params[] = 'orderBy=startTime'; $params[] ='maxResults=100'; $params[] = 'timeMin='.urlencode($rfc_format); $url_param = ''; foreach($params as $param) { $url_param.= '&'.$param; } $calender_id = "calender_id"; $client_key = "client_key"; $url = "https://www.googleapis.com/calendar/v3/calendars/".$calender_id."/events?key=".$client_key."&singleEvents=true".$url_param; $list_events = wp_remote_post($url, ...
<?php
/*
Plugin Name: Demo SMS
Plugin URI: http://myasa.net
Description: This plugin will integrate Demo SMS API
Author: Sheikh Aamir Wahid
Version: 1.0
Author URI: https://github.com/aamirwahid5
*/
ob_start();
//include "functions.php";
add_action('admin_menu', function() {
add_options_page( 'SMS Settings', 'Demo SMS', 'manage_options', 'mobi-sms-plugin', 'mobiSMS_plugin_page' );
});
add_action( 'woocommerce_order_status_pending', 'mysite_pending', 10, 1);
add_action( 'woocommerce_order_status_failed', 'mysite_failed', 10, 1);
add_action( 'woocommerce_order_status_on-hold', 'mysite_hold', 10, 1);
// Note that it's woocommerce_order_status_on-hold, and NOT on_hold.
add_action( 'woocommerce_order_status_processing', 'mysite_processing', 10, 1);
add_action( 'woocommerce_order_status_completed', 'mysite_completed', 10, 1);
add_action( 'woocommerce_order_status_refunded', 'mysite_refunded', 10, 1);
add_action( 'woocommerce_order_status_cancelled', 'mysite_cancelled', 10, 1);
// add the action
add_action( 'woocommerce_after_cart_item_quantity_update', 'action_woocommerce_after_cart_item_quantity_update', 10, 3 );
//Give SMS Updates to admin on Product Creation
add_action( 'draft_to_publish', 'my_product_update' );
add_action( 'admin_init', function() {
register_setting( 'mobi-sms-plugin-settings', 'map_option_0' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_1' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_2' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_3' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_4' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_5' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_6' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_7' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_8' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_9' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_10' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_11' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_12' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_13' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_14' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_15' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_16' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_17' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_18' );
});
function mysite_pending($order_id) {
$order = new WC_Order( $order_id );
$order_meta = get_post_meta($order_id);
$first_name=$order_meta[_billing_first_name][0];
//getting customer mobile no. from woocommerce
$customer_id = $order->user_id;
$order_date=$order->order_date;
$billing_phone = get_user_meta( $customer_id, 'billing_phone', true );
//get order details
$items = $order->get_items();
foreach ( $items as $item_id => $item_data ) {
$product_id=$item_data['product_id'];
$order_name=$item_data['name'];
$order_qty=$order->get_item_meta($item_id, '_qty', true);
}
$mobiUrl=get_option('map_option_0');
$userId=get_option('map_option_1');
$password=get_option('map_option_2');
$number=get_option('map_option_3');
$value= esc_attr( get_option('map_option_5') ) == 'on' ? 'checked="checked"' : '';
$text=get_option('map_option_6');
//shortcoded text
$sh_text=extract_shortcode($text,$first_name,$product_id,$order_name,$order_qty,$order_date);
//Replace space with %20
$striped_text = preg_replace('/\s+/', '%20', $sh_text);
// Send SMS
send_SMS($mobiUrl,$userId,$password,$billing_phone,$value,$striped_text);
}
function mysite_failed($order_id) {
$order = new WC_Order( $order_id );
$order_meta = get_post_meta($order_id);
$first_name=$order_meta[_billing_first_name][0];
//getting customer mobile no. from woocommerce
$customer_id = $order->user_id;
$order_date=$order->order_date;
$billing_phone = get_user_meta( $customer_id, 'billing_phone', true );
//get order details
$items = $order->get_items();
foreach ( $items as $item_id => $item_data ) {
$product_id=$item_data['product_id'];
$order_name=$item_data['name'];
$order_qty=$order->get_item_meta($item_id, '_qty', true);
}
$mobiUrl=get_option('map_option_0');
$userId=get_option('map_option_1');
$password=get_option('map_option_2');
$number=get_option('map_option_3');
$value= esc_attr( get_option('map_option_7') ) == 'on' ? 'checked="checked"' : '';
$text=get_option('map_option_13');
//shortcoded text
$sh_text=extract_shortcode($text,$first_name,$product_id,$order_name,$order_qty,$order_date);
//Replace space with %20
$striped_text = preg_replace('/\s+/', '%20', $sh_text);
// Send SMS
send_SMS($mobiUrl,$userId,$password,$billing_phone,$value,$striped_text);
}
function mysite_hold($order_id) {
$order = new WC_Order( $order_id );
$order_meta = get_post_meta($order_id);
$first_name=$order_meta[_billing_first_name][0];
//getting customer mobile no. from woocommerce
$customer_id = $order->user_id;
$order_date=$order->order_date;
$billing_phone = get_user_meta( $customer_id, 'billing_phone', true );
//get order details
$items = $order->get_items();
foreach ( $items as $item_id => $item_data ) {
$product_id=$item_data['product_id'];
$order_name=$item_data['name'];
$order_qty=$order->get_item_meta($item_id, '_qty', true);
}
$mobiUrl=get_option('map_option_0');
$userId=get_option('map_option_1');
$password=get_option('map_option_2');
$number=get_option('map_option_3');
$value= esc_attr( get_option('map_option_14') ) == 'on' ? 'checked="checked"' : '';
$text=get_option('map_option_8');
//shortcoded text
$sh_text=extract_shortcode($text,$first_name,$product_id,$order_name,$order_qty,$order_date);
//Replace space with %20
$striped_text = preg_replace('/\s+/', '%20', $sh_text);
// Send SMS
send_SMS($mobiUrl,$userId,$password,$billing_phone,$value,$striped_text);
}
function mysite_processing($order_id) {
$order = new WC_Order( $order_id );
$order_meta = get_post_meta($order_id);
$first_name=$order_meta[_billing_first_name][0];
//getting customer mobile no. from woocommerce
$customer_id = $order->user_id;
$order_date=$order->order_date;
$billing_phone = get_user_meta( $customer_id, 'billing_phone', true );
//get order details
$items = $order->get_items();
foreach ( $items as $item_id => $item_data ) {
$product_id=$item_data['product_id'];
$order_name=$item_data['name'];
$order_qty=$order->get_item_meta($item_id, '_qty', true);
}
$mobiUrl=get_option('map_option_0');
$userId=get_option('map_option_1');
$password=get_option('map_option_2');
$number=get_option('map_option_3');
$value= esc_attr( get_option('map_option_15') ) == 'on' ? 'checked="checked"' : '';
$text=get_option('map_option_9');
//shortcoded text
$sh_text=extract_shortcode($text,$first_name,$product_id,$order_name,$order_qty,$order_date);
//Replace space with %20
$striped_text = preg_replace('/\s+/', '%20', $sh_text);
// Send SMS
send_SMS($mobiUrl,$userId,$password,$billing_phone,$value,$striped_text);
}
function mysite_completed($order_id) {
$order = new WC_Order( $order_id );
$order_meta = get_post_meta($order_id);
$first_name=$order_meta[_billing_first_name][0];
//getting customer mobile no. from woocommerce
$customer_id = $order->user_id;
$order_date=$order->order_date;
$billing_phone = get_user_meta( $customer_id, 'billing_phone', true );
//get order details
$items = $order->get_items();
foreach ( $items as $item_id => $item_data ) {
$product_id=$item_data['product_id'];
$order_name=$item_data['name'];
$order_qty=$order->get_item_meta($item_id, '_qty', true);
}
$mobiUrl=get_option('map_option_0');
$userId=get_option('map_option_1');
$password=get_option('map_option_2');
$number=get_option('map_option_3');
$text=get_option('map_option_10');
$value= esc_attr( get_option('map_option_16') ) == 'on' ? 'checked="checked"' : '';
//shortcoded text
$sh_text=extract_shortcode($text,$first_name,$product_id,$order_name,$order_qty,$order_date);
//Replace space with %20
$striped_text = preg_replace('/\s+/', '%20', $sh_text);
// Send SMS
send_SMS($mobiUrl,$userId,$password,$billing_phone,$value,$striped_text);
}
function mysite_refunded($order_id) {
$order = new WC_Order( $order_id );
$order_meta = get_post_meta($order_id);
$first_name=$order_meta[_billing_first_name][0];
//getting customer mobile no. from woocommerce
$customer_id = $order->user_id;
$order_date=$order->order_date;
$billing_phone = get_user_meta( $customer_id, 'billing_phone', true );
//get order details
$items = $order->get_items();
foreach ( $items as $item_id => $item_data ) {
$product_id=$item_data['product_id'];
$order_name=$item_data['name'];
$order_qty=$order->get_item_meta($item_id, '_qty', true);
}
$mobiUrl=get_option('map_option_0');
$userId=get_option('map_option_1');
$password=get_option('map_option_2');
$number=get_option('map_option_3');
$value= esc_attr( get_option('map_option_17') ) == 'on' ? 'checked="checked"' : '';
$text=get_option('map_option_11');
//shortcoded text
$sh_text=extract_shortcode($text,$first_name,$product_id,$order_name,$order_qty,$order_date);
//Replace space with %20
$striped_text = preg_replace('/\s+/', '%20', $sh_text);
// Send SMS
send_SMS($mobiUrl,$userId,$password,$billing_phone,$value,$striped_text);
}
function mysite_cancelled($order_id) {
$order = new WC_Order( $order_id );
$order_meta = get_post_meta($order_id);
$first_name=$order_meta[_billing_first_name][0];
//getting customer mobile no. from woocommerce
$customer_id = $order->user_id;
$order_date=$order->order_date;
$billing_phone = get_user_meta( $customer_id, 'billing_phone', true );
//get order details
$items = $order->get_items();
foreach ( $items as $item_id => $item_data ) {
$product_id=$item_data['product_id'];
$order_name=$item_data['name'];
$order_qty=$order->get_item_meta($item_id, '_qty', true);
}
//get Values saved in admin panel
$mobiUrl=get_option('map_option_0');
$userId=get_option('map_option_1');
$password=get_option('map_option_2');
$number=get_option('map_option_3');
$text=get_option('map_option_12');
$value= esc_attr( get_option('map_option_18') ) == 'on' ? 'checked="checked"' : '';
//shortcoded text
$sh_text=extract_shortcode($text,$first_name,$product_id,$order_name,$order_qty,$order_date);
//Replace space with %20
$striped_text = preg_replace('/\s+/', '%20', $sh_text);
// Send SMS
send_SMS($mobiUrl,$userId,$password,$billing_phone,$value,$striped_text);
}
//function to extract shortcode
function extract_shortcode($string,$first_name,$product_id,$order_name,$order_qty,$order_date){
$patterns = array();
$patterns[0] = '/\[first-name]/';
$patterns[1] = '/\[product-id]/';
$patterns[2] = '/\[product-name]/';
$patterns[3] = '/\[product-qty]/';
$patterns[4] = '/\[order-date]/';
$replacements = array();
$replacements[0] = $first_name;
$replacements[1] = $product_id;
$replacements[2] = $order_name;
$replacements[3] = $order_qty;
$replacements[4] = $order_date;
return preg_replace($patterns, $replacements, $string);
}
//function to send SMS
function send_SMS($mobiUrl,$userId,$password,$billing_phone,$value,$striped_text){
if($value!=''){
$url = "$mobiUrl?user=$userId&pwd=$password&senderid=ABC&mobileno=$billing_phone&msgtext=$striped_text";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);
echo $curl_scraped_page;
}
}
function mobiSMS_plugin_page() {
?>
<head>
<style>
.test{
width: 100px;
margin-top: 9px;
background: #0085ba;
border: 1px solid #0073aa;
border-radius: 2px;
color: #FFF;
padding: 6px;
font-size: 13px;
cursor: pointer;
font-family: sans-serif;
}
.test:hover
{
background-color:#0792ca;
}
#note{
color: #ef1515;
padding-top: 25px;
}
</style>
</head>
<div class="wrap">
<div id="icon-options-general" class="icon32"> <br>
</div>
<h2><u>Demo SMS API Settings</u></h2>
<form action="options.php" method="post">
<h3>API Settings</h3>
<hr>
<div class="metabox-holder">
<div class="postbox">
<?php
settings_fields( 'mobi-sms-plugin-settings' );
do_settings_sections( 'mobi-sms-plugin-settings' );
?>
<table style="text-align:left; padding-left:20px;padding-top:20px">
<tr>
<th>Demo SMS API</th>
<td><input type="text" placeholder="SMS API URL" name="map_option_0" value="<?php echo esc_attr( get_option('map_option_0') ); ?>" size="50" /></td>
</tr>
<tr>
<th>Your User ID</th>
<td><input type="text" placeholder="User ID" name="map_option_1" value="<?php echo esc_attr( get_option('map_option_1') ); ?>" size="50" /></td>
</tr>
<tr>
<th>Your Password</th>
<td><input type="text" placeholder="Password" name="map_option_2" value="<?php echo esc_attr( get_option('map_option_2') ); ?>" size="50" /></td>
</tr>
<tr>
<th>Admin Mobile Number</th>
<td><input type="text" placeholder="Mobile No." name="map_option_3" value="<?php echo esc_attr( get_option('map_option_3') ); ?>" size="50" /></td>
</tr>
<tr>
<th id="note" colspan='2'>Note: Make sure to SAVE CHANGES first before testing the API!!!</th>
</tr>
<tr>
<td><?php submit_button(); ?></td>
<td><a target="_blank" href="<?php echo esc_attr( get_option('map_option_0') ); ?>?user=<?php echo esc_attr( get_option('map_option_1') ); ?>&pwd=<?php echo esc_attr( get_option('map_option_2') ); ?>&senderid=ABC&mobileno=<?php echo esc_attr( get_option('map_option_3') ); ?>&msgtext=TestedSuccessfully"><input class="test" type="button" value="Test API"/></a>
</td>
</tr>
</table>
</div></div>
<h3>WooCommerce Order Settings</h3>
<hr>
<div class="metabox-holder">
<div class="postbox">
<table style="text-align:left; padding:20px">
<tr style="height:20px;"></tr>
<tr>
<th>Enable Pending Order</th>
<td>
<label>
<input type="checkbox" name="map_option_5" <?php echo esc_attr( get_option('map_option_5') ) == 'on' ? 'checked="checked"' : ''; ?> />Check If you Want to send SMS updates to customer if order is kept pending.
</label><br/>
</td>
</tr>
<tr>
<th>Pending Order Text</th>
<td>
<textarea rows="4" cols="50" name="map_option_6"><?php echo esc_attr( get_option('map_option_6') ); ?></textarea>
</td>
</tr>
<tr style="height:20px;"></tr>
<tr>
<th>Enable Failed Order</th>
<td>
<label>
<input type="checkbox" name="map_option_7" <?php echo esc_attr( get_option('map_option_7') ) == 'on' ? 'checked="checked"' : ''; ?> />Check If you Want to send SMS updates to customer if order is failed.
</label><br/>
</td>
</tr>
<tr>
<th>Failed Order Text</th>
<td>
<textarea rows="4" cols="50" name="map_option_13"><?php echo esc_attr( get_option('map_option_13') ); ?></textarea>
</td>
</tr>
<tr style="height:20px;"></tr>
<tr>
<th>Enable On Hold Order</th>
<td>
<label>
<input type="checkbox" name="map_option_14" <?php echo esc_attr( get_option('map_option_14') ) == 'on' ? 'checked="checked"' : ''; ?> />Check If you Want to send SMS updates to customer if order is on hold.
</label><br/>
</td>
</tr>
<tr>
<th>Hold Order Text</th>
<td>
<textarea rows="4" cols="50" name="map_option_8"><?php echo esc_attr( get_option('map_option_8') ); ?></textarea>
</td>
</tr>
<tr style="height:20px;"></tr>
<tr>
<th>Enable Processing Order</th>
<td>
<label>
<input type="checkbox" name="map_option_15" <?php echo esc_attr( get_option('map_option_15') ) == 'on' ? 'checked="checked"' : ''; ?> />Check If you Want to send SMS updates to customer if order is in Processing State.
</label><br/>
</td>
</tr>
<tr>
<th>Processing Order Text</th>
<td>
<textarea rows="4" cols="50" name="map_option_9" ><?php echo esc_attr( get_option('map_option_9') ); ?></textarea>
</td>
</tr>
<tr style="height:20px;"></tr>
<tr>
<th>Enable Completed Order</th>
<td>
<label>
<input type="checkbox" name="map_option_16" <?php echo esc_attr( get_option('map_option_16') ) == 'on' ? 'checked="checked"' : ''; ?> />Check If you Want to send SMS updates to customer if order is Completed.
</label><br/>
</td>
</tr>
<tr>
<th>Completed Order Text</th>
<td>
<textarea rows="4" cols="50" name="map_option_10"><?php echo esc_attr( get_option('map_option_10') ); ?></textarea>
</td>
</tr>
<tr style="height:20px;"></tr>
<tr>
<th>Enable Refunding Order</th>
<td>
<label>
<input type="checkbox" name="map_option_17" <?php echo esc_attr( get_option('map_option_17') ) == 'on' ? 'checked="checked"' : ''; ?> />Check If you Want to send SMS updates to customer if order is Refunded.
</label><br/>
</td>
</tr>
<tr>
<th>Refunded Order Text</th>
<td>
<textarea rows="4" cols="50" name="map_option_11"><?php echo esc_attr( get_option('map_option_11') ); ?></textarea>
</td>
</tr>
<tr style="height:20px;"></tr>
<tr>
<th>Enable Cancelled Order</th>
<td>
<label>
<input type="checkbox" name="map_option_18" <?php echo esc_attr( get_option('map_option_18') ) == 'on' ? 'checked="checked"' : ''; ?> />Check If you Want to send SMS updates to customer if order is Cancelled.
</label><br/>
</td>
</tr>
<tr>
<th>Cancelled Order Text</th>
<td>
<textarea rows="4" cols="50" name="map_option_12"><?php echo esc_attr( get_option('map_option_12') ); ?></textarea>
</td>
</tr>
<!---
<tr>
<th>Your age</th>
<td>
<select name="map_option_23">
<option value="">— select —</option>
<option value="10-20" <?php //echo esc_attr( get_option('map_option_3') ) == '10-20' ? 'selected="selected"' : ''; ?>>10-30</option>
<option value="20-30" <?php //echo esc_attr( get_option('map_option_3') ) == '20-30' ? 'selected="selected"' : ''; ?>>20-30</option>
<option value="30-50" <?php //echo esc_attr( get_option('map_option_3') ) == '30-50' ? 'selected="selected"' : ''; ?>>30-50</option>
</select>
</td>
</tr>
<tr>
<th>Your gender</th>
<td>
<label>
<input type="radio" name="map_option_4" value="male" <?php //echo esc_attr( get_option('map_option_4') ) == 'male' ? 'checked="checked"' : ''; ?> /> Male <br/>
</label>
<label>
<input type="radio" name="map_option_4" value="female" <?php //echo esc_attr( get_option('map_option_4') ) == 'female' ? 'checked="checked"' : ''; ?> /> Female
</label>
</td>
</tr>
--->
<tr>
<td><?php submit_button(); ?></td>
</tr>
<tr><td colspan="2" align="center"> </td></tr>
</table>
</div></div>
</form>
</div>
<?php
}
/*
Plugin Name: Demo SMS
Plugin URI: http://myasa.net
Description: This plugin will integrate Demo SMS API
Author: Sheikh Aamir Wahid
Version: 1.0
Author URI: https://github.com/aamirwahid5
*/
ob_start();
//include "functions.php";
add_action('admin_menu', function() {
add_options_page( 'SMS Settings', 'Demo SMS', 'manage_options', 'mobi-sms-plugin', 'mobiSMS_plugin_page' );
});
add_action( 'woocommerce_order_status_pending', 'mysite_pending', 10, 1);
add_action( 'woocommerce_order_status_failed', 'mysite_failed', 10, 1);
add_action( 'woocommerce_order_status_on-hold', 'mysite_hold', 10, 1);
// Note that it's woocommerce_order_status_on-hold, and NOT on_hold.
add_action( 'woocommerce_order_status_processing', 'mysite_processing', 10, 1);
add_action( 'woocommerce_order_status_completed', 'mysite_completed', 10, 1);
add_action( 'woocommerce_order_status_refunded', 'mysite_refunded', 10, 1);
add_action( 'woocommerce_order_status_cancelled', 'mysite_cancelled', 10, 1);
// add the action
add_action( 'woocommerce_after_cart_item_quantity_update', 'action_woocommerce_after_cart_item_quantity_update', 10, 3 );
//Give SMS Updates to admin on Product Creation
add_action( 'draft_to_publish', 'my_product_update' );
add_action( 'admin_init', function() {
register_setting( 'mobi-sms-plugin-settings', 'map_option_0' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_1' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_2' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_3' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_4' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_5' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_6' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_7' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_8' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_9' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_10' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_11' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_12' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_13' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_14' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_15' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_16' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_17' );
register_setting( 'mobi-sms-plugin-settings', 'map_option_18' );
});
function mysite_pending($order_id) {
$order = new WC_Order( $order_id );
$order_meta = get_post_meta($order_id);
$first_name=$order_meta[_billing_first_name][0];
//getting customer mobile no. from woocommerce
$customer_id = $order->user_id;
$order_date=$order->order_date;
$billing_phone = get_user_meta( $customer_id, 'billing_phone', true );
//get order details
$items = $order->get_items();
foreach ( $items as $item_id => $item_data ) {
$product_id=$item_data['product_id'];
$order_name=$item_data['name'];
$order_qty=$order->get_item_meta($item_id, '_qty', true);
}
$mobiUrl=get_option('map_option_0');
$userId=get_option('map_option_1');
$password=get_option('map_option_2');
$number=get_option('map_option_3');
$value= esc_attr( get_option('map_option_5') ) == 'on' ? 'checked="checked"' : '';
$text=get_option('map_option_6');
//shortcoded text
$sh_text=extract_shortcode($text,$first_name,$product_id,$order_name,$order_qty,$order_date);
//Replace space with %20
$striped_text = preg_replace('/\s+/', '%20', $sh_text);
// Send SMS
send_SMS($mobiUrl,$userId,$password,$billing_phone,$value,$striped_text);
}
function mysite_failed($order_id) {
$order = new WC_Order( $order_id );
$order_meta = get_post_meta($order_id);
$first_name=$order_meta[_billing_first_name][0];
//getting customer mobile no. from woocommerce
$customer_id = $order->user_id;
$order_date=$order->order_date;
$billing_phone = get_user_meta( $customer_id, 'billing_phone', true );
//get order details
$items = $order->get_items();
foreach ( $items as $item_id => $item_data ) {
$product_id=$item_data['product_id'];
$order_name=$item_data['name'];
$order_qty=$order->get_item_meta($item_id, '_qty', true);
}
$mobiUrl=get_option('map_option_0');
$userId=get_option('map_option_1');
$password=get_option('map_option_2');
$number=get_option('map_option_3');
$value= esc_attr( get_option('map_option_7') ) == 'on' ? 'checked="checked"' : '';
$text=get_option('map_option_13');
//shortcoded text
$sh_text=extract_shortcode($text,$first_name,$product_id,$order_name,$order_qty,$order_date);
//Replace space with %20
$striped_text = preg_replace('/\s+/', '%20', $sh_text);
// Send SMS
send_SMS($mobiUrl,$userId,$password,$billing_phone,$value,$striped_text);
}
function mysite_hold($order_id) {
$order = new WC_Order( $order_id );
$order_meta = get_post_meta($order_id);
$first_name=$order_meta[_billing_first_name][0];
//getting customer mobile no. from woocommerce
$customer_id = $order->user_id;
$order_date=$order->order_date;
$billing_phone = get_user_meta( $customer_id, 'billing_phone', true );
//get order details
$items = $order->get_items();
foreach ( $items as $item_id => $item_data ) {
$product_id=$item_data['product_id'];
$order_name=$item_data['name'];
$order_qty=$order->get_item_meta($item_id, '_qty', true);
}
$mobiUrl=get_option('map_option_0');
$userId=get_option('map_option_1');
$password=get_option('map_option_2');
$number=get_option('map_option_3');
$value= esc_attr( get_option('map_option_14') ) == 'on' ? 'checked="checked"' : '';
$text=get_option('map_option_8');
//shortcoded text
$sh_text=extract_shortcode($text,$first_name,$product_id,$order_name,$order_qty,$order_date);
//Replace space with %20
$striped_text = preg_replace('/\s+/', '%20', $sh_text);
// Send SMS
send_SMS($mobiUrl,$userId,$password,$billing_phone,$value,$striped_text);
}
function mysite_processing($order_id) {
$order = new WC_Order( $order_id );
$order_meta = get_post_meta($order_id);
$first_name=$order_meta[_billing_first_name][0];
//getting customer mobile no. from woocommerce
$customer_id = $order->user_id;
$order_date=$order->order_date;
$billing_phone = get_user_meta( $customer_id, 'billing_phone', true );
//get order details
$items = $order->get_items();
foreach ( $items as $item_id => $item_data ) {
$product_id=$item_data['product_id'];
$order_name=$item_data['name'];
$order_qty=$order->get_item_meta($item_id, '_qty', true);
}
$mobiUrl=get_option('map_option_0');
$userId=get_option('map_option_1');
$password=get_option('map_option_2');
$number=get_option('map_option_3');
$value= esc_attr( get_option('map_option_15') ) == 'on' ? 'checked="checked"' : '';
$text=get_option('map_option_9');
//shortcoded text
$sh_text=extract_shortcode($text,$first_name,$product_id,$order_name,$order_qty,$order_date);
//Replace space with %20
$striped_text = preg_replace('/\s+/', '%20', $sh_text);
// Send SMS
send_SMS($mobiUrl,$userId,$password,$billing_phone,$value,$striped_text);
}
function mysite_completed($order_id) {
$order = new WC_Order( $order_id );
$order_meta = get_post_meta($order_id);
$first_name=$order_meta[_billing_first_name][0];
//getting customer mobile no. from woocommerce
$customer_id = $order->user_id;
$order_date=$order->order_date;
$billing_phone = get_user_meta( $customer_id, 'billing_phone', true );
//get order details
$items = $order->get_items();
foreach ( $items as $item_id => $item_data ) {
$product_id=$item_data['product_id'];
$order_name=$item_data['name'];
$order_qty=$order->get_item_meta($item_id, '_qty', true);
}
$mobiUrl=get_option('map_option_0');
$userId=get_option('map_option_1');
$password=get_option('map_option_2');
$number=get_option('map_option_3');
$text=get_option('map_option_10');
$value= esc_attr( get_option('map_option_16') ) == 'on' ? 'checked="checked"' : '';
//shortcoded text
$sh_text=extract_shortcode($text,$first_name,$product_id,$order_name,$order_qty,$order_date);
//Replace space with %20
$striped_text = preg_replace('/\s+/', '%20', $sh_text);
// Send SMS
send_SMS($mobiUrl,$userId,$password,$billing_phone,$value,$striped_text);
}
function mysite_refunded($order_id) {
$order = new WC_Order( $order_id );
$order_meta = get_post_meta($order_id);
$first_name=$order_meta[_billing_first_name][0];
//getting customer mobile no. from woocommerce
$customer_id = $order->user_id;
$order_date=$order->order_date;
$billing_phone = get_user_meta( $customer_id, 'billing_phone', true );
//get order details
$items = $order->get_items();
foreach ( $items as $item_id => $item_data ) {
$product_id=$item_data['product_id'];
$order_name=$item_data['name'];
$order_qty=$order->get_item_meta($item_id, '_qty', true);
}
$mobiUrl=get_option('map_option_0');
$userId=get_option('map_option_1');
$password=get_option('map_option_2');
$number=get_option('map_option_3');
$value= esc_attr( get_option('map_option_17') ) == 'on' ? 'checked="checked"' : '';
$text=get_option('map_option_11');
//shortcoded text
$sh_text=extract_shortcode($text,$first_name,$product_id,$order_name,$order_qty,$order_date);
//Replace space with %20
$striped_text = preg_replace('/\s+/', '%20', $sh_text);
// Send SMS
send_SMS($mobiUrl,$userId,$password,$billing_phone,$value,$striped_text);
}
function mysite_cancelled($order_id) {
$order = new WC_Order( $order_id );
$order_meta = get_post_meta($order_id);
$first_name=$order_meta[_billing_first_name][0];
//getting customer mobile no. from woocommerce
$customer_id = $order->user_id;
$order_date=$order->order_date;
$billing_phone = get_user_meta( $customer_id, 'billing_phone', true );
//get order details
$items = $order->get_items();
foreach ( $items as $item_id => $item_data ) {
$product_id=$item_data['product_id'];
$order_name=$item_data['name'];
$order_qty=$order->get_item_meta($item_id, '_qty', true);
}
//get Values saved in admin panel
$mobiUrl=get_option('map_option_0');
$userId=get_option('map_option_1');
$password=get_option('map_option_2');
$number=get_option('map_option_3');
$text=get_option('map_option_12');
$value= esc_attr( get_option('map_option_18') ) == 'on' ? 'checked="checked"' : '';
//shortcoded text
$sh_text=extract_shortcode($text,$first_name,$product_id,$order_name,$order_qty,$order_date);
//Replace space with %20
$striped_text = preg_replace('/\s+/', '%20', $sh_text);
// Send SMS
send_SMS($mobiUrl,$userId,$password,$billing_phone,$value,$striped_text);
}
//function to extract shortcode
function extract_shortcode($string,$first_name,$product_id,$order_name,$order_qty,$order_date){
$patterns = array();
$patterns[0] = '/\[first-name]/';
$patterns[1] = '/\[product-id]/';
$patterns[2] = '/\[product-name]/';
$patterns[3] = '/\[product-qty]/';
$patterns[4] = '/\[order-date]/';
$replacements = array();
$replacements[0] = $first_name;
$replacements[1] = $product_id;
$replacements[2] = $order_name;
$replacements[3] = $order_qty;
$replacements[4] = $order_date;
return preg_replace($patterns, $replacements, $string);
}
//function to send SMS
function send_SMS($mobiUrl,$userId,$password,$billing_phone,$value,$striped_text){
if($value!=''){
$url = "$mobiUrl?user=$userId&pwd=$password&senderid=ABC&mobileno=$billing_phone&msgtext=$striped_text";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);
echo $curl_scraped_page;
}
}
function mobiSMS_plugin_page() {
?>
<head>
<style>
.test{
width: 100px;
margin-top: 9px;
background: #0085ba;
border: 1px solid #0073aa;
border-radius: 2px;
color: #FFF;
padding: 6px;
font-size: 13px;
cursor: pointer;
font-family: sans-serif;
}
.test:hover
{
background-color:#0792ca;
}
#note{
color: #ef1515;
padding-top: 25px;
}
</style>
</head>
<div class="wrap">
<div id="icon-options-general" class="icon32"> <br>
</div>
<h2><u>Demo SMS API Settings</u></h2>
<form action="options.php" method="post">
<h3>API Settings</h3>
<hr>
<div class="metabox-holder">
<div class="postbox">
<?php
settings_fields( 'mobi-sms-plugin-settings' );
do_settings_sections( 'mobi-sms-plugin-settings' );
?>
<table style="text-align:left; padding-left:20px;padding-top:20px">
<tr>
<th>Demo SMS API</th>
<td><input type="text" placeholder="SMS API URL" name="map_option_0" value="<?php echo esc_attr( get_option('map_option_0') ); ?>" size="50" /></td>
</tr>
<tr>
<th>Your User ID</th>
<td><input type="text" placeholder="User ID" name="map_option_1" value="<?php echo esc_attr( get_option('map_option_1') ); ?>" size="50" /></td>
</tr>
<tr>
<th>Your Password</th>
<td><input type="text" placeholder="Password" name="map_option_2" value="<?php echo esc_attr( get_option('map_option_2') ); ?>" size="50" /></td>
</tr>
<tr>
<th>Admin Mobile Number</th>
<td><input type="text" placeholder="Mobile No." name="map_option_3" value="<?php echo esc_attr( get_option('map_option_3') ); ?>" size="50" /></td>
</tr>
<tr>
<th id="note" colspan='2'>Note: Make sure to SAVE CHANGES first before testing the API!!!</th>
</tr>
<tr>
<td><?php submit_button(); ?></td>
<td><a target="_blank" href="<?php echo esc_attr( get_option('map_option_0') ); ?>?user=<?php echo esc_attr( get_option('map_option_1') ); ?>&pwd=<?php echo esc_attr( get_option('map_option_2') ); ?>&senderid=ABC&mobileno=<?php echo esc_attr( get_option('map_option_3') ); ?>&msgtext=TestedSuccessfully"><input class="test" type="button" value="Test API"/></a>
</td>
</tr>
</table>
</div></div>
<h3>WooCommerce Order Settings</h3>
<hr>
<div class="metabox-holder">
<div class="postbox">
<table style="text-align:left; padding:20px">
<tr style="height:20px;"></tr>
<tr>
<th>Enable Pending Order</th>
<td>
<label>
<input type="checkbox" name="map_option_5" <?php echo esc_attr( get_option('map_option_5') ) == 'on' ? 'checked="checked"' : ''; ?> />Check If you Want to send SMS updates to customer if order is kept pending.
</label><br/>
</td>
</tr>
<tr>
<th>Pending Order Text</th>
<td>
<textarea rows="4" cols="50" name="map_option_6"><?php echo esc_attr( get_option('map_option_6') ); ?></textarea>
</td>
</tr>
<tr style="height:20px;"></tr>
<tr>
<th>Enable Failed Order</th>
<td>
<label>
<input type="checkbox" name="map_option_7" <?php echo esc_attr( get_option('map_option_7') ) == 'on' ? 'checked="checked"' : ''; ?> />Check If you Want to send SMS updates to customer if order is failed.
</label><br/>
</td>
</tr>
<tr>
<th>Failed Order Text</th>
<td>
<textarea rows="4" cols="50" name="map_option_13"><?php echo esc_attr( get_option('map_option_13') ); ?></textarea>
</td>
</tr>
<tr style="height:20px;"></tr>
<tr>
<th>Enable On Hold Order</th>
<td>
<label>
<input type="checkbox" name="map_option_14" <?php echo esc_attr( get_option('map_option_14') ) == 'on' ? 'checked="checked"' : ''; ?> />Check If you Want to send SMS updates to customer if order is on hold.
</label><br/>
</td>
</tr>
<tr>
<th>Hold Order Text</th>
<td>
<textarea rows="4" cols="50" name="map_option_8"><?php echo esc_attr( get_option('map_option_8') ); ?></textarea>
</td>
</tr>
<tr style="height:20px;"></tr>
<tr>
<th>Enable Processing Order</th>
<td>
<label>
<input type="checkbox" name="map_option_15" <?php echo esc_attr( get_option('map_option_15') ) == 'on' ? 'checked="checked"' : ''; ?> />Check If you Want to send SMS updates to customer if order is in Processing State.
</label><br/>
</td>
</tr>
<tr>
<th>Processing Order Text</th>
<td>
<textarea rows="4" cols="50" name="map_option_9" ><?php echo esc_attr( get_option('map_option_9') ); ?></textarea>
</td>
</tr>
<tr style="height:20px;"></tr>
<tr>
<th>Enable Completed Order</th>
<td>
<label>
<input type="checkbox" name="map_option_16" <?php echo esc_attr( get_option('map_option_16') ) == 'on' ? 'checked="checked"' : ''; ?> />Check If you Want to send SMS updates to customer if order is Completed.
</label><br/>
</td>
</tr>
<tr>
<th>Completed Order Text</th>
<td>
<textarea rows="4" cols="50" name="map_option_10"><?php echo esc_attr( get_option('map_option_10') ); ?></textarea>
</td>
</tr>
<tr style="height:20px;"></tr>
<tr>
<th>Enable Refunding Order</th>
<td>
<label>
<input type="checkbox" name="map_option_17" <?php echo esc_attr( get_option('map_option_17') ) == 'on' ? 'checked="checked"' : ''; ?> />Check If you Want to send SMS updates to customer if order is Refunded.
</label><br/>
</td>
</tr>
<tr>
<th>Refunded Order Text</th>
<td>
<textarea rows="4" cols="50" name="map_option_11"><?php echo esc_attr( get_option('map_option_11') ); ?></textarea>
</td>
</tr>
<tr style="height:20px;"></tr>
<tr>
<th>Enable Cancelled Order</th>
<td>
<label>
<input type="checkbox" name="map_option_18" <?php echo esc_attr( get_option('map_option_18') ) == 'on' ? 'checked="checked"' : ''; ?> />Check If you Want to send SMS updates to customer if order is Cancelled.
</label><br/>
</td>
</tr>
<tr>
<th>Cancelled Order Text</th>
<td>
<textarea rows="4" cols="50" name="map_option_12"><?php echo esc_attr( get_option('map_option_12') ); ?></textarea>
</td>
</tr>
<!---
<tr>
<th>Your age</th>
<td>
<select name="map_option_23">
<option value="">— select —</option>
<option value="10-20" <?php //echo esc_attr( get_option('map_option_3') ) == '10-20' ? 'selected="selected"' : ''; ?>>10-30</option>
<option value="20-30" <?php //echo esc_attr( get_option('map_option_3') ) == '20-30' ? 'selected="selected"' : ''; ?>>20-30</option>
<option value="30-50" <?php //echo esc_attr( get_option('map_option_3') ) == '30-50' ? 'selected="selected"' : ''; ?>>30-50</option>
</select>
</td>
</tr>
<tr>
<th>Your gender</th>
<td>
<label>
<input type="radio" name="map_option_4" value="male" <?php //echo esc_attr( get_option('map_option_4') ) == 'male' ? 'checked="checked"' : ''; ?> /> Male <br/>
</label>
<label>
<input type="radio" name="map_option_4" value="female" <?php //echo esc_attr( get_option('map_option_4') ) == 'female' ? 'checked="checked"' : ''; ?> /> Female
</label>
</td>
</tr>
--->
<tr>
<td><?php submit_button(); ?></td>
</tr>
<tr><td colspan="2" align="center"> </td></tr>
</table>
</div></div>
</form>
</div>
<?php
}
Comments
Post a Comment