Skip to content

Commit

Permalink
feat: track coupon authentications
Browse files Browse the repository at this point in the history
  • Loading branch information
mijogu committed May 18, 2021
1 parent 8efadc3 commit dfb8e01
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
59 changes: 58 additions & 1 deletion acf-json/group_5f9f3d11c5367.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,63 @@
"prepend": "",
"append": "",
"maxlength": ""
},
{
"key": "field_60a3fed902bc5",
"label": "Authentications",
"name": "authentications",
"type": "repeater",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"collapsed": "",
"min": 0,
"max": 0,
"layout": "table",
"button_label": "",
"sub_fields": [
{
"key": "field_60a3ff0002bc6",
"label": "Date",
"name": "date",
"type": "date_picker",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"display_format": "d\/m\/Y",
"return_format": "d\/m\/Y",
"first_day": 1
},
{
"key": "field_60a3ff0d02bc7",
"label": "IP Address",
"name": "ip_address",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "",
"append": "",
"maxlength": ""
}
]
}
],
"location": [
Expand All @@ -210,5 +267,5 @@
"hide_on_screen": "",
"active": true,
"description": "",
"modified": 1606765859
"modified": 1621362064
}
21 changes: 21 additions & 0 deletions woocommerce-coupon-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,27 @@ function wcg_process_coupon_code_url()
// set coupon cookie?
if (!isset($_COOKIE[$coupon_cookie]) || $_COOKIE[$coupon_cookie] != $coupon_code) {
setcookie($coupon_cookie, $coupon_code, $expire);

// track the coupon has been used to login - timestamp and IP address
$date = date('d/m/Y');
$ip = '';

if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
//ip from share internet
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
//ip pass from proxy
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}

$row = array(
'date' => $date,
'ip_address' => $ip
);
add_row('authentications', $row, $coupon->id);

}
// set redirect cookie?
if (!isset($_COOKIE[$redirect_cookie]) || $_COOKIE[$redirect_cookie] != $redirect_slug) {
Expand Down

0 comments on commit dfb8e01

Please sign in to comment.