-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass-plugin.php
More file actions
131 lines (88 loc) · 2.3 KB
/
Copy pathclass-plugin.php
File metadata and controls
131 lines (88 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/**
* Main plugin file.
*
* @package dorzki\WooCommerce\Custom_Email
* @subpackage Plugin
* @author Dor Zuberi <webmaster@dorzki.co.il>
* @link https://www.dorzki.co.il
* @version 1.0.0
*/
namespace dorzki\WooCommerce\Custom_Email;
use dorzki\WooCommerce\Custom_Email\Emails\Custom_Email;
// Block if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class Plugin
*
* @package dorzki\WooCommerce\Custom_Email
*/
class Plugin {
/**
* Plugin instance.
*
* @var null|Plugin
*/
private static $instance = null;
/* ------------------------------------------ */
/**
* Plugin constructor.
*/
public function __construct() {
add_filter( 'woocommerce_email_classes', [ $this, 'register_emails' ] );
add_filter( 'woocommerce_order_actions', [ $this, 'register_actions' ] );
add_action( 'woocommerce_order_action_dorzki_wc_send_custom_email', [ $this, 'send_custom_email' ] );
}
/* ------------------------------------------ */
/**
* Retrieve plugin instance.
*
* @return Plugin|null
*/
public static function get_instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/* ------------------------------------------ */
/**
* Register custom emails.
*
* @param array $emails WooCommerce registered emails.
*
* @return array
*/
public function register_emails( $emails ) {
require_once 'emails/class-custom-email.php';
$emails['custom_email'] = new Custom_Email();
return $emails;
}
/* ------------------------------------------ */
/**
* Register custom order actions.
*
* @param array $actions WooCommerce registered order actions.
*
* @return array
*/
public function register_actions( $actions ) {
$actions['dorzki_wc_send_custom_email'] = __( 'Send Custom Email', 'dorzki-wc-custom-email' );
return $actions;
}
/* ------------------------------------------ */
/**
* Send custom email on request.
*
* @param WC_Order $order current order.
*/
public function send_custom_email( $order ) {
WC()->mailer()->emails['custom_email']->trigger( $order );
// Optional: Add order note.
$order->add_order_note( __( 'Custom Email Sent!', 'dorzki-wc-custom-email' ), false, false );
}
}
// initiate plugin.
Plugin::get_instance();