-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcustom-email-manager.php
64 lines (49 loc) · 1.8 KB
/
custom-email-manager.php
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
<?php
/**
* Handles email sending
*/
class Custom_Email_Manager {
/**
* Constructor sets up actions
*/
public function __construct() {
// template path
define( 'CUSTOM_TEMPLATE_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) . '/templates/' );
// hook for when order status is changed
add_action( 'woocommerce_order_status_pending', array( &$this, 'custom_trigger_email_action' ), 10, 2 );
// include the email class files
add_filter( 'woocommerce_email_classes', array( &$this, 'custom_init_emails' ) );
// Email Actions - Triggers
$email_actions = array(
'custom_pending_email',
'custom_item_email',
);
foreach ( $email_actions as $action ) {
add_action( $action, array( 'WC_Emails', 'send_transactional_email' ), 10, 10 );
}
add_filter( 'woocommerce_template_directory', array( $this, 'custom_template_directory' ), 10, 2 );
}
public function custom_init_emails( $emails ) {
// Include the email class file if it's not included already
if ( ! isset( $emails[ 'Custom_Email' ] ) ) {
$emails[ 'Custom_Email' ] = include_once( 'emails/class-custom-email.php' );
}
return $emails;
}
public function custom_trigger_email_action( $order_id, $posted ) {
// add an action for our email trigger if the order id is valid
if ( isset( $order_id ) && 0 != $order_id ) {
new WC_Emails();
do_action( 'custom_pending_email_notification', $order_id );
}
}
public function custom_template_directory( $directory, $template ) {
// ensure the directory name is correct
if ( false !== strpos( $template, '-custom' ) ) {
return 'my-custom-email';
}
return $directory;
}
}// end of class
new Custom_Email_Manager();
?>