Skip to content

Commit

Permalink
feat(hook): woocommerce order new (#17)
Browse files Browse the repository at this point in the history
* feat(hook): woocommerce order new

* feat: add more details to woocommerce order new

* chore: update label for woocommerce new order callback

* chore: translate woocommerce order new
  • Loading branch information
mahdyar authored Oct 6, 2021
1 parent e860049 commit 4cc9f2d
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 2 deletions.
3 changes: 3 additions & 0 deletions inc/Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public static function get_services()
Telegram\ThemeSwitch::class,
Telegram\PluginActivate::class,
Telegram\PluginDeactivate::class,

// WooCommerce Hooks
Telegram\WooCommerce\WooCommerceOrderNew::class,
];
}

Expand Down
19 changes: 18 additions & 1 deletion inc/Pages/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Admin
['api_key', ''], ['chat_id', ''], ['on_post_publish', '1'],
['on_post_update', '1'], ['on_post_comment', '1'], ['on_login_fail', '1'],
['on_register_user', '1'], ['on_theme_switch', '1'], ['on_plugin_activate', '1'],
['on_plugin_deactivate', '1'],
['on_plugin_deactivate', '1'], ['on_woocommerce_order_new', '0'],
];

public $callbacks;
Expand Down Expand Up @@ -181,6 +181,23 @@ private function set_fields()
'section' => 'hooks_settings'
),
);

$woocommerceArgs = array(
array(
'id' => 'telelog_on_woocommerce_order_new',
'title' => __('WooCommerce New order', 'telelog'),
'callback' => array($this->callbacks, 'telelog_on_woocommerce_order_new'),
'page' => $this->page,
'section' => 'hooks_settings'
),
);

if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
foreach ($woocommerceArgs as $woocommerceArg) {
array_push($args, $woocommerceArg);
}
}

$this->fields = $args;
}
}
10 changes: 10 additions & 0 deletions inc/Pages/Callbacks/AdminCallbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,14 @@ public function telelog_on_plugin_deactivate()

$this->hooks_sanitizer($html);
}

public function telelog_on_woocommerce_order_new()
{
$checked = get_option('telelog_on_woocommerce_order_new');

$html = '<input type="checkbox" id="on_woocommerce_order_new" name="telelog_on_woocommerce_order_new" value="1"' . checked(1, esc_attr($checked), false) . '/>';
$html .= '<label for="on_woocommerce_order_new">' . __('Let you know when a new order in Woocommerce is submited.', 'telelog') . '</label>';

$this->hooks_sanitizer($html);
}
}
40 changes: 40 additions & 0 deletions inc/Telegram/WooCommerce/WooCommerceOrderNew.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
* @package Telelog
*/

namespace Telelog\Inc\Telegram\WooCommerce;

use Telelog\Inc\Telegram\Telegram;

class WooCommerceOrderNew extends Telegram
{
private $onWooCommerceOrderNew;
public function __construct()
{
parent::__construct();

$this->onWooCommerceOrderNew = get_option('telelog_on_woocommerce_order_new');
}
public function register()
{
if ($this->onWooCommerceOrderNew === '1' && in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins'))))
add_action('woocommerce_new_order', array($this, 'woocommerce_order_new'), 10, 1);
}
public function woocommerce_order_new($order_id)
{
$order = wc_get_order( $order_id );
$ip = $order->customer_ip_address;
$order_id = $order->get_id();

$site_url = get_site_url();
$order_url = $site_url . '/wp-admin/post.php?post=' . $order_id . '&action=edit';

$author = $order->get_billing_first_name() . ' ' . $order->get_billing_last_name();
$email = $order->get_billing_email();

$title = __('New WooCommerce order', 'telelog') . ": <a href='$order_url'>$order_id</a>";
$this->alert($title, null, __FUNCTION__, $author, $ip, $email);
}
}
Binary file modified languages/telelog-fa_IR.mo
Binary file not shown.
14 changes: 13 additions & 1 deletion languages/telelog-fa_IR.po
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2021-08-24T11:01:10+00:00\n"
"PO-Revision-Date: 2021-10-02 17:03+0330\n"
"PO-Revision-Date: 2021-10-06 12:51+0330\n"
"X-Generator: Poedit 3.0\n"
"X-Domain: telelog\n"
"Last-Translator: \n"
Expand Down Expand Up @@ -168,3 +168,15 @@ msgstr "وقتی یک افزونه غیرفعال شد به من اطلاع بد
#: inc/Telegram/PluginDeactivate.php:31
msgid "Plugin deactivated"
msgstr "افزونه غیرفعال شد"

#: inc/Pages/Admin.php:188
msgid "WooCommerce New order"
msgstr "سفارش جدید ووکامرس"

#: inc/Pages/Callbacks/AdminCallbacks.php:196
msgid "Let you know when a new order in Woocommerce is submited."
msgstr "وقتی یک سفارش جدید در ووکامرس ثبت شد به من اطلاع بده."

#: inc/Telegram/WooCommerce/WooCommerceOrderNew.php:37
msgid "New WooCommerce order"
msgstr "سفارش جدید ووکامرس"
12 changes: 12 additions & 0 deletions languages/telelog.pot
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,15 @@ msgstr ""
#: inc/Telegram/PluginDeactivate.php:31
msgid "Plugin deactivated"
msgstr ""

#: inc/Pages/Admin.php:188
msgid "WooCommerce New order"
msgstr ""

#: inc/Pages/Callbacks/AdminCallbacks.php:196
msgid "Let you know when a new order in Woocommerce is submited."
msgstr ""

#: inc/Telegram/WooCommerce/WooCommerceOrderNew.php:37
msgid "New WooCommerce order"
msgstr ""

0 comments on commit 4cc9f2d

Please sign in to comment.