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 132 133 134 135 136 137 138 139 140 141 142 143 144
<?php
class BKAP_Email_Manager {
public function __construct() {
add_action( 'woocommerce_checkout_order_processed', array( &$this, 'init_confirmation_emails' ), 10, 2 );
add_filter( 'woocommerce_email_classes', array( &$this, 'bkap_init_emails' ) );
$email_actions = array(
'bkap_pending_booking',
'bkap_admin_new_booking',
'bkap_booking_confirmed',
'bkap_booking_pending-confirmation_to_cancelled',
'bkap_gcal_events_imported',
'bkap_booking_rescheduled_admin'
);
foreach ( $email_actions as $action ) {
add_action( $action, array( 'WC_Emails', 'send_transactional_email' ), 10, 10 );
}
add_filter( 'woocommerce_template_directory', array( $this, 'bkap_template_directory' ), 10, 2 );
}
function init_confirmation_emails( $order_id, $posted ) {
if ( isset( $order_id ) && 0 != $order_id ) {
$order = new WC_order( $order_id );
$requires = bkap_common::bkap_order_requires_confirmation( $order );
if ( $requires ) {
new WC_Emails();
do_action( 'bkap_pending_booking_notification', $order_id );
}
}
}
public function bkap_init_emails( $emails ) {
if ( ! isset( $emails[ 'BKAP_Email_New_Booking' ] ) ) {
$emails[ 'BKAP_Email_New_Booking' ] = include_once( 'emails/class-bkap-email-new-booking.php' );
}
if ( ! isset( $emails[ 'BKAP_Email_Booking_Confirmed' ] ) ) {
$emails[ 'BKAP_Email_Booking_Confirmed' ] = include_once( 'emails/class-bkap-email-booking-confirmed.php' );
}
if ( ! isset( $emails[ 'BKAP_Email_Booking_Cancelled' ] ) ) {
$emails[ 'BKAP_Email_Booking_Cancelled' ] = include_once( 'emails/class-bkap-email-booking-cancelled.php' );
}
if ( ! isset( $emails[ 'BKAP_Email_Event_Imported' ] ) ) {
$emails[ 'BKAP_Email_Event_Imported' ] = include_once( 'emails/class-bkap-email-imported-events.php' );
}
if ( ! isset( $emails[ 'BKAP_Email_Booking_Rescheduled_Admin' ] ) ) {
$emails[ 'BKAP_Email_Booking_Rescheduled_Admin' ] = include_once( 'emails/class-bkap-email-booking-rescheduled-admin.php' );
}
return $emails;
}
public function bkap_template_directory( $directory, $template ) {
if ( false !== strpos( $template, '-booking' ) ) {
return 'woocommerce-booking';
}
return $directory;
}
}
new BKAP_Email_Manager();
?>