-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedd-expired-discount-code-notifier.php
More file actions
56 lines (45 loc) · 1.38 KB
/
edd-expired-discount-code-notifier.php
File metadata and controls
56 lines (45 loc) · 1.38 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
<?php
/*
Plugin Name: Easy Digital Downloads - Expired Discount Code Notifier
Description: Notifies the store owner via email when a customer attempts to make a purchase with an expired discount code.
Plugin URI: https://wisdomplugin.com
Author: Brian Batt
Author URI: https://wisdomplugin.com
Version: 1.1
*/
if(!class_exists('EDD_Expired_Discount_Code_Notifier'))
{
class EDD_Expired_Discount_Code_Notifier
{
public function __construct(){
add_filter( 'edd_ajax_discount_response', array( $this, 'check_edd_ajax_discount_response'), 100, 1 );
}
public function check_edd_ajax_discount_response( $response ){
if( is_array($response) )
{
if( isset($response['msg'] ) )
{
if( $response['msg'] !="valid" )
{
$this->send_notification( $response );
}
}
}
return $response;
}
public function send_notification( $response )
{
$code = isset( $response['code'] )? $response['code'] : "";
$name_of_store = get_bloginfo("name");
$headers = array('Content-Type: text/html; charset=UTF-8');
$to = get_bloginfo('admin_email');
$subject = "Invalid discount code used";
$body = "Someone tried to use this discount code:<br><br>";
$body.=$code."<br><br>";
$body.="Thanks,<br><br>";
$body.=$name_of_store;
wp_mail( $to, $subject, $body, $headers);
}
}//end class
new EDD_Expired_Discount_Code_Notifier();
}//end if