Skip to content

Instantly share code, notes, and snippets.

@scandiumby
Last active September 19, 2018 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scandiumby/8c67a17dfa4c60c5377309c348330338 to your computer and use it in GitHub Desktop.
Save scandiumby/8c67a17dfa4c60c5377309c348330338 to your computer and use it in GitHub Desktop.
Private data were changed in the code.
<?php
/**
* Author: Egor N. Kostyuk
* Date: 06.02.2018
* Time: 15:35
*/
if (!defined('ABSPATH')) {
exit;
}
if (!class_exists('EJ_WC_Email_New_Order_Notification_To_Regional_Office_and_To_Additional_email')) :
class EJ_WC_Email_New_Order_Notification_To_Regional_Office_and_To_Additional_email extends WC_Email_New_Order
{
private $warehouseNamesInMinskRegion = [
'machulishhi', 'shabany', 'minsk-center'
];
const ADDITIONAL_EMAIL = 'test1@example.by,test2@example.by';
public function __construct()
{
$this->id = 'new_order_regional';
$this->title = 'New order regional';
$this->description = 'New order email notification for regional managers';
parent::__construct();
$isOrderToMinskOffice = $this->isOrderToMinskOffices();
// Set regional and additional emails
$regionalEmail = WC()->session->get('order_regional_email_for_notification', NULL);
if (check_wholesale_user()) {
$manager_email = get_user_meta(get_current_user_id(), 'wwlc_cf_email_manager');
if(count($manager_email) > 0) {
$this->recipient = $manager_email[0];
} else {
$this->recipient = self::ADDITIONAL_EMAIL;
}
} else {
if (is_null($regionalEmail)) {
if ($isOrderToMinskOffice) {
$this->recipient = self::ADDITIONAL_EMAIL;
} else {
// This email class have to off if regional and additional emails isn't defined
// (or isn't needed).
$this->enabled = false;
}
} else {
$this->recipient = $isOrderToMinskOffice ? self::ADDITIONAL_EMAIL : $regionalEmail;
}
}
}
//Check order to Minsk offices
protected function isOrderToMinskOffices()
{
$regionalWarehouseName = WC()->session->get('order_regional_warehouse_name_for_notification', NULL);
if (is_null($regionalWarehouseName)) {
return false;
} else {
if (in_array($regionalWarehouseName, $this->warehouseNamesInMinskRegion)) {
return true;
} else {
return false;
}
}
}
}
endif;
return new EJ_WC_Email_New_Order_Notification_To_Regional_Office_and_To_Additional_email();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment