The Lounge
Need wordpress programmer/ PHP LOL HELP Please
Submitted by Xnite, 28-02-2018, 02:22 AM, Thread ID: 77550
Thread Closed
Sup guys
I have a Wordpress plugin that a guy made its simple and neat the plugin uses PushOver to send the notification to my Phone but it uses Woocommerce I get the order Name and How many but I don't get the customer address through. Code here
I have a Wordpress plugin that a guy made its simple and neat the plugin uses PushOver to send the notification to my Phone but it uses Woocommerce I get the order Name and How many but I don't get the customer address through. Code here
Code:
<?php
/*
* Plugin Name: SB Woo Pushover Notifications
* Plugin URI: http://www.sean-barton.co.uk
* Description: A plugin to send PUSH notifications to site administrators using Pushover.net
* Author: Sean Barton - Tortoise IT
* Version: 1.1
* Author URI: http://www.sean-barton.co.uk
*/
add_action('init', 'sb_woo_po_init');
function sb_woo_po_init() {
add_action('admin_menu', 'sb_woo_po_submenu');
add_action( 'woocommerce_payment_complete', 'sb_woo_po_payment_processing' );
//add_action( 'woocommerce_order_status_processing', 'sb_woo_po_payment_processing' );
}
function sb_woo_po_submenu() {
add_submenu_page(
'options-general.php',
'SB Woo Pushover',
'SB Woo Pushover',
'manage_options',
'sb_woo_po',
'sb_woo_po_submenu_cb' );
}
function sb_woo_po_box_start($title) {
return '<div class="postbox">
<h2 class="hndle">' . $title . '</h2>
<div class="inside">';
}
function sb_woo_po_box_end() {
return ' </div>
</div>';
}
function sb_woo_po_submenu_cb() {
echo '<div class="wrap"><div id="icon-tools" class="icon32"></div>';
echo '<h2>SB Woo Pushover Notifications</h2>';
echo '<div id="poststuff">';
echo '<div id="post-body" class="metabox-holder columns-2">';
if (isset($_POST['sb_woo_po_edit_submit'])) {
update_option('sb_woo_po_app_key', $_POST['sb_woo_po_app_key']);
update_option('sb_woo_po_user_key', $_POST['sb_woo_po_user_key']);
echo '<div id="message" class="updated fade"><p>Settings saved successfully</p></div>';
}
echo '<p>This plugin will send a Pushover notification to administrators when orders come in to your WooCommerce store. Enter pipe separated keys below for those wanting to receive notifications</p>';
echo '<form method="POST">';
echo sb_woo_po_box_start('SB Woo Pushover Notifications - Settings');
$key = get_option('sb_woo_po_app_key');
echo '<label style="display: inline-block; margin-right: 20px;">App Key</label><input style="width: 350px;" name="sb_woo_po_app_key" value="' . $key . '" />';
echo '<p>(Pushover Keys can be obtained for free from <a href="https://pushover.net/" target="_blank">https://pushover.net/</a>)</p>';
$userkey = get_option('sb_woo_po_user_key');
echo '<label style="display: inline-block; margin-right: 20px;">User Keys</label><input style="width: 350px;" name="sb_woo_po_user_key" value="' . $userkey . '" />';
echo '<p>(Pipe separated for multiple users. No spaces)</p>';
echo sb_woo_po_box_end();
echo '<p id="submit"><input type="submit" name="sb_woo_po_edit_submit" class="button-primary" value="Save Settings" /></p>';
echo '</form>';
echo '</div>';
echo '</div>';
echo '</div>';
}
function sb_woo_po_payment_processing( $order_id ) {
$order = new WC_Order( $order_id );
$items = $order->get_items();
foreach ( $items as $order_item_id=>$item ) {
if ($app_key = get_option('sb_woo_po_app_key')) {
if ($user_key = get_option('sb_woo_po_user_key')) {
$qty = wc_get_order_item_meta($order_item_id, '_qty', true);
$line_total = wc_get_order_item_meta($order_item_id, '_line_total', true);
$product_id = wc_get_order_item_meta($order_item_id, '_product_id', true);
$line_total = wc_get_order_item_meta($order_item_id, '_line_total', true);
$currency = get_option('woocommerce_currency');
$user_keys = explode('|', $user_key);
foreach ($user_keys as $user_key) {
$args = array(
'token'=>$app_key
, 'user'=>$user_key
, 'title'=>get_bloginfo('blogname') . ' - Sale Made!'
, 'sound'=>'cashregister'
, 'message'=>$qty . ' x ' . $item['name'] . '. ' . $currency . ' ' . $line_total
);
$data_string = http_build_query($args);
$ch = curl_init('https://api.pushover.net/1/messages.json');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen($data_string)));
curl_exec($ch);
curl_close($ch);
}
}
}
}
}
?>
Users browsing this thread: 1 Guest(s)