summaryrefslogtreecommitdiff
path: root/Postman/Postman-Mail/PostmanWooCommerce.php
blob: e53f37363c693eb77c1117565dc24936d145383a (plain)
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
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}

if ( ! class_exists( 'PostmanWoocommerce' ) ) {
	class PostmanWoocommerce {

		private $options;

		public function __construct() {
			$this->set_vars();
			$this->hooks();
		}

		public function set_vars() {
			$this->options = PostmanOptions::getInstance ();
		}

		public function hooks() {
			add_filter( 'option_woocommerce_email_from_address', array( $this, 'set_postman_from_address' ), 10, 2 );
			add_filter( 'woocommerce_email_from_address', array( $this, 'set_postman_from_address' ), 10, 2 );
			add_filter( 'woocommerce_get_settings_email', array( $this, 'overide_email_settings' ) );
		}

		public function set_postman_from_address( $from_address, $WC_Email ) {
			return $this->options->getMessageSenderEmail();
		}

		public function overide_email_settings( $settings ) {

			$key = $this->find_woocommerce_email_from_address( $settings );

			if ( $key ) {
				$settings[$key] = array(
					'title'             => __( '"From" address', 'post-smtp' ),
					'desc'              => __( 'This is override by the account configured on Post SMTP plugin configuration.', 'post-smtp' ),
					'id'                => 'woocommerce_email_from_address',
					'type'              => 'email',
					'custom_attributes' => array(
						'multiple' => 'multiple',
						'disabled' => 'true',
					),
					'css'               => 'min-width:300px;',
					'default'           => $this->options->getMessageSenderEmail(),
					'autoload'          => false,
					'desc_tip'          => true,
				);
			}

			return $settings;
		}

		private function find_woocommerce_email_from_address($settings) {
			foreach ( $settings as $key => $data ) {
				if ( isset( $data['id'] ) && $data['id'] == 'woocommerce_email_from_address' ) {
					return $key;
				}
			}

			return false;
		}
	}
}