WooCommerce Cart Abandonment Recovery - Version 1.0.0

Version Description

Download this release

Release Info

Developer cartflows
Plugin Icon 128x128 WooCommerce Cart Abandonment Recovery
Version 1.0.0
Comparing to
See all releases

Version 1.0.0

admin/assets/css/admin-cart-abandonment-rtl.css ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ .wcf-ca-ibox {
3
+ clear: both;
4
+ margin-bottom: 25px;
5
+ margin-top: 0;
6
+ padding: 0;
7
+ }
8
+
9
+ .wcf-ca-ibox-title {
10
+ background-color: white;
11
+ border-image: none;
12
+ border-width: 3px 0px 0;
13
+ color: inherit;
14
+ margin-bottom: 0;
15
+ padding: 14px 15px 7px;
16
+ min-height: 48px;
17
+ }
18
+
19
+ .wcf-ca-ibox-content {
20
+ background-color: white;
21
+ color: inherit;
22
+ padding: 15px 20px 20px 20px;
23
+ border-color: #d7dadc;
24
+ border-image: none;
25
+ border-style: solid solid none;
26
+ border-width: 1px 0px;
27
+ }
28
+
29
+ .wcf-ca-raw {
30
+ margin-right: -15px;
31
+ margin-left: -15px;
32
+ }
33
+
34
+ .wcf-ca-grid-container {
35
+ display: grid;
36
+ grid-template-columns: 1fr 1fr 1fr;
37
+ grid-gap: 20px;
38
+ }
39
+
40
+ .grid-container > div {
41
+ background-color: rgba(255, 255, 255, 0.8);
42
+ text-align: center;
43
+ padding: 20px 0;
44
+ font-size: 30px;
45
+ }
46
+
47
+
48
+ .wcf-ca-center-msg {
49
+ margin: auto;
50
+ width: 50%;
51
+ padding: 10px;
52
+ margin-top: 20px;
53
+ text-align: center;
54
+ }
55
+
56
+
57
+ .wcf-ca-switch {
58
+ cursor: pointer;
59
+ text-indent: -999em;
60
+ display: block;
61
+ width: 38px;
62
+ height: 22px;
63
+ border-radius: 30px;
64
+ border: none;
65
+ position: relative;
66
+ box-sizing: border-box;
67
+ -webkit-transition: all .3s ease;
68
+ transition: all .3s ease;
69
+ box-shadow: inset 0 0 0 0 transparent;
70
+ }
71
+ .wcf-ca-switch:focus {
72
+ outline: none;
73
+ }
74
+ .wcf-ca-switch:before {
75
+ border-radius: 50%;
76
+ background: #ffffff;
77
+ content: '';
78
+ position: absolute;
79
+ display: block;
80
+ width: 18px;
81
+ height: 18px;
82
+ top: 2px;
83
+ right: 2px;
84
+ -webkit-transition: all .15s ease;
85
+ transition: all .15s ease;
86
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
87
+ }
88
+ .wcf-ca-switch[wcf-ca-template-switch="on"] {
89
+ box-shadow: inset 0 0 0 11px #008000;
90
+ }
91
+ .wcf-ca-switch[wcf-ca-template-switch="on"]:before {
92
+ -webkit-transform: translateX(-16px);
93
+ transform: translateX(-16px);
94
+ }
95
+ .wcf-ca-switch[wcf-ca-template-switch="off"] {
96
+ background: #ccc;
97
+ }
98
+ .wcf-ca-switch.wcap-loading {
99
+ cursor: default;
100
+ opacity: 0.5;
101
+ }
102
+
103
+ .wcf-ca-trigger-input{
104
+ height: 28px;
105
+ width: 40%;
106
+ margin-left: 10px;
107
+ }
108
+
109
+ .wcf-ca-report-btn {
110
+ padding: 15px 0px 15px 0px;
111
+ display: table;
112
+ width: 100%;
113
+ }
114
+
115
+ .wcf-ca-email-inputs {
116
+ width: 25%;
117
+ }
118
+
119
+ .wcf-ca-coupon-inputs {
120
+ width: 10%;
121
+ vertical-align: middle;
122
+ }
123
+
124
+ .wcf-ca-filter-input{
125
+ height: 28px;
126
+ width: 7em;
127
+ margin: 0;
128
+ text-align: center;
129
+ }
130
+
131
+ .wcf-ca-left-report-field-group {
132
+ display: table-cell; text-align: right
133
+ }
134
+ .wcf-ca-right-report-field-group {
135
+ display: table-cell; text-align: left
136
+ }
admin/assets/css/admin-cart-abandonment.css ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ .wcf-ca-ibox {
3
+ clear: both;
4
+ margin-bottom: 25px;
5
+ margin-top: 0;
6
+ padding: 0;
7
+ }
8
+
9
+ .wcf-ca-ibox-title {
10
+ background-color: white;
11
+ border-image: none;
12
+ border-width: 3px 0px 0;
13
+ color: inherit;
14
+ margin-bottom: 0;
15
+ padding: 14px 15px 7px;
16
+ min-height: 48px;
17
+ }
18
+
19
+ .wcf-ca-ibox-content {
20
+ background-color: white;
21
+ color: inherit;
22
+ padding: 15px 20px 20px 20px;
23
+ border-color: #d7dadc;
24
+ border-image: none;
25
+ border-style: solid solid none;
26
+ border-width: 1px 0px;
27
+ }
28
+
29
+ .wcf-ca-raw {
30
+ margin-left: -15px;
31
+ margin-right: -15px;
32
+ }
33
+
34
+ .wcf-ca-grid-container {
35
+ display: grid;
36
+ grid-template-columns: 1fr 1fr 1fr;
37
+ grid-gap: 20px;
38
+ }
39
+
40
+ .grid-container > div {
41
+ background-color: rgba(255, 255, 255, 0.8);
42
+ text-align: center;
43
+ padding: 20px 0;
44
+ font-size: 30px;
45
+ }
46
+
47
+
48
+ .wcf-ca-center-msg {
49
+ margin: auto;
50
+ width: 50%;
51
+ padding: 10px;
52
+ margin-top: 20px;
53
+ text-align: center;
54
+ }
55
+
56
+
57
+ .wcf-ca-switch {
58
+ cursor: pointer;
59
+ text-indent: -999em;
60
+ display: block;
61
+ width: 38px;
62
+ height: 22px;
63
+ border-radius: 30px;
64
+ border: none;
65
+ position: relative;
66
+ box-sizing: border-box;
67
+ -webkit-transition: all .3s ease;
68
+ transition: all .3s ease;
69
+ box-shadow: inset 0 0 0 0 transparent;
70
+ }
71
+ .wcf-ca-switch:focus {
72
+ outline: none;
73
+ }
74
+ .wcf-ca-switch:before {
75
+ border-radius: 50%;
76
+ background: #ffffff;
77
+ content: '';
78
+ position: absolute;
79
+ display: block;
80
+ width: 18px;
81
+ height: 18px;
82
+ top: 2px;
83
+ left: 2px;
84
+ -webkit-transition: all .15s ease;
85
+ transition: all .15s ease;
86
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
87
+ }
88
+ .wcf-ca-switch[wcf-ca-template-switch="on"] {
89
+ box-shadow: inset 0 0 0 11px #008000;
90
+ }
91
+ .wcf-ca-switch[wcf-ca-template-switch="on"]:before {
92
+ -webkit-transform: translateX(16px);
93
+ transform: translateX(16px);
94
+ }
95
+ .wcf-ca-switch[wcf-ca-template-switch="off"] {
96
+ background: #ccc;
97
+ }
98
+ .wcf-ca-switch.wcap-loading {
99
+ cursor: default;
100
+ opacity: 0.5;
101
+ }
102
+
103
+ .wcf-ca-trigger-input{
104
+ height: 28px;
105
+ width: 40%;
106
+ margin-right: 10px;
107
+ }
108
+
109
+ .wcf-ca-report-btn {
110
+ padding: 15px 0px 15px 0px;
111
+ display: table;
112
+ width: 100%;
113
+ }
114
+
115
+ .wcf-ca-email-inputs {
116
+ width: 25%;
117
+ }
118
+
119
+ .wcf-ca-coupon-inputs {
120
+ width: 10%;
121
+ vertical-align: middle;
122
+ }
123
+
124
+ .wcf-ca-filter-input{
125
+ height: 28px;
126
+ width: 7em;
127
+ margin: 0;
128
+ text-align: center;
129
+ }
130
+
131
+ .wcf-ca-left-report-field-group {
132
+ display: table-cell; text-align: left
133
+ }
134
+ .wcf-ca-right-report-field-group {
135
+ display: table-cell; text-align: right
136
+ }
admin/assets/js/admin-email-templates.js ADDED
@@ -0,0 +1,244 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function ($) {
2
+
3
+ CartAbandonmentSettings = {
4
+
5
+ init: function () {
6
+
7
+ $("#wcf_ca_custom_filter_from").datepicker({
8
+ dateFormat: 'yy-mm-dd',
9
+ maxDate: '0',
10
+ onClose: function( selectedDate ) {
11
+ jQuery( "#wcf_ca_custom_filter_to" ).datepicker( "option", "minDate", selectedDate );
12
+ }
13
+ }).attr('readonly','readonly').css('background', 'white');
14
+
15
+ $("#wcf_ca_custom_filter_to").datepicker({
16
+ dateFormat: 'yy-mm-dd',
17
+ maxDate: '0',
18
+ onClose: function( selectedDate ) {
19
+ jQuery( "#wcf_ca_custom_filter_from" ).datepicker( "option", "maxDate", selectedDate );
20
+ }
21
+ }).attr('readonly','readonly').css('background', 'white');
22
+
23
+ $("#wcf_ca_custom_filter").click(function () {
24
+ var from = $("#wcf_ca_custom_filter_from").val().trim();
25
+ var to = $("#wcf_ca_custom_filter_to").val().trim();
26
+ var url = window.location.search;
27
+ url = url + "&from_date=" + from + "&to_date=" + to + "&filter=custom";
28
+ window.location.href = url;
29
+
30
+ });
31
+
32
+ // Hide initially.
33
+ $("#wcf_ca_discount_type, #wcf_ca_coupon_amount, #wcf_ca_coupon_expiry, #wcf_ca_zapier_cart_abandoned_webhook, #wcf_ca_coupon_code_status, #wcf_ca_gdpr_message").closest('tr').hide();
34
+
35
+
36
+ if( $("#wcf_ca_gdpr_status:checked").length ) {
37
+ $("#wcf_ca_gdpr_message").closest('tr').show();
38
+ }
39
+
40
+ if ($("#wcf_ca_zapier_tracking_status:checked").length) {
41
+ $("#wcf_ca_zapier_cart_abandoned_webhook, #wcf_ca_coupon_code_status").closest('tr').show();
42
+ }
43
+
44
+ if ( $("#wcf_ca_coupon_code_status:checked").length && $("#wcf_ca_zapier_tracking_status:checked").length ) {
45
+ $("#wcf_ca_discount_type, #wcf_ca_coupon_amount, #wcf_ca_coupon_expiry").closest('tr').show();
46
+ }
47
+
48
+ $("#wcf_ca_coupon_code_status").click(
49
+ function () {
50
+ if (!$("#wcf_ca_coupon_code_status:checked").length) {
51
+ $("#wcf_ca_discount_type, #wcf_ca_coupon_amount, #wcf_ca_coupon_expiry").closest('tr').fadeOut();
52
+ } else {
53
+ $("#wcf_ca_discount_type, #wcf_ca_coupon_amount, #wcf_ca_coupon_expiry").closest('tr').fadeIn();
54
+ }
55
+ }
56
+ );
57
+
58
+ $("#wcf_ca_gdpr_status").click(
59
+ function () {
60
+ if (!$("#wcf_ca_gdpr_status:checked").length) {
61
+ $("#wcf_ca_gdpr_message").closest('tr').fadeOut();
62
+ } else {
63
+ $("#wcf_ca_gdpr_message").closest('tr').fadeIn();
64
+ }
65
+ }
66
+ );
67
+
68
+ $("#wcf_ca_zapier_tracking_status").click(
69
+ function () {
70
+ if (!$("#wcf_ca_zapier_tracking_status:checked").length) {
71
+ $("#wcf_ca_zapier_cart_abandoned_webhook, #wcf_ca_coupon_code_status").closest('tr').fadeOut();
72
+ } else {
73
+ $("#wcf_ca_zapier_cart_abandoned_webhook, #wcf_ca_coupon_code_status").closest('tr').fadeIn();
74
+ }
75
+
76
+ if ($("#wcf_ca_coupon_code_status:checked").length && $("#wcf_ca_zapier_tracking_status:checked").length) {
77
+ $("#wcf_ca_discount_type, #wcf_ca_coupon_amount, #wcf_ca_coupon_expiry").closest('tr').fadeIn();
78
+ } else {
79
+ $("#wcf_ca_discount_type, #wcf_ca_coupon_amount, #wcf_ca_coupon_expiry").closest('tr').fadeOut();
80
+ }
81
+ }
82
+ );
83
+
84
+ }
85
+ }
86
+
87
+ EmailTemplatesAdmin = {
88
+
89
+ init: function () {
90
+
91
+ $(document).on('click', '#wcf_preview_email', EmailTemplatesAdmin.send_test_email);
92
+ $(document).on('click', '.wcf-ca-switch.wcf-toggle-template-status', EmailTemplatesAdmin.toggle_activate_template);
93
+
94
+ $("#wcf_email_discount_type, #wcf_email_discount_amount, #wcf_email_coupon_expiry_date").closest('tr').hide();
95
+ if ( $("#wcf_override_global_coupon").is(":checked")) {
96
+ $("#wcf_email_discount_type, #wcf_email_discount_amount, #wcf_email_coupon_expiry_date").closest('tr').show();
97
+ }
98
+
99
+ $(document).on('click', '#wcf_override_global_coupon', EmailTemplatesAdmin.toggle_coupon_fileds);
100
+
101
+ },
102
+
103
+ toggle_coupon_fileds: function() {
104
+
105
+ if ( $("#wcf_override_global_coupon").is(":checked")) {
106
+ $("#wcf_email_discount_type, #wcf_email_discount_amount, #wcf_email_coupon_expiry_date").closest('tr').fadeIn();
107
+ } else {
108
+ $("#wcf_email_discount_type, #wcf_email_discount_amount, #wcf_email_coupon_expiry_date").closest('tr').fadeOut();
109
+ }
110
+
111
+ },
112
+
113
+ send_test_email: function () {
114
+
115
+ var email_body = '';
116
+ if (jQuery("#wp-wcf_email_body-wrap").hasClass("tmce-active")) {
117
+ email_body = tinyMCE.get('wcf_email_body').getContent();
118
+ } else {
119
+ email_body = jQuery('#wcf_email_body').val();
120
+ }
121
+
122
+ var email_subject = $('#wcf_email_subject').val();
123
+ var email_send_to = $('#wcf_send_test_email').val();
124
+ var wp_nonce = $("#_wpnonce").val();
125
+
126
+ $(this).next('div.error').remove();
127
+
128
+ if (!$.trim(email_body)) {
129
+ $(this).after('<div class="error-message wcf-ca-error-msg"> Email body is required! </div>');
130
+ } else if (!$.trim(email_subject)) {
131
+ $(this).after('<div class="error-message wcf-ca-error-msg"> Email subject is required! </div>');
132
+ } else if (!$.trim(email_send_to)) {
133
+ $(this).after('<div class="error-message wcf-ca-error-msg"> You must add your email id! </div>');
134
+ }
135
+ else {
136
+
137
+ var data = {
138
+ email_subject: email_subject,
139
+ email_body: email_body,
140
+ email_send_to: email_send_to,
141
+ action: 'wcf_ca_preview_email_send',
142
+ security: wp_nonce
143
+ };
144
+ $("#wcf_preview_email").css('cursor', 'wait').attr("disabled", true);
145
+
146
+ // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
147
+ $.post(
148
+ ajaxurl, data, function (response) {
149
+ $("#mail_response_msg").empty().fadeIn();;
150
+
151
+ if (response.success) {
152
+ var htmlString = "<strong> Email has been sent successfully! </strong>";
153
+ $("#mail_response_msg").css('color','green').html(htmlString).delay(3000).fadeOut();
154
+
155
+ } else {
156
+ var htmlString = "<strong> Email sending failed! Please check your <a href='"+ CAEmailTemplate.settings_url +"'> email settings! </a></strong>"
157
+ $("#mail_response_msg").css('color','red').html(htmlString).delay(3000).fadeOut();;
158
+ }
159
+ $("#wcf_preview_email").css('cursor', '').attr("disabled", false);
160
+
161
+ }
162
+ );
163
+ }
164
+
165
+ $(".wcf-ca-error-msg").delay(2000).fadeOut();
166
+ },
167
+
168
+ toggle_activate_template: function () {
169
+
170
+ var $switch, state, new_state;
171
+ $switch = $(this);
172
+ state = $switch.attr('wcf-ca-template-switch');
173
+ new_state = state === 'on' ? 'off' : 'on';
174
+
175
+ $("#wcf_activate_email_template").val(new_state == 'on' ? 1 : 0);
176
+ $switch.attr('wcf-ca-template-switch', new_state);
177
+ }
178
+
179
+ }
180
+
181
+ ZapierSettings = {
182
+ init: function () {
183
+
184
+ $(document).delegate("#wcf_ca_trigger_web_hook_abandoned_btn", "click",
185
+ { 'order_status': 'abandoned' },
186
+ ZapierSettings.zapier_trigger_sample);
187
+ },
188
+ zapier_trigger_sample: function( event ) {
189
+
190
+ var zapier_webhook_url = $("#wcf_ca_zapier_cart_"+ event.data.order_status +"_webhook").val().trim();
191
+
192
+ if ( ! zapier_webhook_url.length ) {
193
+ $("#wcf_ca_"+ event.data.order_status +"_btn_message").text("Webhook URL is required.").fadeIn().css('color', '#dc3232').delay(2000).fadeOut();
194
+ return;
195
+ }
196
+
197
+ $("#wcf_ca_"+ event.data.order_status +"_btn_message").text("Triggering...").fadeIn();
198
+
199
+ var now = new Date();
200
+ var datetime = now.getFullYear()+'/'+(now.getMonth()+1)+'/'+now.getDate();
201
+ datetime += ' '+now.getHours()+':'+now.getMinutes()+':'+now.getSeconds();
202
+ if ($.trim(zapier_webhook_url) !== "") {
203
+ var sample_data = {
204
+ "first_name": CartFlowsCADetails.name,
205
+ "last_name": CartFlowsCADetails.surname,
206
+ "email": CartFlowsCADetails.email,
207
+ "order_status": event.data.order_status,
208
+ "checkout_url": window.location.origin + "/checkout/?wcf_ac_token=something",
209
+ "coupon_code": "abcgefgh",
210
+ "product_names": "Product1, Product2 & Product3",
211
+ "cart_total": CartFlowsCADetails.woo_currency_symbol + "20"
212
+ };
213
+ $.ajax({
214
+ url: zapier_webhook_url,
215
+ type: 'POST',
216
+ data: sample_data,
217
+ success: function(data) {
218
+ if (data.status == "success") {
219
+ $("#wcf_ca_"+ event.data.order_status +"_btn_message").text("Trigger Success!").css('color', '#46b450');
220
+ } else {
221
+ $("#wcf_ca_"+ event.data.order_status +"_btn_message").text("Trigger Failed!").css('color', '#dc3232');
222
+ }
223
+ $("#wcf_ca_"+ event.data.order_status +"_btn_message").fadeIn().delay(2000).fadeOut();
224
+ },
225
+ error: function() {
226
+ $("#wcf_ca_"+ event.data.order_status +"_btn_message").text("Trigger Failed!").css('color', '#dc3232');
227
+ }
228
+ });
229
+ } else {
230
+ $("wcf_ca"+ event.data.order_status +"_btn_message").text("Please verify webhook URL.").fadeIn().delay(2000).fadeOut();;
231
+ }
232
+ },
233
+ }
234
+
235
+ $(document).ready(
236
+ function () {
237
+ EmailTemplatesAdmin.init();
238
+ CartAbandonmentSettings.init();
239
+ ZapierSettings.init();
240
+ }
241
+ );
242
+
243
+
244
+ })(jQuery);
admin/assets/js/admin-mce.js ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function ($) {
2
+
3
+ $(document).ready(
4
+ function () {
5
+ tinymce.PluginManager.add(
6
+ 'cartflows_ac', function (editor, url) {
7
+
8
+ editor.addButton(
9
+ 'cartflows_ac', {
10
+ type: 'menubutton',
11
+ text: 'CartFlows Field',
12
+ icon: false,
13
+ menu: [
14
+ {
15
+ text: 'Admin Firstname',
16
+ value: '{{admin.firstname}}',
17
+ onclick: function () {
18
+ editor.insertContent(this.value());
19
+ }
20
+ },
21
+ {
22
+ text: 'Admin Company',
23
+ value: '{{admin.company}}',
24
+ onclick: function () {
25
+ editor.insertContent(this.value());
26
+ }
27
+ },
28
+ {
29
+ text: 'Abandoned Product Details Table',
30
+ value: '{{cart.product.table}}',
31
+ onclick: function () {
32
+ editor.insertContent(this.value());
33
+ }
34
+ },
35
+ {
36
+ text: 'Abandoned Product Names',
37
+ value: '{{cart.product.names}}',
38
+ onclick: function () {
39
+ editor.insertContent(this.value());
40
+ }
41
+ },
42
+ {
43
+ text: 'Cart Checkout URL',
44
+ value: '{{cart.checkout_url}}',
45
+ onclick: function () {
46
+ editor.insertContent(this.value());
47
+ }
48
+ },
49
+ {
50
+ text: 'Coupon Code',
51
+ value: '{{cart.coupon_code}}',
52
+ onclick: function () {
53
+ editor.insertContent(this.value());
54
+ }
55
+ },
56
+ {
57
+ text: 'Customer First Name',
58
+ value: '{{customer.firstname}}',
59
+ onclick: function () {
60
+ editor.insertContent(this.value());
61
+ }
62
+ },
63
+ {
64
+ text: 'Customer Last Name',
65
+ value: '{{customer.lastname}}',
66
+ onclick: function () {
67
+ editor.insertContent(this.value());
68
+ }
69
+ },
70
+ {
71
+ text: 'Customer Full Name',
72
+ value: '{{customer.fullname}}',
73
+ onclick: function () {
74
+ editor.insertContent(this.value());
75
+ }
76
+ },
77
+ {
78
+ text: 'Cart Abandonment Date',
79
+ value: '{{cart.abandoned_date}}',
80
+ onclick: function () {
81
+ editor.insertContent(this.value());
82
+ }
83
+ },
84
+ {
85
+ text: 'Site URL',
86
+ value: '{{site.url}}',
87
+ onclick: function () {
88
+ editor.insertContent(this.value());
89
+ }
90
+ },
91
+ {
92
+ text: 'Unsubscribe Link',
93
+ value: '{{cart.unsubscribe}}',
94
+ onclick: function () {
95
+ editor.insertContent(this.value());
96
+ }
97
+ },
98
+ ].sort(function(a,b){
99
+ return a.text.localeCompare(b.text);
100
+ })
101
+ }
102
+ );
103
+ }
104
+ );
105
+ }
106
+ );
107
+
108
+ })(jQuery);
109
+
assets/images/cartflows-icon.svg ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
3
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4
+ <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5
+ width="95px" height="95px" viewBox="0 0 95 95" enable-background="new 0 0 95 95" xml:space="preserve">
6
+ <g>
7
+ <path fill="#81878c" d="M58.942,5.609c-3.444,3.354-5.587,8.036-5.587,13.22v30.718c0,4.521-3.668,8.188-8.188,8.188H24.574
8
+ c-4.52,0-8.188-3.668-8.188-8.188c0-4.52,3.668-8.188,8.188-8.188h22.583V24.974H24.574c-1.399,0-2.763,0.115-4.099,0.34
9
+ C8.86,27.26,0,37.377,0,49.547c0,10.7,6.843,19.803,16.386,23.176c1.318,0.466,2.681,0.825,4.09,1.058
10
+ c1.336,0.225,2.699,0.341,4.099,0.341h20.592c1.399,0,2.763-0.116,4.099-0.341c1.409-0.232,2.771-0.592,4.09-1.058
11
+ C62.897,69.35,69.74,60.247,69.74,49.547v-8.188c9.05,0,16.386-7.337,16.386-16.386H69.74v-6.145c0-1.13,0.915-2.044,2.045-2.044
12
+ h4.098c4.996,0,9.525-1.982,12.843-5.212c2.987-2.905,4.996-6.807,5.471-11.174H71.786C66.799,0.399,62.261,2.381,58.942,5.609"/>
13
+ <path fill="#81878c" d="M24.575,78.218c-4.523,0-8.191,3.667-8.191,8.191c0,4.523,3.667,8.191,8.191,8.191s8.191-3.668,8.191-8.191
14
+ C32.766,81.885,29.098,78.218,24.575,78.218"/>
15
+ <path fill="#81878c" d="M49.149,78.218c-4.524,0-8.192,3.667-8.192,8.191c0,4.523,3.667,8.191,8.192,8.191
16
+ c4.523,0,8.191-3.668,8.191-8.191C57.34,81.885,53.672,78.218,49.149,78.218"/>
17
+ </g>
18
+ </svg>
assets/images/cartflows-logo.svg ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
3
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4
+ <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5
+ width="500px" height="95px" viewBox="0 0 500 95" enable-background="new 0 0 500 95" xml:space="preserve">
6
+ <g>
7
+ <path fill="#F06335" d="M135.779,68.374c-5.939,0-10.946-1.951-14.934-5.939c-3.989-3.988-5.939-8.995-5.939-15.019
8
+ c0-6.025,1.951-11.031,5.939-15.02c3.988-3.988,8.995-6.024,14.934-6.024c6.535,0,11.964,2.376,16.208,7.212l7.211-6.194
9
+ c-6.194-7.043-14-10.606-23.42-10.606c-8.74,0-16.207,2.885-22.317,8.74c-6.023,5.854-9.079,13.152-9.079,21.893
10
+ c0,8.739,3.056,16.037,9.079,21.892c6.11,5.77,13.577,8.655,22.317,8.655c9.25,0,17.735-3.988,23.505-10.776l-7.127-6.194
11
+ C148,65.914,142.483,68.374,135.779,68.374"/>
12
+ <path fill="#F06335" d="M199.086,40.372c-1.443-4.157-6.619-7.127-13.661-7.127c-6.025,0-11.117,2.121-15.274,6.448
13
+ c-4.073,4.243-6.11,9.504-6.11,15.868s2.037,11.625,6.11,15.952c4.157,4.243,9.249,6.364,15.274,6.364
14
+ c7.042,0,12.218-2.97,13.661-7.128v6.194h10.182V34.178h-10.182V40.372z M196.03,64.896c-2.46,2.461-5.6,3.733-9.249,3.733
15
+ c-3.648,0-6.619-1.272-9.08-3.733c-2.375-2.461-3.563-5.601-3.563-9.334c0-3.734,1.188-6.873,3.563-9.334
16
+ c2.461-2.461,5.432-3.734,9.08-3.734c3.649,0,6.788,1.273,9.249,3.734c2.547,2.461,3.819,5.6,3.819,9.334
17
+ C199.85,59.295,198.577,62.435,196.03,64.896"/>
18
+ <path fill="#F06335" d="M229.891,40.542v-6.363h-10.098v42.767h10.098V54.458c0-7.043,4.498-11.455,11.541-11.455
19
+ c1.527,0,2.971,0.17,4.243,0.424v-9.843c-0.848-0.169-1.867-0.254-3.055-0.254C236.595,33.33,231.928,36.045,229.891,40.542"/>
20
+ <polygon fill="#F06335" points="267.654,17.802 257.472,17.802 257.472,34.178 251.955,34.178 251.955,43.427 257.472,43.427
21
+ 257.472,76.944 267.654,76.944 267.654,43.427 276.902,43.427 276.902,34.178 267.654,34.178 "/>
22
+ <polygon fill="#F06335" points="286.834,76.944 297.439,76.944 297.439,51.827 320.436,51.827 320.436,42.239 297.439,42.239
23
+ 297.439,27.39 322.641,27.39 322.641,17.802 286.834,17.802 "/>
24
+ <rect x="332.487" y="17.802" fill="#F06335" width="10.183" height="59.143"/>
25
+ <path fill="#F06335" d="M374.832,32.905c-6.534,0-12.049,2.206-16.547,6.533c-4.498,4.328-6.789,9.759-6.789,16.123
26
+ s2.291,11.795,6.789,16.122s10.013,6.534,16.547,6.534c6.533,0,12.049-2.207,16.547-6.534c4.496-4.327,6.787-9.758,6.787-16.122
27
+ s-2.291-11.795-6.787-16.123C386.881,35.111,381.365,32.905,374.832,32.905 M384.25,65.149c-2.545,2.546-5.685,3.819-9.418,3.819
28
+ c-3.819,0-6.959-1.273-9.505-3.819c-2.46-2.63-3.733-5.77-3.733-9.588s1.273-6.958,3.733-9.504
29
+ c2.546-2.631,5.686-3.903,9.505-3.903c3.733,0,6.873,1.272,9.418,3.903c2.547,2.546,3.818,5.686,3.818,9.504
30
+ S386.797,62.52,384.25,65.149"/>
31
+ <polygon fill="#F06335" points="443.992,60.822 435.337,34.178 427.615,34.178 418.959,60.822 410.051,34.178 400.461,34.178
32
+ 414.717,76.944 422.693,76.944 431.518,49.876 440.344,76.944 448.234,76.944 462.575,34.178 452.902,34.178 "/>
33
+ <path fill="#F06335" d="M488.545,51.743c-1.697-0.595-4.074-1.442-5.346-1.782c-1.104-0.424-2.801-1.104-3.479-1.527
34
+ c-1.188-0.764-1.952-1.527-1.952-2.97c0-2.291,2.037-3.818,5.176-3.818c3.649,0,6.449,1.188,8.316,3.563l5.686-6.024
35
+ c-3.225-4.158-7.807-6.279-13.832-6.279c-4.242,0-7.807,1.188-10.776,3.479c-2.886,2.291-4.327,5.346-4.327,9.333
36
+ c0,6.109,3.648,9.589,10.521,12.05c1.443,0.594,3.988,1.357,5.262,1.782c1.271,0.424,3.055,1.018,3.988,1.611
37
+ c1.442,0.765,2.459,1.952,2.459,3.395c0,2.631-2.291,4.667-7.636,4.667c-5.176,0-9.333-2.291-11.286-5.346l-6.533,5.516
38
+ c2.715,5.346,9.08,8.655,17.65,8.655c11.624,0,17.564-5.685,17.564-13.577C500,58.361,496.436,54.543,488.545,51.743"/>
39
+ <path fill="#F06335" d="M58.942,5.609c-3.444,3.354-5.587,8.036-5.587,13.22v30.718c0,4.521-3.668,8.188-8.188,8.188H24.574
40
+ c-4.52,0-8.188-3.668-8.188-8.188c0-4.52,3.668-8.188,8.188-8.188h22.583V24.974H24.574c-1.399,0-2.763,0.115-4.099,0.34
41
+ C8.86,27.26,0,37.377,0,49.547c0,10.7,6.843,19.803,16.386,23.176c1.318,0.466,2.681,0.825,4.09,1.058
42
+ c1.336,0.225,2.699,0.341,4.099,0.341h20.592c1.399,0,2.763-0.116,4.099-0.341c1.409-0.232,2.771-0.592,4.09-1.058
43
+ C62.897,69.35,69.74,60.247,69.74,49.547v-8.188c9.05,0,16.386-7.337,16.386-16.386H69.74v-6.145c0-1.13,0.915-2.044,2.045-2.044
44
+ h4.098c4.996,0,9.525-1.982,12.843-5.212c2.987-2.905,4.996-6.807,5.471-11.174H71.786C66.799,0.399,62.261,2.381,58.942,5.609"/>
45
+ <path fill="#F06335" d="M24.575,78.218c-4.523,0-8.191,3.667-8.191,8.191c0,4.523,3.667,8.191,8.191,8.191s8.191-3.668,8.191-8.191
46
+ C32.766,81.885,29.098,78.218,24.575,78.218"/>
47
+ <path fill="#F06335" d="M49.149,78.218c-4.524,0-8.192,3.667-8.192,8.191c0,4.523,3.667,8.191,8.192,8.191
48
+ c4.523,0,8.191-3.668,8.191-8.191C57.34,81.885,53.672,78.218,49.149,78.218"/>
49
+ </g>
50
+ </svg>
assets/images/hoodie.jpg ADDED
Binary file
assets/images/polo.jpg ADDED
Binary file
changelog.txt ADDED
@@ -0,0 +1,2 @@
 
 
1
+ Version 1.0.0 - Monday, 27th May 2019
2
+ - Initial Release
classes/class-cartflows-ca-loader.php ADDED
@@ -0,0 +1,352 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * CartFlows Loader.
4
+ *
5
+ * @package Woocommerce-Cart-Abandonment-Recovery
6
+ */
7
+
8
+ if ( ! class_exists( 'CARTFLOWS_CA_Loader' ) ) {
9
+
10
+ /**
11
+ * Class CARTFLOWS_CA_Loader.
12
+ */
13
+ final class CARTFLOWS_CA_Loader {
14
+
15
+
16
+ /**
17
+ * Member Variable
18
+ *
19
+ * @var instance
20
+ */
21
+ private static $instance = null;
22
+
23
+ /**
24
+ * Member Variable
25
+ *
26
+ * @var utils
27
+ */
28
+ public $utils = null;
29
+
30
+
31
+ /**
32
+ * Initiator
33
+ */
34
+ public static function get_instance() {
35
+
36
+ if ( is_null( self::$instance ) ) {
37
+
38
+ self::$instance = new self;
39
+
40
+ /**
41
+ * CartFlows CA loaded.
42
+ *
43
+ * Fires when Cartflows CA was fully loaded and instantiated.
44
+ *
45
+ * @since 1.0.0
46
+ */
47
+ do_action( 'cartflows_ca_loaded' );
48
+ }
49
+
50
+ return self::$instance;
51
+ }
52
+
53
+ /**
54
+ * Constructor
55
+ */
56
+ public function __construct() {
57
+
58
+ $this->define_constants();
59
+
60
+ // Activation hook.
61
+ register_activation_hook( CARTFLOWS_CA_FILE, array( $this, 'activation_reset' ) );
62
+
63
+ // deActivation hook.
64
+ register_deactivation_hook( CARTFLOWS_CA_FILE, array( $this, 'deactivation_reset' ) );
65
+
66
+ add_action( 'plugins_loaded', array( $this, 'load_plugin' ), 99 );
67
+
68
+ add_action( 'plugins_loaded', array( $this, 'load_cf_textdomain' ) );
69
+ }
70
+
71
+ /**
72
+ * Defines all constants
73
+ *
74
+ * @since 1.0.0
75
+ */
76
+ public function define_constants() {
77
+ define( 'CARTFLOWS_CA_BASE', plugin_basename( CARTFLOWS_CA_FILE ) );
78
+ define( 'CARTFLOWS_CA_DIR', plugin_dir_path( CARTFLOWS_CA_FILE ) );
79
+ define( 'CARTFLOWS_CA_URL', plugins_url( '/', CARTFLOWS_CA_FILE ) );
80
+ define( 'CARTFLOWS_CA_VER', '1.0.0' );
81
+ define( 'CARTFLOWS_CA_SLUG', 'cartflows_ca' );
82
+
83
+ define( 'CARTFLOWS_CA_CART_ABANDONMENT_TABLE', 'cartflows_ca_cart_abandonment' );
84
+ define( 'CARTFLOWS_CA_EMAIL_TEMPLATE_TABLE', 'cartflows_ca_email_templates' );
85
+ define( 'CARTFLOWS_CA_EMAIL_HISTORY_TABLE', 'cartflows_ca_email_history' );
86
+ define( 'CARTFLOWS_CA_EMAIL_TEMPLATE_META_TABLE', 'cartflows_ca_email_templates_meta' );
87
+ }
88
+
89
+ /**
90
+ * Loads plugin files.
91
+ *
92
+ * @since 1.0.0
93
+ *
94
+ * @return void
95
+ */
96
+ function load_plugin() {
97
+
98
+ if ( ! function_exists( 'WC' ) ) {
99
+ add_action( 'admin_notices', array( $this, 'fails_to_load' ) );
100
+ return;
101
+ }
102
+
103
+ $this->load_helper_files_components();
104
+ $this->load_core_files();
105
+ $this->load_core_components();
106
+
107
+ /**
108
+ * CartFlows Init.
109
+ *
110
+ * Fires when Cartflows is instantiated.
111
+ *
112
+ * @since 1.0.0
113
+ */
114
+ do_action( 'cartflows_ca_init' );
115
+ }
116
+
117
+ /**
118
+ * Fires admin notice when Elementor is not installed and activated.
119
+ *
120
+ * @since 1.0.0
121
+ *
122
+ * @return void
123
+ */
124
+ public function fails_to_load() {
125
+
126
+ $screen = get_current_screen();
127
+
128
+ if ( isset( $screen->parent_file ) && 'plugins.php' === $screen->parent_file && 'update' === $screen->id ) {
129
+ return;
130
+ }
131
+
132
+ $class = 'notice notice-error';
133
+ /* translators: %s: html tags */
134
+ $message = sprintf( __( 'The %1$sWoocommerce Cart Abandonment Recovery%2$s plugin requires %1$sWooCommerce%2$s plugin installed & activated.', 'cartflows-ca' ), '<strong>', '</strong>' );
135
+
136
+ $plugin = 'woocommerce/woocommerce.php';
137
+
138
+ if ( $this->is_woo_installed() ) {
139
+ if ( ! current_user_can( 'activate_plugins' ) ) {
140
+ return;
141
+ }
142
+
143
+ $action_url = wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . $plugin . '&amp;plugin_status=all&amp;paged=1&amp;s', 'activate-plugin_' . $plugin );
144
+ $button_label = __( 'Activate WooCommerce', 'cartflows-ca' );
145
+
146
+ } else {
147
+ if ( ! current_user_can( 'install_plugins' ) ) {
148
+ return;
149
+ }
150
+
151
+ $action_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=woocommerce' ), 'install-plugin_woocommerce' );
152
+ $button_label = __( 'Install WooCommerce', 'cartflows-ca' );
153
+ }
154
+
155
+ $button = '<p><a href="' . $action_url . '" class="button-primary">' . $button_label . '</a></p><p></p>';
156
+
157
+ printf( '<div class="%1$s"><p>%2$s</p>%3$s</div>', esc_attr( $class ), $message, $button );
158
+ }
159
+
160
+
161
+ /**
162
+ * Is woocommerce plugin installed.
163
+ *
164
+ * @since 1.0.0
165
+ *
166
+ * @access public
167
+ */
168
+ function is_woo_installed() {
169
+
170
+ $path = 'woocommerce/woocommerce.php';
171
+ $plugins = get_plugins();
172
+
173
+ return isset( $plugins[ $path ] );
174
+ }
175
+
176
+ /**
177
+ * Create new database tables for plugin updates.
178
+ *
179
+ * @since 1.0.0
180
+ *
181
+ * @return void
182
+ */
183
+ function initialize_cart_abandonment_tables() {
184
+
185
+ include_once CARTFLOWS_CA_DIR . 'modules/cart-abandonment/class-cartflows-ca-cart-abandonment-db.php';
186
+ $db = Cartflows_Ca_Cart_Abandonment_Db::get_instance();
187
+ $db->create_tables();
188
+ $db->template_table_seeder();
189
+ }
190
+
191
+
192
+ /**
193
+ * Load Helper Files and Components.
194
+ *
195
+ * @since 1.0.0
196
+ *
197
+ * @return void
198
+ */
199
+ function load_helper_files_components() {
200
+
201
+ include_once CARTFLOWS_CA_DIR . 'classes/class-cartflows-ca-utils.php';
202
+ $this->utils = Cartflows_Ca_Utils::get_instance();
203
+ }
204
+
205
+ /**
206
+ * Load core files.
207
+ */
208
+ function load_core_files() {
209
+ /* Update compatibility. */
210
+ require_once CARTFLOWS_CA_DIR . 'classes/class-cartflows-ca-update.php';
211
+
212
+ include_once CARTFLOWS_CA_DIR . 'classes/class-cartflows-ca-settings.php';
213
+ }
214
+
215
+ /**
216
+ * Load CartFlows Ca Text Domain.
217
+ * This will load the translation textdomain depending on the file priorities.
218
+ * 1. Global Languages /wp-content/languages/%plugin-folder-name%/ folder
219
+ * 2. Local dorectory /wp-content/plugins/%plugin-folder-name%/languages/ folder
220
+ *
221
+ * @since 1.0.3
222
+ * @return void
223
+ */
224
+ public function load_cf_textdomain() {
225
+
226
+ // Default languages directory for CartFlows Ca.
227
+ $lang_dir = CARTFLOWS_CA_DIR . 'languages/';
228
+
229
+ /**
230
+ * Filters the languages directory path to use for CartFlows Ca.
231
+ *
232
+ * @param string $lang_dir The languages directory path.
233
+ */
234
+ $lang_dir = apply_filters( 'carflows_ca_languages_directory', $lang_dir );
235
+
236
+ // Traditional WordPress plugin locale filter.
237
+ global $wp_version;
238
+
239
+ $get_locale = get_locale();
240
+
241
+ if ( $wp_version >= 4.7 ) {
242
+ $get_locale = get_user_locale();
243
+ }
244
+
245
+ /**
246
+ * Language Locale for CartFlows Ca
247
+ *
248
+ * @var $get_locale The locale to use.
249
+ * Uses get_user_locale()` in WordPress 4.7 or greater,
250
+ * otherwise uses `get_locale()`.
251
+ */
252
+ $locale = apply_filters( 'plugin_locale', $get_locale, 'cartflows-ca' );
253
+ $mofile = sprintf( '%1$s-%2$s.mo', 'cartflows-ca', $locale );
254
+
255
+ // Setup paths to current locale file.
256
+ $mofile_local = $lang_dir . $mofile;
257
+ $mofile_global = WP_LANG_DIR . '/plugins/' . $mofile;
258
+
259
+ if ( file_exists( $mofile_global ) ) {
260
+ // Look in global /wp-content/languages/%plugin-folder-name%/ folder.
261
+ load_textdomain( 'cartflows-ca', $mofile_global );
262
+ } elseif ( file_exists( $mofile_local ) ) {
263
+ // Look in local /wp-content/plugins/%plugin-folder-name%/languages/ folder.
264
+ load_textdomain( 'cartflows-ca', $mofile_local );
265
+ } else {
266
+ // Load the default language files.
267
+ load_plugin_textdomain( 'cartflows-ca', false, $lang_dir );
268
+ }
269
+ }
270
+ /**
271
+ * Load Core Components.
272
+ *
273
+ * @since 1.0.0
274
+ *
275
+ * @return void
276
+ */
277
+ function load_core_components() {
278
+
279
+ /* Cart abandonment templates class */
280
+ include_once CARTFLOWS_CA_DIR . 'modules/cart-abandonment/class-cartflows-ca-module-loader.php';
281
+
282
+ }
283
+
284
+
285
+ /**
286
+ * Activation Reset
287
+ */
288
+ function activation_reset() {
289
+ $this->update_default_settings();
290
+ $this->initialize_cart_abandonment_tables();
291
+ }
292
+
293
+
294
+ /**
295
+ * Set the default cart abandonment settings.
296
+ */
297
+ function update_default_settings() {
298
+
299
+ $current_user = wp_get_current_user();
300
+ $email_from = ( isset( $current_user->user_firstname ) && ! empty( $current_user->user_firstname ) ) ? $current_user->user_firstname . ' ' . $current_user->user_lastname : 'Admin';
301
+ $default_settings = array(
302
+ 'wcf_ca_status' => 'on',
303
+ 'wcf_ca_gdpr_status' => 'off',
304
+ 'wcf_ca_coupon_code_status' => 'off',
305
+ 'wcf_ca_zapier_tracking_status' => 'off',
306
+ 'wcf_ca_cut_off_time' => 15,
307
+ 'wcf_ca_from_name' => $email_from,
308
+ 'wcf_ca_from_email' => $current_user->user_email,
309
+ 'wcf_ca_reply_email' => $current_user->user_email,
310
+ 'wcf_ca_discount_type' => 'percent',
311
+ 'wcf_ca_coupon_amount' => 10,
312
+ 'wcf_ca_zapier_cart_abandoned_webhook' => '',
313
+ 'wcf_ca_gdpr_message' => 'Your email & cart are saved so we can send email reminders about this order.',
314
+ 'wcf_ca_coupon_expiry' => 0,
315
+ 'wcf_ca_coupon_expiry_unit' => 'hours',
316
+ );
317
+
318
+ foreach ( $default_settings as $option_key => $option_value ) {
319
+ if ( ! get_option( $option_key ) ) {
320
+ update_option( $option_key, $option_value );
321
+ }
322
+ }
323
+ }
324
+
325
+ /**
326
+ * Deactivation Reset
327
+ */
328
+ function deactivation_reset() {
329
+ wp_clear_scheduled_hook( 'cartflows_ca_update_order_status_action' );
330
+ }
331
+
332
+ }
333
+
334
+ /**
335
+ * Prepare if class 'CARTFLOWS_CA_Loader' exist.
336
+ * Kicking this off by calling 'get_instance()' method
337
+ */
338
+ CARTFLOWS_CA_Loader::get_instance();
339
+ }
340
+
341
+
342
+ if ( ! function_exists( 'wcf_ca' ) ) {
343
+ /**
344
+ * Get global class.
345
+ *
346
+ * @return object
347
+ */
348
+ function wcf_ca() {
349
+ return CARTFLOWS_CA_Loader::get_instance();
350
+ }
351
+ }
352
+
classes/class-cartflows-ca-settings.php ADDED
@@ -0,0 +1,569 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Settings.
4
+ *
5
+ * @package Woocommerce-Cart-Abandonment-Recovery
6
+ */
7
+
8
+ /**
9
+ * Class Cartflows_Ca_Utils.
10
+ */
11
+ class Cartflows_Ca_Settings {
12
+
13
+
14
+ /**
15
+ * Member Variable
16
+ *
17
+ * @var instance
18
+ */
19
+ private static $instance;
20
+
21
+
22
+ /**
23
+ * Cartflows_Ca_Settings constructor.
24
+ */
25
+ public function __construct() {
26
+ add_action( 'admin_init', array( $this, 'wcf_initialize_settings' ) );
27
+ add_filter( 'plugin_action_links_' . CARTFLOWS_CA_BASE, array( $this, 'add_action_links' ), 999 );
28
+ }
29
+
30
+ /**
31
+ * Adding action links for plugin list page.
32
+ *
33
+ * @param array $links links.
34
+ * @return array
35
+ */
36
+ public function add_action_links( $links ) {
37
+ $mylinks = array(
38
+ '<a href="' . admin_url( 'admin.php?page=' . WCF_CA_PAGE_NAME ) . '">Settings</a>',
39
+ );
40
+
41
+ return array_merge( $mylinks, $links );
42
+ }
43
+ /**
44
+ * Add new settings for cart abandonment settings.
45
+ *
46
+ * @since 1.1.5
47
+ */
48
+ function wcf_initialize_settings() {
49
+
50
+ // Start: Settings for cart abandonment.
51
+ add_settings_section(
52
+ WCF_CA_GENERAL_SETTINGS_SECTION,
53
+ __( 'Cart Abandonment Settings', 'cartflows-ca' ),
54
+ array( $this, 'wcf_cart_abandonment_options_callback' ),
55
+ WCF_CA_PAGE_NAME
56
+ );
57
+
58
+ add_settings_field(
59
+ 'wcf_ca_status',
60
+ __( 'Enable Cart Abandonment Tracking', 'cartflows-ca' ),
61
+ array( $this, 'wcf_ca_status_callback' ),
62
+ WCF_CA_PAGE_NAME,
63
+ WCF_CA_GENERAL_SETTINGS_SECTION,
64
+ array( __( 'Start capturing abandoned carts. <br/><br/> <span class="description"><strong>Note:</strong> Cart will be considered abandoned if order is not completed in <strong>15 minutes</strong>.</span>', 'cartflows-ca' ) )
65
+ );
66
+
67
+ register_setting(
68
+ WCF_CA_SETTINGS_OPTION_GROUP,
69
+ 'wcf_ca_status'
70
+ );
71
+
72
+ // End: Settings for cart abandonment.
73
+ // Start: Settings for email templates.
74
+ add_settings_section(
75
+ WCF_CA_EMAIL_SETTINGS_SECTION,
76
+ __( 'Email settings', 'cartflows-ca' ),
77
+ array( $this, 'wcf_cart_abandonment_options_callback' ),
78
+ WCF_CA_PAGE_NAME
79
+ );
80
+
81
+ add_settings_field(
82
+ 'wcf_ca_from_name',
83
+ __( '"From" Name', 'cartflows-ca' ),
84
+ array( $this, 'wcf_ca_from_name_callback' ),
85
+ WCF_CA_PAGE_NAME,
86
+ WCF_CA_EMAIL_SETTINGS_SECTION,
87
+ array( 'Name will appear in email sent.', 'cartflows-ca' )
88
+ );
89
+
90
+ add_settings_field(
91
+ 'wcf_ca_from_email',
92
+ __( '"From" Address', 'cartflows-ca' ),
93
+ array( $this, 'wcf_ca_from_email_callback' ),
94
+ WCF_CA_PAGE_NAME,
95
+ WCF_CA_EMAIL_SETTINGS_SECTION,
96
+ array( 'Email which send from.', 'cartflows-ca' )
97
+ );
98
+
99
+ add_settings_field(
100
+ 'wcf_ca_reply_email',
101
+ __( 'Send Reply Emails to', 'cartflows-ca' ),
102
+ array( $this, 'wcf_ca_reply_email_callback' ),
103
+ WCF_CA_PAGE_NAME,
104
+ WCF_CA_EMAIL_SETTINGS_SECTION,
105
+ array( 'When a user clicks reply, which email address should that reply be sent to?', 'cartflows-ca' )
106
+ );
107
+
108
+ register_setting(
109
+ WCF_CA_SETTINGS_OPTION_GROUP,
110
+ 'wcf_ca_from_name'
111
+ );
112
+
113
+ register_setting(
114
+ WCF_CA_SETTINGS_OPTION_GROUP,
115
+ 'wcf_ca_from_email',
116
+ array( $this, 'wcf_ca_from_email_validation' )
117
+ );
118
+
119
+ register_setting(
120
+ WCF_CA_SETTINGS_OPTION_GROUP,
121
+ 'wcf_ca_reply_email',
122
+ array( $this, 'wcf_ca_reply_email_validation' )
123
+ );
124
+ // End: Settings for email templates.
125
+ // Start: Settings for coupon code.
126
+ add_settings_field(
127
+ 'wcf_ca_zapier_tracking_status',
128
+ __( 'Enable Webhook', 'cartflows-ca' ),
129
+ array( $this, 'wcf_ca_zapier_tracking_status_callback' ),
130
+ WCF_CA_PAGE_NAME,
131
+ WCF_CA_ZAPIER_SETTINGS_SECTION,
132
+ array( __( 'Allows you to trigger webhooks automatically upon cart abandonment and recovery.', 'cartflows-ca' ) )
133
+ );
134
+
135
+ add_settings_field(
136
+ 'wcf_ca_zapier_cart_abandoned_webhook',
137
+ __( 'Webhook URL', 'cartflows-ca' ),
138
+ array( $this, 'wcf_ca_zapier_cart_abandoned_webhook_callback' ),
139
+ WCF_CA_PAGE_NAME,
140
+ WCF_CA_ZAPIER_SETTINGS_SECTION,
141
+ array( '', 'cartflows-ca' )
142
+ );
143
+
144
+ register_setting(
145
+ WCF_CA_SETTINGS_OPTION_GROUP,
146
+ 'wcf_ca_zapier_tracking_status'
147
+ );
148
+
149
+ register_setting(
150
+ WCF_CA_SETTINGS_OPTION_GROUP,
151
+ 'wcf_ca_zapier_cart_abandoned_webhook'
152
+ );
153
+
154
+ add_settings_section(
155
+ WCF_CA_ZAPIER_SETTINGS_SECTION,
156
+ __( 'Coupon Code Settings', 'cartflows-ca' ),
157
+ array( $this, 'wcf_cart_abandonment_options_callback' ),
158
+ WCF_CA_PAGE_NAME
159
+ );
160
+
161
+ add_settings_field(
162
+ 'wcf_ca_coupon_code_status',
163
+ __( 'Create Coupon Code', 'cartflows-ca' ),
164
+ array( $this, 'wcf_ca_coupon_code_status_callback' ),
165
+ WCF_CA_PAGE_NAME,
166
+ WCF_CA_ZAPIER_SETTINGS_SECTION,
167
+ array( __( 'Auto-create the special coupon for the abandoned cart to send over the emails.', 'cartflows-ca' ) )
168
+ );
169
+
170
+ add_settings_field(
171
+ 'wcf_ca_discount_type',
172
+ __( 'Discount Type', 'cartflows-ca' ),
173
+ array( $this, 'wcf_ca_discount_type_callback' ),
174
+ WCF_CA_PAGE_NAME,
175
+ WCF_CA_ZAPIER_SETTINGS_SECTION,
176
+ array( '', 'cartflows-ca' )
177
+ );
178
+
179
+ add_settings_field(
180
+ 'wcf_ca_coupon_amount',
181
+ __( 'Coupon Amount', 'cartflows-ca' ),
182
+ array( $this, 'wcf_ca_coupon_amount_callback' ),
183
+ WCF_CA_PAGE_NAME,
184
+ WCF_CA_ZAPIER_SETTINGS_SECTION,
185
+ array( '', 'cartflows-ca' )
186
+ );
187
+
188
+ add_settings_field(
189
+ 'wcf_ca_coupon_expiry',
190
+ __( 'Coupon Expires After', 'cartflows-ca' ),
191
+ array( $this, 'wcf_ca_coupon_expiry_callback' ),
192
+ WCF_CA_PAGE_NAME,
193
+ WCF_CA_ZAPIER_SETTINGS_SECTION,
194
+ array( '<br/><br/> <span class="description"><strong>Note: </strong> Enter zero (0) to restrict coupon from expiring.</span>', 'cartflows-ca' )
195
+ );
196
+
197
+ register_setting(
198
+ WCF_CA_SETTINGS_OPTION_GROUP,
199
+ 'wcf_ca_coupon_expiry'
200
+ );
201
+ register_setting(
202
+ WCF_CA_SETTINGS_OPTION_GROUP,
203
+ 'wcf_ca_coupon_expiry_unit'
204
+ );
205
+
206
+ register_setting(
207
+ WCF_CA_SETTINGS_OPTION_GROUP,
208
+ 'wcf_ca_coupon_code_status'
209
+ );
210
+
211
+ register_setting(
212
+ WCF_CA_SETTINGS_OPTION_GROUP,
213
+ 'wcf_ca_discount_type'
214
+ );
215
+
216
+ register_setting(
217
+ WCF_CA_SETTINGS_OPTION_GROUP,
218
+ 'wcf_ca_coupon_amount',
219
+ array( $this, 'wcf_ca_coupon_amount_validation' )
220
+ );
221
+ // End: Settings for coupon code.
222
+ // Start: Settings for Zapier.
223
+ add_settings_section(
224
+ WCF_CA_ZAPIER_SETTINGS_SECTION,
225
+ __( 'Webhook Settings', 'cartflows-ca' ),
226
+ array( $this, 'wcf_cart_abandonment_options_callback' ),
227
+ WCF_CA_PAGE_NAME
228
+ );
229
+
230
+ // End: Settings for webhook.
231
+ // Start: GDPR Settings.
232
+ add_settings_section(
233
+ WCF_CA_GDPR_SETTINGS_SECTION,
234
+ __( 'GDPR Settings', 'cartflows-ca' ),
235
+ array( $this, 'wcf_cart_abandonment_options_callback' ),
236
+ WCF_CA_PAGE_NAME
237
+ );
238
+
239
+ add_settings_field(
240
+ 'wcf_ca_gdpr_status',
241
+ __( 'Enable GDPR integration', 'cartflows-ca' ),
242
+ array( $this, 'wcf_ca_gdpr_status_callback' ),
243
+ WCF_CA_PAGE_NAME,
244
+ WCF_CA_GDPR_SETTINGS_SECTION,
245
+ array( __( 'Ask confirmation from the user before tracking data. <br/><br/> <span class="description"><strong>Note:</strong> By checking this, it will show up confirmation text below the email id on checkout page.</span>', 'cartflows-ca' ) )
246
+ );
247
+
248
+ add_settings_field(
249
+ 'wcf_ca_gdpr_message',
250
+ __( 'GDPR Message', 'cartflows-ca' ),
251
+ array( $this, 'wcf_ca_gdpr_message_callback' ),
252
+ WCF_CA_PAGE_NAME,
253
+ WCF_CA_GDPR_SETTINGS_SECTION,
254
+ array( '', 'cartflows-ca' )
255
+ );
256
+
257
+ register_setting(
258
+ WCF_CA_SETTINGS_OPTION_GROUP,
259
+ 'wcf_ca_gdpr_status'
260
+ );
261
+ register_setting(
262
+ WCF_CA_SETTINGS_OPTION_GROUP,
263
+ 'wcf_ca_gdpr_message'
264
+ );
265
+
266
+ }
267
+
268
+ /**
269
+ * Callback for cart abandonment status.
270
+ *
271
+ * @param array $args args.
272
+ * @since 1.1.5
273
+ */
274
+ function wcf_ca_coupon_code_status_callback( $args ) {
275
+ $wcf_ca_coupon_code_status = get_option( 'wcf_ca_coupon_code_status' );
276
+ $html = '';
277
+ printf(
278
+ '<input type="checkbox" id="wcf_ca_coupon_code_status" name="wcf_ca_coupon_code_status" value="on"
279
+ ' . checked( 'on', $wcf_ca_coupon_code_status, false ) . ' />'
280
+ );
281
+ $html .= '<label for="wcf_ca_coupon_code_status"> ' . $args[0] . '</label>';
282
+ echo $html;
283
+ }
284
+
285
+
286
+ /**
287
+ * Callback for cart abandonment cut off time.
288
+ *
289
+ * @param array $args args.
290
+ * @since 1.1.5
291
+ */
292
+ function wcf_ca_zapier_cart_abandoned_webhook_callback( $args ) {
293
+ $wcf_ca_zapier_cart_abandoned_webhook = get_option( 'wcf_ca_zapier_cart_abandoned_webhook' );
294
+ echo '<input type="text" class="wcf-ca-trigger-input" id="wcf_ca_zapier_cart_abandoned_webhook" name="wcf_ca_zapier_cart_abandoned_webhook" value="' . sanitize_text_field( $wcf_ca_zapier_cart_abandoned_webhook ) . '" />';
295
+ echo '<button id="wcf_ca_trigger_web_hook_abandoned_btn" type="button" class="button"> Trigger Sample </button>';
296
+ echo '<span style="margin-left: 10px;" id="wcf_ca_abandoned_btn_message"></span>';
297
+ $html = '<label for="wcf_ca_zapier_cart_abandoned_webhook"> ' . $args[0] . '</label>';
298
+ echo $html;
299
+ }
300
+
301
+
302
+ /**
303
+ * Callback for cart abandonment status.
304
+ *
305
+ * @param array $args args.
306
+ * @since 1.1.5
307
+ */
308
+ function wcf_ca_zapier_tracking_status_callback( $args ) {
309
+ $wcf_ca_zapier_tracking_status = get_option( 'wcf_ca_zapier_tracking_status' );
310
+
311
+ $html = '';
312
+ printf(
313
+ '<input type="checkbox" id="wcf_ca_zapier_tracking_status" name="wcf_ca_zapier_tracking_status" value="on"
314
+ ' . checked( 'on', $wcf_ca_zapier_tracking_status, false ) . ' />'
315
+ );
316
+ $html .= '<label for="wcf_ca_zapier_tracking_status"> ' . $args[0] . '</label>';
317
+ echo $html;
318
+ }
319
+
320
+
321
+ /**
322
+ * Callback for cart abandonment cut off time.
323
+ *
324
+ * @param array $args args.
325
+ * @since 1.1.5
326
+ */
327
+ function wcf_ca_coupon_amount_callback( $args ) {
328
+ $wcf_ca_coupon_amount = get_option( 'wcf_ca_coupon_amount' );
329
+ printf(
330
+ '<input type="number" class="wcf-ca-trigger-input wcf-ca-email-inputs" id="wcf_ca_coupon_amount" name="wcf_ca_coupon_amount" value="%s" />',
331
+ isset( $wcf_ca_coupon_amount ) ? esc_attr( $wcf_ca_coupon_amount ) : ''
332
+ );
333
+ $html = '<label for="wcf_ca_coupon_amount"> ' . $args[0] . '</label>';
334
+ echo $html;
335
+ }
336
+
337
+ /**
338
+ * Callback for cart abandonment cut off time.
339
+ *
340
+ * @param array $args args.
341
+ * @since 1.1.5
342
+ */
343
+ function wcf_ca_coupon_expiry_callback( $args ) {
344
+ $wcf_ca_coupon_expiry = intval( get_option( 'wcf_ca_coupon_expiry' ) );
345
+ printf(
346
+ '<input type="number" class="wcf-ca-trigger-input wcf-ca-coupon-inputs" id="wcf_ca_coupon_expiry" name="wcf_ca_coupon_expiry" value="%s" autocomplete="off" />',
347
+ isset( $wcf_ca_coupon_expiry ) ? esc_attr( $wcf_ca_coupon_expiry ) : ''
348
+ );
349
+
350
+ $coupon_expiry_unit = get_option( 'wcf_ca_coupon_expiry_unit' );
351
+ $items = array(
352
+ 'hours' => 'Hour(s)',
353
+ 'days' => 'Day(s)',
354
+ );
355
+ echo "<select id='wcf_ca_coupon_expiry_unit' name='wcf_ca_coupon_expiry_unit'>";
356
+ foreach ( $items as $key => $item ) {
357
+ $selected = ( $coupon_expiry_unit === $key ) ? 'selected="selected"' : '';
358
+ echo "<option value='$key' $selected>$item</option>";
359
+ }
360
+ echo '</select>';
361
+
362
+ $html = '<label for="wcf_ca_coupon_expiry_unit"> ' . $args[0] . '</label>';
363
+ echo $html;
364
+ }
365
+
366
+
367
+
368
+ /**
369
+ * Callback for cart abandonment cut off time.
370
+ *
371
+ * @param array $args args.
372
+ * @since 1.1.5
373
+ */
374
+ function wcf_ca_gdpr_message_callback( $args ) {
375
+ $wcf_ca_gdpr_message = get_option( 'wcf_ca_gdpr_message' );
376
+
377
+ printf(
378
+ '<textarea rows="2" cols="60" id="wcf_ca_gdpr_message" name="wcf_ca_gdpr_message" spellcheck="false">%s</textarea>',
379
+ isset( $wcf_ca_gdpr_message ) ? esc_attr( $wcf_ca_gdpr_message ) : ''
380
+ );
381
+ $html = '<label for="wcf_ca_gdpr_message"> ' . $args[0] . '</label>';
382
+ echo $html;
383
+ }
384
+
385
+ /**
386
+ * Callback for cart abandonment cut off time.
387
+ *
388
+ * @param array $args args.
389
+ * @since 1.1.5
390
+ */
391
+ function wcf_ca_discount_type_callback( $args ) {
392
+
393
+ $discount_type = get_option( 'wcf_ca_discount_type' );
394
+ $items = array(
395
+ 'percent' => 'Percentage discount',
396
+ 'fixed_cart' => 'Fixed cart discount',
397
+ );
398
+ echo "<select id='wcf_ca_discount_type' name='wcf_ca_discount_type'>";
399
+ foreach ( $items as $key => $item ) {
400
+ $selected = ( $discount_type === $key ) ? 'selected="selected"' : '';
401
+ echo "<option value='$key' $selected>$item</option>";
402
+ }
403
+ echo '</select>';
404
+ }
405
+
406
+ /**
407
+ * Validation for cart abandonment `cut-off` settings.
408
+ *
409
+ * @param array $input input.
410
+ * @since 1.1.5
411
+ */
412
+ function wcf_ca_coupon_amount_validation( $input ) {
413
+
414
+ $output = '';
415
+ if ( ( is_numeric( $input ) && $input >= 1 ) ) {
416
+ $output = stripslashes( $input );
417
+ } else {
418
+ add_settings_error(
419
+ 'wcf_ca_coupon_amount',
420
+ 'error found',
421
+ __( 'Coupon code should be numeric and has to be greater than or equals to 1.', 'cartflows-ca' )
422
+ );
423
+ }
424
+ return $output;
425
+ }
426
+
427
+ /**
428
+ * Callback for cart abandonment options.
429
+ *
430
+ * @since 1.1.5
431
+ */
432
+ function wcf_cart_abandonment_options_callback() {
433
+ echo '<hr/>';
434
+ }
435
+
436
+
437
+ /**
438
+ * Callback for cart abandonment status.
439
+ *
440
+ * @param array $args args.
441
+ * @since 1.1.5
442
+ */
443
+ function wcf_ca_status_callback( $args ) {
444
+ $wcf_ca_status = get_option( 'wcf_ca_status' );
445
+ $html = '';
446
+ printf(
447
+ '<input type="checkbox" id="wcf_ca_status" name="wcf_ca_status" value="on"
448
+ ' . checked( 'on', $wcf_ca_status, false ) . ' />'
449
+ );
450
+ $html .= '<label for="wcf_ca_status"> ' . $args[0] . '</label>';
451
+ echo $html;
452
+ }
453
+
454
+ /**
455
+ * Callback for cart abandonment status.
456
+ *
457
+ * @param array $args args.
458
+ * @since 1.1.5
459
+ */
460
+ function wcf_ca_gdpr_status_callback( $args ) {
461
+ $wcf_ca_gdpr_status = get_option( 'wcf_ca_gdpr_status' );
462
+ $html = '';
463
+ printf(
464
+ '<input type="checkbox" id="wcf_ca_gdpr_status" name="wcf_ca_gdpr_status" value="on"
465
+ ' . checked( 'on', $wcf_ca_gdpr_status, false ) . ' />'
466
+ );
467
+ $html .= '<label for="wcf_ca_gdpr_status"> ' . $args[0] . '</label>';
468
+ echo $html;
469
+ }
470
+
471
+ /**
472
+ * Callback for email from name.
473
+ *
474
+ * @param array $args Arguments.
475
+ */
476
+ public static function wcf_ca_from_name_callback( $args ) {
477
+ $wcf_ca_from_name = get_option( 'wcf_ca_from_name' );
478
+ printf(
479
+ '<input class="wcf-ca-trigger-input wcf-ca-email-inputs" type="text" id="wcf_ca_from_name" name="wcf_ca_from_name" value="%s" />',
480
+ isset( $wcf_ca_from_name ) ? esc_attr( $wcf_ca_from_name ) : ''
481
+ );
482
+ $html = '<label for="wcf_ca_from_name"> ' . $args[0] . '</label>';
483
+ echo $html;
484
+ }
485
+
486
+ /**
487
+ * Callback for email from.
488
+ *
489
+ * @param array $args Arguments.
490
+ */
491
+ public static function wcf_ca_from_email_callback( $args ) {
492
+ $wcf_ca_from_email = get_option( 'wcf_ca_from_email' );
493
+ printf(
494
+ '<input class="wcf-ca-trigger-input wcf-ca-email-inputs" type="text" id="wcf_ca_from_email" name="wcf_ca_from_email" value="%s" />',
495
+ isset( $wcf_ca_from_email ) ? esc_attr( $wcf_ca_from_email ) : ''
496
+ );
497
+ $html = '<label for="wcf_ca_from_email"> ' . $args[0] . '</label>';
498
+ echo $html;
499
+ }
500
+
501
+ /**
502
+ * Callback for email reply.
503
+ *
504
+ * @param array $args Arguments.
505
+ * @since 3.5
506
+ */
507
+ public static function wcf_ca_reply_email_callback( $args ) {
508
+ $wcf_ca_reply_email = get_option( 'wcf_ca_reply_email' );
509
+ printf(
510
+ '<input class="wcf-ca-trigger-input wcf-ca-email-inputs" type="text" id="wcf_ca_reply_email" name="wcf_ca_reply_email" value="%s" />',
511
+ isset( $wcf_ca_reply_email ) ? esc_attr( $wcf_ca_reply_email ) : ''
512
+ );
513
+
514
+ $html = '<label for="wcf_ca_reply_email"> ' . $args[0] . '</label>';
515
+ echo $html;
516
+ }
517
+
518
+
519
+ /**
520
+ * Validation for email.
521
+ *
522
+ * @param array $input input.
523
+ * @since 1.1.5
524
+ */
525
+ function wcf_ca_from_email_validation( $input ) {
526
+
527
+ if ( $input && ! is_email( $input ) ) {
528
+ add_settings_error(
529
+ 'wcf_ca_from_email',
530
+ 'error found',
531
+ __( 'Invalid email "From" address field', 'cartflows-ca' )
532
+ );
533
+ }
534
+ return sanitize_email( $input );
535
+ }
536
+
537
+ /**
538
+ * Validation for reply email.
539
+ *
540
+ * @param array $input input.
541
+ * @since 1.1.5
542
+ */
543
+ function wcf_ca_reply_email_validation( $input ) {
544
+
545
+ if ( $input && ! is_email( $input ) ) {
546
+ add_settings_error(
547
+ 'wcf_ca_reply_email',
548
+ 'error found',
549
+ __( 'Invalid email "Reply" address field', 'cartflows-ca' )
550
+ );
551
+ }
552
+ return sanitize_email( $input );
553
+ }
554
+
555
+ /**
556
+ * Initiator
557
+ */
558
+ public static function get_instance() {
559
+ if ( ! isset( self::$instance ) ) {
560
+ self::$instance = new self;
561
+ }
562
+ return self::$instance;
563
+ }
564
+
565
+
566
+
567
+
568
+ }
569
+ Cartflows_Ca_Settings::get_instance();
classes/class-cartflows-ca-update.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Update Compatibility
4
+ *
5
+ * @package Woocommerce-Cart-Abandonment-Recovery
6
+ */
7
+
8
+ if ( ! class_exists( 'Cartflows_Ca_Update' ) ) :
9
+
10
+ /**
11
+ * CartFlows CA Update initial setup
12
+ *
13
+ * @since 1.0.0
14
+ */
15
+ class Cartflows_Ca_Update {
16
+
17
+ /**
18
+ * Class instance.
19
+ *
20
+ * @access private
21
+ * @var $instance Class instance.
22
+ */
23
+ private static $instance;
24
+
25
+ /**
26
+ * Initiator
27
+ */
28
+ public static function get_instance() {
29
+ if ( ! isset( self::$instance ) ) {
30
+ self::$instance = new self();
31
+ }
32
+ return self::$instance;
33
+ }
34
+
35
+ /**
36
+ * Constructor
37
+ */
38
+ public function __construct() {
39
+ add_action( 'admin_init', __CLASS__ . '::init' );
40
+ }
41
+
42
+ /**
43
+ * Init
44
+ *
45
+ * @since 1.0.0
46
+ * @return void
47
+ */
48
+ static public function init() {
49
+
50
+ do_action( 'cartflows_ca_update_before' );
51
+
52
+ // Get auto saved version number.
53
+ $saved_version = get_option( 'wcf_ca_version', false );
54
+
55
+ // Update auto saved version number.
56
+ if ( ! $saved_version ) {
57
+ update_option( 'wcf_ca_version', CARTFLOWS_CA_VER );
58
+ return;
59
+ }
60
+
61
+ // If equals then return.
62
+ if ( version_compare( $saved_version, CARTFLOWS_CA_VER, '=' ) ) {
63
+ return;
64
+ }
65
+
66
+ // Update auto saved version number.
67
+ update_option( 'wcf_ca_version', CARTFLOWS_CA_VER );
68
+
69
+ do_action( 'cartflows_ca_update_after' );
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Kicking this off by calling 'get_instance()' method
75
+ */
76
+ Cartflows_Ca_Update::get_instance();
77
+
78
+ endif;
classes/class-cartflows-ca-utils.php ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Utils.
4
+ *
5
+ * @package Woocommerce-Cart-Abandonment-Recovery
6
+ */
7
+
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit; // Exit if accessed directly.
10
+ }
11
+
12
+ /**
13
+ * Class Cartflows_Ca_Utils.
14
+ */
15
+ class Cartflows_Ca_Utils {
16
+
17
+
18
+ /**
19
+ * Member Variable
20
+ *
21
+ * @var instance
22
+ */
23
+ private static $instance;
24
+
25
+ /**
26
+ * Common zapier data
27
+ *
28
+ * @var zapier
29
+ */
30
+ private static $zapier = null;
31
+
32
+ /**
33
+ * Common zapier data
34
+ *
35
+ * @var zapier
36
+ */
37
+ private static $cart_abandonment_settings = null;
38
+
39
+
40
+ /**
41
+ * Initiator
42
+ */
43
+ public static function get_instance() {
44
+ if ( ! isset( self::$instance ) ) {
45
+ self::$instance = new self;
46
+ }
47
+ return self::$instance;
48
+ }
49
+
50
+ /**
51
+ * Check if cart abandonment tracking is enabled.
52
+ *
53
+ * @return bool
54
+ */
55
+ function is_cart_abandonment_tracking_enabled() {
56
+
57
+ $wcf_ca_status = get_option( 'wcf_ca_status' );
58
+
59
+ // Check if abandonment cart tracking is disabled or zapier webhook is empty.
60
+ if ( isset( $wcf_ca_status ) && 'on' === $wcf_ca_status ) {
61
+ return true;
62
+ }
63
+
64
+ return false;
65
+ }
66
+
67
+ /**
68
+ * Check if cart abandonment tracking is enabled.
69
+ *
70
+ * @return bool
71
+ */
72
+ function is_zapier_trigger_enabled() {
73
+
74
+ $wcf_ca_zapier_tracking_status = get_option( 'wcf_ca_zapier_tracking_status' );
75
+
76
+ // Check if zapier tracking is disabled or zapier webhook is empty.
77
+ if ( isset( $wcf_ca_zapier_tracking_status ) && 'on' === $wcf_ca_zapier_tracking_status ) {
78
+ return true;
79
+ }
80
+
81
+ return false;
82
+ }
83
+
84
+ /**
85
+ * Get cart abandonment tracking cutoff time.
86
+ *
87
+ * @param boolean $in_seconds get cutoff time in seconds if true.
88
+ * @return bool
89
+ */
90
+ function get_cart_abandonment_tracking_cut_off_time( $in_seconds = false ) {
91
+
92
+ $cart_abandoned_time = apply_filters( 'cartflows_ca_cart_abandonment_cut_off_time', WCF_DEFAULT_CUT_OFF_TIME );
93
+ return $in_seconds ? $cart_abandoned_time * MINUTE_IN_SECONDS : $cart_abandoned_time;
94
+
95
+ }
96
+
97
+ /**
98
+ * Check if GDPR is enabled.
99
+ *
100
+ * @return bool
101
+ */
102
+ function is_gdpr_enabled() {
103
+
104
+ $wcf_ca_gdpr_status = get_option( 'wcf_ca_gdpr_status' );
105
+
106
+ // Check if abandonment cart tracking is disabled or zapier webhook is empty.
107
+ if ( isset( $wcf_ca_gdpr_status ) && 'on' === $wcf_ca_gdpr_status ) {
108
+ return true;
109
+ }
110
+
111
+ return false;
112
+ }
113
+
114
+
115
+ }
languages/cartflows-ca.pot ADDED
@@ -0,0 +1,417 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2019 CartFlows Inc
2
+ # This file is distributed under the same license as the Woocommerce Cart Abandonment Recovery package.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: Woocommerce Cart Abandonment Recovery 1.0.0\n"
6
+ "Report-Msgid-Bugs-To: "
7
+ "https://wordpress.org/support/plugin/woocommerce-cart-abandonment-recovery\n"
8
+ "POT-Creation-Date: 2019-05-27 06:23:42+00:00\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=utf-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "PO-Revision-Date: 2019-MO-DA HO:MI+ZONE\n"
13
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
+ "Language-Team: LANGUAGE <LL@li.org>\n"
15
+ "Language: en\n"
16
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
17
+ "X-Poedit-Country: United States\n"
18
+ "X-Poedit-SourceCharset: UTF-8\n"
19
+ "X-Poedit-KeywordsList: "
20
+ "__;_e;_x:1,2c;_ex:1,2c;_n:1,2;_nx:1,2,4c;_n_noop:1,2;_nx_noop:1,2,3c;esc_"
21
+ "attr__;esc_html__;esc_attr_e;esc_html_e;esc_attr_x:1,2c;esc_html_x:1,2c;\n"
22
+ "X-Poedit-Basepath: ../\n"
23
+ "X-Poedit-SearchPath-0: .\n"
24
+ "X-Poedit-Bookmarks: \n"
25
+ "X-Textdomain-Support: yes\n"
26
+ "X-Generator: grunt-wp-i18n 1.0.3\n"
27
+
28
+ #: classes/class-cartflows-ca-loader.php:134
29
+ #. translators: %s: html tags
30
+ msgid ""
31
+ "The %1$sWoocommerce Cart Abandonment Recovery%2$s plugin requires "
32
+ "%1$sWooCommerce%2$s plugin installed & activated."
33
+ msgstr ""
34
+
35
+ #: classes/class-cartflows-ca-loader.php:144
36
+ msgid "Activate WooCommerce"
37
+ msgstr ""
38
+
39
+ #: classes/class-cartflows-ca-loader.php:152
40
+ msgid "Install WooCommerce"
41
+ msgstr ""
42
+
43
+ #: classes/class-cartflows-ca-settings.php:53
44
+ msgid "Cart Abandonment Settings"
45
+ msgstr ""
46
+
47
+ #: classes/class-cartflows-ca-settings.php:60
48
+ msgid "Enable Cart Abandonment Tracking"
49
+ msgstr ""
50
+
51
+ #: classes/class-cartflows-ca-settings.php:64
52
+ msgid ""
53
+ "Start capturing abandoned carts. <br/><br/> <span "
54
+ "class=\"description\"><strong>Note:</strong> Cart will be considered "
55
+ "abandoned if order is not completed in <strong>15 minutes</strong>.</span>"
56
+ msgstr ""
57
+
58
+ #: classes/class-cartflows-ca-settings.php:76
59
+ msgid "Email settings"
60
+ msgstr ""
61
+
62
+ #: classes/class-cartflows-ca-settings.php:83
63
+ msgid "\"From\" Name"
64
+ msgstr ""
65
+
66
+ #: classes/class-cartflows-ca-settings.php:92
67
+ msgid "\"From\" Address"
68
+ msgstr ""
69
+
70
+ #: classes/class-cartflows-ca-settings.php:101
71
+ msgid "Send Reply Emails to"
72
+ msgstr ""
73
+
74
+ #: classes/class-cartflows-ca-settings.php:128
75
+ msgid "Enable Webhook"
76
+ msgstr ""
77
+
78
+ #: classes/class-cartflows-ca-settings.php:132
79
+ msgid ""
80
+ "Allows you to trigger webhooks automatically upon cart abandonment and "
81
+ "recovery."
82
+ msgstr ""
83
+
84
+ #: classes/class-cartflows-ca-settings.php:137
85
+ msgid "Webhook URL"
86
+ msgstr ""
87
+
88
+ #: classes/class-cartflows-ca-settings.php:156
89
+ msgid "Coupon Code Settings"
90
+ msgstr ""
91
+
92
+ #: classes/class-cartflows-ca-settings.php:163
93
+ msgid "Create Coupon Code"
94
+ msgstr ""
95
+
96
+ #: classes/class-cartflows-ca-settings.php:167
97
+ msgid ""
98
+ "Auto-create the special coupon for the abandoned cart to send over the "
99
+ "emails."
100
+ msgstr ""
101
+
102
+ #: classes/class-cartflows-ca-settings.php:172
103
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates.php:491
104
+ msgid "Discount Type"
105
+ msgstr ""
106
+
107
+ #: classes/class-cartflows-ca-settings.php:181
108
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates.php:523
109
+ msgid "Coupon Amount"
110
+ msgstr ""
111
+
112
+ #: classes/class-cartflows-ca-settings.php:190
113
+ msgid "Coupon Expires After"
114
+ msgstr ""
115
+
116
+ #: classes/class-cartflows-ca-settings.php:225
117
+ msgid "Webhook Settings"
118
+ msgstr ""
119
+
120
+ #: classes/class-cartflows-ca-settings.php:234
121
+ msgid "GDPR Settings"
122
+ msgstr ""
123
+
124
+ #: classes/class-cartflows-ca-settings.php:241
125
+ msgid "Enable GDPR integration"
126
+ msgstr ""
127
+
128
+ #: classes/class-cartflows-ca-settings.php:245
129
+ msgid ""
130
+ "Ask confirmation from the user before tracking data. <br/><br/> <span "
131
+ "class=\"description\"><strong>Note:</strong> By checking this, it will show "
132
+ "up confirmation text below the email id on checkout page.</span>"
133
+ msgstr ""
134
+
135
+ #: classes/class-cartflows-ca-settings.php:250
136
+ msgid "GDPR Message"
137
+ msgstr ""
138
+
139
+ #: classes/class-cartflows-ca-settings.php:421
140
+ msgid "Coupon code should be numeric and has to be greater than or equals to 1."
141
+ msgstr ""
142
+
143
+ #: classes/class-cartflows-ca-settings.php:531
144
+ msgid "Invalid email \"From\" address field"
145
+ msgstr ""
146
+
147
+ #: classes/class-cartflows-ca-settings.php:549
148
+ msgid "Invalid email \"Reply\" address field"
149
+ msgstr ""
150
+
151
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment-table.php:55
152
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment-table.php:123
153
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates-table.php:85
154
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates-table.php:119
155
+ msgid "Delete"
156
+ msgstr ""
157
+
158
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment-table.php:59
159
+ msgid "Unsubscribe"
160
+ msgstr ""
161
+
162
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment-table.php:189
163
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment.php:1482
164
+ msgid "Name"
165
+ msgstr ""
166
+
167
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment-table.php:190
168
+ msgid "Email"
169
+ msgstr ""
170
+
171
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment-table.php:191
172
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment.php:1488
173
+ msgid "Cart Total"
174
+ msgstr ""
175
+
176
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment-table.php:192
177
+ msgid "Order Status"
178
+ msgstr ""
179
+
180
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment-table.php:193
181
+ msgid "Time"
182
+ msgstr ""
183
+
184
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment.php:97
185
+ msgid "Mail has been sent successfully!"
186
+ msgstr ""
187
+
188
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment.php:99
189
+ msgid "Mail sending failed!"
190
+ msgstr ""
191
+
192
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment.php:132
193
+ msgid "Every Fifteen Minutes"
194
+ msgstr ""
195
+
196
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment.php:197
197
+ msgid "You have successfully unsubscribed from our email list."
198
+ msgstr ""
199
+
200
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment.php:197
201
+ msgid "Unsubscribed"
202
+ msgstr ""
203
+
204
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment.php:343
205
+ msgid "No Thanks"
206
+ msgstr ""
207
+
208
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment.php:737
209
+ msgid "CartFlows says: This order was abandoned & subsequently recovered."
210
+ msgstr ""
211
+
212
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment.php:849
213
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment.php:850
214
+ msgid "Cart Abandonment"
215
+ msgstr ""
216
+
217
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment.php:883
218
+ msgid "Items deleted: %d"
219
+ msgstr ""
220
+
221
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment.php:900
222
+ msgid "User unsubscribed successfully!"
223
+ msgstr ""
224
+
225
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment.php:1095
226
+ msgid "Report"
227
+ msgstr ""
228
+
229
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment.php:1111
230
+ msgid "Emails"
231
+ msgstr ""
232
+
233
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment.php:1127
234
+ msgid "Settings"
235
+ msgstr ""
236
+
237
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment.php:1478
238
+ msgid "Your Shopping Cart"
239
+ msgstr ""
240
+
241
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment.php:1481
242
+ msgid "Item"
243
+ msgstr ""
244
+
245
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment.php:1483
246
+ msgid "Quantity"
247
+ msgstr ""
248
+
249
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment.php:1484
250
+ msgid "Price"
251
+ msgstr ""
252
+
253
+ #: modules/cart-abandonment/class-cartflows-ca-cart-abandonment.php:1485
254
+ msgid "Line Subtotal"
255
+ msgstr ""
256
+
257
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates-table.php:73
258
+ msgid "Edit"
259
+ msgstr ""
260
+
261
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates-table.php:97
262
+ msgid "Clone"
263
+ msgstr ""
264
+
265
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates-table.php:183
266
+ msgid "Template Name"
267
+ msgstr ""
268
+
269
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates-table.php:184
270
+ msgid "Email Subject"
271
+ msgstr ""
272
+
273
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates-table.php:185
274
+ msgid "Trigger After"
275
+ msgstr ""
276
+
277
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates-table.php:186
278
+ msgid "Is Activated?"
279
+ msgstr ""
280
+
281
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates.php:187
282
+ msgid "The Email Template has been successfully added."
283
+ msgstr ""
284
+
285
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates.php:197
286
+ msgid "The Email Template has been cloned successfully."
287
+ msgstr ""
288
+
289
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates.php:207
290
+ msgid "The Email Template has been successfully deleted."
291
+ msgstr ""
292
+
293
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates.php:216
294
+ msgid "The Email Template has been successfully updated."
295
+ msgstr ""
296
+
297
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates.php:226
298
+ msgid "Default Email Templates has been restored successfully."
299
+ msgstr ""
300
+
301
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates.php:392
302
+ msgid "Activate Template now?"
303
+ msgstr ""
304
+
305
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates.php:412
306
+ msgid "Template Name:"
307
+ msgstr ""
308
+
309
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates.php:427
310
+ msgid "Email Subject:"
311
+ msgstr ""
312
+
313
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates.php:442
314
+ msgid "Email Body:"
315
+ msgstr ""
316
+
317
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates.php:471
318
+ msgid "Create Coupon"
319
+ msgstr ""
320
+
321
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates.php:541
322
+ msgid "Coupon expiry date"
323
+ msgstr ""
324
+
325
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates.php:578
326
+ msgid "Send This Email"
327
+ msgstr ""
328
+
329
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates.php:611
330
+ msgid "after cart is abandoned."
331
+ msgstr ""
332
+
333
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates.php:621
334
+ msgid "Send Test Email To:"
335
+ msgstr ""
336
+
337
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates.php:935
338
+ msgid "Create New Template"
339
+ msgstr ""
340
+
341
+ #: modules/cart-abandonment/class-cartflows-ca-email-templates.php:938
342
+ msgid " Restore Default Templates"
343
+ msgstr ""
344
+
345
+ #: modules/cart-abandonment/includes/admin/cartflows-cart-abandonment-reports.php:46
346
+ msgid "Recoverable Orders"
347
+ msgstr ""
348
+
349
+ #: modules/cart-abandonment/includes/admin/cartflows-cart-abandonment-reports.php:50
350
+ msgid "Total Recoverable Orders."
351
+ msgstr ""
352
+
353
+ #: modules/cart-abandonment/includes/admin/cartflows-cart-abandonment-reports.php:55
354
+ msgid "Recovered Orders"
355
+ msgstr ""
356
+
357
+ #: modules/cart-abandonment/includes/admin/cartflows-cart-abandonment-reports.php:57
358
+ msgid "Total Recovered Orders."
359
+ msgstr ""
360
+
361
+ #: modules/cart-abandonment/includes/admin/cartflows-cart-abandonment-reports.php:62
362
+ msgid "Lost Orders"
363
+ msgstr ""
364
+
365
+ #: modules/cart-abandonment/includes/admin/cartflows-cart-abandonment-reports.php:65
366
+ msgid "Total Lost Orders."
367
+ msgstr ""
368
+
369
+ #: modules/cart-abandonment/includes/admin/cartflows-cart-abandonment-reports.php:74
370
+ msgid "Recoverable Revenue"
371
+ msgstr ""
372
+
373
+ #: modules/cart-abandonment/includes/admin/cartflows-cart-abandonment-reports.php:79
374
+ msgid "Total Recoverable Revenue."
375
+ msgstr ""
376
+
377
+ #: modules/cart-abandonment/includes/admin/cartflows-cart-abandonment-reports.php:84
378
+ msgid "Recovered Revenue"
379
+ msgstr ""
380
+
381
+ #: modules/cart-abandonment/includes/admin/cartflows-cart-abandonment-reports.php:90
382
+ msgid "Total Recovered Revenue."
383
+ msgstr ""
384
+
385
+ #: modules/cart-abandonment/includes/admin/cartflows-cart-abandonment-reports.php:95
386
+ msgid "Recovery Rate"
387
+ msgstr ""
388
+
389
+ #: modules/cart-abandonment/includes/admin/cartflows-cart-abandonment-reports.php:97
390
+ msgid "Total Percentage Of Recovered Orders After Abandonment."
391
+ msgstr ""
392
+
393
+ #: modules/cart-abandonment/includes/admin/cartflows-cart-abandonment-reports.php:135
394
+ msgid "No Orders Found."
395
+ msgstr ""
396
+
397
+ #: modules/cart-abandonment/includes/admin/cartflows-cart-abandonment-tabs.php:10
398
+ msgid "Woocommerce Cart Abandonment Recovery "
399
+ msgstr ""
400
+
401
+ #. Plugin Name of the plugin/theme
402
+ msgid "Woocommerce Cart Abandonment Recovery"
403
+ msgstr ""
404
+
405
+ #. Author URI of the plugin/theme
406
+ msgid "https://cartflows.com/"
407
+ msgstr ""
408
+
409
+ #. Description of the plugin/theme
410
+ msgid ""
411
+ "Recover your lost revenue. Capture email address of users on the checkout "
412
+ "page and send follow up emails if they don't complete the purchase."
413
+ msgstr ""
414
+
415
+ #. Author of the plugin/theme
416
+ msgid "CartFlows Inc"
417
+ msgstr ""
modules/cart-abandonment/assets/js/cart-abandonment-tracking.js ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function ($) {
2
+
3
+ var timer;
4
+ var wcf_cart_abandonment = {
5
+
6
+ init: function () {
7
+
8
+ if ( CartFlowsProCAVars._show_gdpr_message && ! $("#wcf_cf_gdpr_message_block").length ) {
9
+ $("#billing_email").after("<span id='wcf_cf_gdpr_message_block'> <span style='font-size: xx-small'> "+ CartFlowsProCAVars._gdpr_message +" <a style='cursor: pointer' id='wcf_ca_gdpr_no_thanks'> "+ CartFlowsProCAVars._gdpr_nothanks_msg +" </a></span></span>");
10
+ }
11
+
12
+ $(document).on(
13
+ 'keyup keypress change',
14
+ '#billing_email, #billing_phone, input.input-text, textarea.input-text, select',
15
+ this._getCheckoutData
16
+ );
17
+
18
+ $("#wcf_ca_gdpr_no_thanks").click( function () {
19
+ wcf_cart_abandonment._set_cookie();
20
+ } );
21
+
22
+ $( document.body ).on( 'updated_checkout', function(){
23
+ wcf_cart_abandonment._getCheckoutData();
24
+ });
25
+
26
+ $(document).on('ready', function(e) {
27
+ setTimeout(function() {
28
+ wcf_cart_abandonment._getCheckoutData();
29
+ }, 800);
30
+ });
31
+ },
32
+
33
+ _set_cookie: function() {
34
+
35
+
36
+ var data = {
37
+ 'wcf_ca_skip_track_data': true,
38
+ 'action': 'cartflows_skip_cart_tracking_gdpr',
39
+ 'security': CartFlowsProCAVars._gdpr_nonce,
40
+ };
41
+
42
+ jQuery.post(
43
+ CartFlowsProCAVars.ajaxurl,data,
44
+ function (response) {
45
+
46
+ if(response.success) {
47
+ $("#wcf_cf_gdpr_message_block").empty().append("<span style='font-size: xx-small'>You won't receive further emails from us, thank you!</span>").delay(5000).fadeOut();
48
+ }
49
+
50
+ }
51
+ );
52
+
53
+ },
54
+
55
+ _validate_email: function (value) {
56
+ var valid = true;
57
+ if (value.indexOf('@') == -1) {
58
+ valid = false;
59
+ } else {
60
+ var parts = value.split('@');
61
+ var domain = parts[1];
62
+ if (domain.indexOf('.') == -1) {
63
+ valid = false;
64
+ } else {
65
+ var domainParts = domain.split('.');
66
+ var ext = domainParts[1];
67
+ if (ext.length > 14 || ext.length < 2) {
68
+ valid = false;
69
+ }
70
+ }
71
+ }
72
+ return valid;
73
+ },
74
+
75
+ _getCheckoutData: function () {
76
+
77
+ var wcf_phone = jQuery("#billing_phone").val();
78
+ var wcf_email = jQuery("#billing_email").val();
79
+ var atposition = wcf_email.indexOf("@");
80
+ var dotposition = wcf_email.lastIndexOf(".");
81
+
82
+ if (typeof wcf_phone === 'undefined' || wcf_phone === null) { //If phone number field does not exist on the Checkout form
83
+ wcf_phone = '';
84
+ }
85
+
86
+ clearTimeout(timer);
87
+
88
+ if (!(atposition < 1 || dotposition < atposition + 2 || dotposition + 2 >= wcf_email.length) || wcf_phone.length >= 1) { //Checking if the email field is valid or phone number is longer than 1 digit
89
+ //If Email or Phone valid
90
+ var wcf_name = jQuery("#billing_first_name").val();
91
+ var wcf_surname = jQuery("#billing_last_name").val();
92
+ var wcf_phone = jQuery("#billing_phone").val();
93
+ var wcf_country = jQuery("#billing_country").val();
94
+ var wcf_city = jQuery("#billing_city").val();
95
+
96
+ //Other fields used for "Remember user input" function
97
+ var wcf_billing_company = jQuery("#billing_company").val();
98
+ var wcf_billing_address_1 = jQuery("#billing_address_1").val();
99
+ var wcf_billing_address_2 = jQuery("#billing_address_2").val();
100
+ var wcf_billing_state = jQuery("#billing_state").val();
101
+ var wcf_billing_postcode = jQuery("#billing_postcode").val();
102
+ var wcf_shipping_first_name = jQuery("#shipping_first_name").val();
103
+ var wcf_shipping_last_name = jQuery("#shipping_last_name").val();
104
+ var wcf_shipping_company = jQuery("#shipping_company").val();
105
+ var wcf_shipping_country = jQuery("#shipping_country").val();
106
+ var wcf_shipping_address_1 = jQuery("#shipping_address_1").val();
107
+ var wcf_shipping_address_2 = jQuery("#shipping_address_2").val();
108
+ var wcf_shipping_city = jQuery("#shipping_city").val();
109
+ var wcf_shipping_state = jQuery("#shipping_state").val();
110
+ var wcf_shipping_postcode = jQuery("#shipping_postcode").val();
111
+ var wcf_order_comments = jQuery("#order_comments").val();
112
+
113
+ var data = {
114
+ action: "cartflows_save_cart_abandonment_data",
115
+ wcf_email: wcf_email,
116
+ wcf_name: wcf_name,
117
+ wcf_surname: wcf_surname,
118
+ wcf_phone: wcf_phone,
119
+ wcf_country: wcf_country,
120
+ wcf_city: wcf_city,
121
+ wcf_billing_company: wcf_billing_company,
122
+ wcf_billing_address_1: wcf_billing_address_1,
123
+ wcf_billing_address_2: wcf_billing_address_2,
124
+ wcf_billing_state: wcf_billing_state,
125
+ wcf_billing_postcode: wcf_billing_postcode,
126
+ wcf_shipping_first_name: wcf_shipping_first_name,
127
+ wcf_shipping_last_name: wcf_shipping_last_name,
128
+ wcf_shipping_company: wcf_shipping_company,
129
+ wcf_shipping_country: wcf_shipping_country,
130
+ wcf_shipping_address_1: wcf_shipping_address_1,
131
+ wcf_shipping_address_2: wcf_shipping_address_2,
132
+ wcf_shipping_city: wcf_shipping_city,
133
+ wcf_shipping_state: wcf_shipping_state,
134
+ wcf_shipping_postcode: wcf_shipping_postcode,
135
+ wcf_order_comments: wcf_order_comments,
136
+ security: CartFlowsProCAVars._nonce,
137
+ wcf_post_id: CartFlowsProCAVars._post_id,
138
+ }
139
+
140
+ timer = setTimeout(
141
+ function () {
142
+ if (wcf_cart_abandonment._validate_email(data.wcf_email)) {
143
+ jQuery.post(
144
+ CartFlowsProCAVars.ajaxurl, data, //Ajaxurl coming from localized script and contains the link to wp-admin/admin-ajax.php file that handles AJAX requests on Wordpress
145
+ function (response) {
146
+ // success response
147
+ }
148
+ );
149
+ }
150
+ }, 500
151
+ );
152
+ } else {
153
+ //console.log("Not a valid e-mail or phone address");
154
+ }
155
+ }
156
+
157
+ }
158
+
159
+ wcf_cart_abandonment.init();
160
+
161
+ })(jQuery);
modules/cart-abandonment/class-cartflows-ca-cart-abandonment-db.php ADDED
@@ -0,0 +1,235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Cart Abandonment DB
4
+ *
5
+ * @package Woocommerce-Cart-Abandonment-Recovery
6
+ */
7
+
8
+ /**
9
+ * Cart Abandonment DB class.
10
+ */
11
+ class Cartflows_Ca_Cart_Abandonment_Db {
12
+
13
+
14
+
15
+ /**
16
+ * Member Variable
17
+ *
18
+ * @var object instance
19
+ */
20
+ private static $instance;
21
+
22
+ /**
23
+ * Initiator
24
+ */
25
+ public static function get_instance() {
26
+ if ( ! isset( self::$instance ) ) {
27
+ self::$instance = new self;
28
+ }
29
+ return self::$instance;
30
+ }
31
+
32
+ /**
33
+ * Create tables
34
+ */
35
+ public function create_tables() {
36
+ $this->create_cart_abandonment_table();
37
+ $this->create_cart_abandonment_template_table();
38
+ $this->create_email_templates_meta_table();
39
+ $this->create_email_history_table();
40
+ }
41
+
42
+ /**
43
+ * Create Email templates meta table.
44
+ */
45
+ public function create_email_templates_meta_table() {
46
+ global $wpdb;
47
+
48
+ $email_template_meta_db = $wpdb->prefix . CARTFLOWS_CA_EMAIL_TEMPLATE_META_TABLE;
49
+ $cart_abandonment_template_db = $wpdb->prefix . CARTFLOWS_CA_EMAIL_TEMPLATE_TABLE;
50
+ $charset_collate = $wpdb->get_charset_collate();
51
+
52
+ // Email templates meta table db sql command.
53
+ $sql = "CREATE TABLE IF NOT EXISTS $email_template_meta_db (
54
+ `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
55
+ `email_template_id` BIGINT(20) NOT NULL,
56
+ `meta_key` varchar(255) NOT NULL,
57
+ `meta_value` longtext NOT NULL,
58
+ PRIMARY KEY (`id`),
59
+ FOREIGN KEY ( `email_template_id` ) REFERENCES $cart_abandonment_template_db(`id`) ON DELETE CASCADE
60
+ ) $charset_collate;\n";
61
+
62
+ include_once ABSPATH . 'wp-admin/includes/upgrade.php';
63
+ dbDelta( $sql );
64
+
65
+ }
66
+
67
+ /**
68
+ * Create tables for analytics.
69
+ */
70
+ public function create_cart_abandonment_table() {
71
+
72
+ global $wpdb;
73
+
74
+ $cart_abandonment_db = $wpdb->prefix . CARTFLOWS_CA_CART_ABANDONMENT_TABLE;
75
+ $charset_collate = $wpdb->get_charset_collate();
76
+
77
+ // Cart abandonment tracking db sql command.
78
+ $sql = "CREATE TABLE IF NOT EXISTS $cart_abandonment_db (
79
+ id BIGINT(20) NOT NULL AUTO_INCREMENT,
80
+ checkout_id int(11) NOT NULL,
81
+ email VARCHAR(100),
82
+ cart_contents LONGTEXT,
83
+ cart_total DECIMAL(10,2),
84
+ session_id VARCHAR(60) NOT NULL,
85
+ other_fields LONGTEXT,
86
+ order_status ENUM( 'normal','abandoned','completed','lost') NOT NULL DEFAULT 'normal',
87
+ unsubscribed boolean DEFAULT 0,
88
+ coupon_code VARCHAR(50),
89
+ time DATETIME DEFAULT CURRENT_TIMESTAMP,
90
+ PRIMARY KEY (`id`, `session_id`),
91
+ UNIQUE KEY `session_id_UNIQUE` (`session_id`)
92
+ ) $charset_collate;\n";
93
+
94
+ include_once ABSPATH . 'wp-admin/includes/upgrade.php';
95
+ dbDelta( $sql );
96
+
97
+ }
98
+
99
+ /**
100
+ * Create tables for analytics.
101
+ */
102
+ public function create_cart_abandonment_template_table() {
103
+
104
+ global $wpdb;
105
+
106
+ $cart_abandonment_template_db = $wpdb->prefix . CARTFLOWS_CA_EMAIL_TEMPLATE_TABLE;
107
+
108
+ $charset_collate = $wpdb->get_charset_collate();
109
+
110
+ // Cart abandonment tracking db sql command.
111
+ $sql = "CREATE TABLE IF NOT EXISTS $cart_abandonment_template_db (
112
+ `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
113
+ `template_name` text NOT NULL,
114
+ `email_subject` text NOT NULL,
115
+ `email_body` mediumtext NOT NULL,
116
+ `is_activated` tinyint(1) NOT NULL DEFAULT '0',
117
+ `frequency` int(11) NOT NULL,
118
+ `frequency_unit` ENUM( 'MINUTE','HOUR','DAY') NOT NULL DEFAULT 'MINUTE',
119
+ PRIMARY KEY (`id`)
120
+ ) $charset_collate;\n";
121
+
122
+ include_once ABSPATH . 'wp-admin/includes/upgrade.php';
123
+ dbDelta( $sql );
124
+
125
+ }
126
+
127
+ /**
128
+ * Create tables for analytics.
129
+ */
130
+ public function create_email_history_table() {
131
+
132
+ global $wpdb;
133
+
134
+ $cart_abandonment_history_db = $wpdb->prefix . CARTFLOWS_CA_EMAIL_HISTORY_TABLE;
135
+ $cart_abandonment_db = $wpdb->prefix . CARTFLOWS_CA_CART_ABANDONMENT_TABLE;
136
+ $cart_abandonment_template_db = $wpdb->prefix . CARTFLOWS_CA_EMAIL_TEMPLATE_TABLE;
137
+
138
+ $charset_collate = $wpdb->get_charset_collate();
139
+
140
+ $sql = "CREATE TABLE IF NOT EXISTS $cart_abandonment_history_db (
141
+ `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
142
+ `template_id` BIGINT(20) NOT NULL,
143
+ `ca_session_id` VARCHAR(60),
144
+ `coupon_code` VARCHAR(50),
145
+ `scheduled_time` DATETIME,
146
+ `email_sent` boolean DEFAULT 0,
147
+ PRIMARY KEY (`id`),
148
+ FOREIGN KEY ( `template_id` ) REFERENCES $cart_abandonment_template_db(`id`) ON DELETE CASCADE,
149
+ FOREIGN KEY ( `ca_session_id` ) REFERENCES $cart_abandonment_db(`session_id`) ON DELETE CASCADE
150
+ ) $charset_collate;\n";
151
+
152
+ include_once ABSPATH . 'wp-admin/includes/upgrade.php';
153
+ dbDelta( $sql );
154
+
155
+ }
156
+
157
+ /**
158
+ * Insert initial sample email templates.
159
+ *
160
+ * @param boolean $force_restore restore forcefully.
161
+ */
162
+ public function template_table_seeder( $force_restore = false ) {
163
+ global $wpdb;
164
+ $cart_abandonment_template_db = $wpdb->prefix . CARTFLOWS_CA_EMAIL_TEMPLATE_TABLE;
165
+ $cart_abandonment_template_meta_db = $wpdb->prefix . CARTFLOWS_CA_EMAIL_TEMPLATE_META_TABLE;
166
+
167
+ $email_templates = array(
168
+ array(
169
+ 'template_name' => 'Sample Email Template 1',
170
+ 'subject' => 'Purchase issue?',
171
+ 'body' => "<p>Hi {{customer.firstname}}!</p><p>We\'re having trouble processing your recent purchase. Would you mind completing it?</p><p>Here\'s a link to continue where you left off:</p><p><a href='{{cart.checkout_url}}' target='_blank' rel='noopener'> Continue Your Purchase Now </a></p><p>Kindly,<br />{{admin.firstname}}<br />{{admin.company}}</p><p>{{cart.unsubscribe}}</p>",
172
+ 'frequency' => 30,
173
+ 'frequency_unit' => 'MINUTE',
174
+ ),
175
+ array(
176
+ 'template_name' => 'Sample Email Template 2',
177
+ 'subject' => 'Need help?',
178
+ 'body' => "<p>Hi {{customer.firstname}}!</p><p>I'm {{admin.firstname}}, and I help handle customer issues at {{admin.company}}.</p><p>I just noticed that you tried to make a purchase, but unfortunately, there was some trouble. Is there anything I can do to help?</p><p>You should be able to complete your checkout in less than a minute:<br /><a href='{{cart.checkout_url}}' target='_blank' rel='noopener'> Click here to continue your purchase </a><p><p>Thanks!<br />{{admin.firstname}}<br />{{admin.company}}</p><p>{{cart.unsubscribe}}</p>",
179
+ 'frequency' => 1,
180
+ 'frequency_unit' => 'DAY',
181
+ ),
182
+ array(
183
+ 'template_name' => 'Sample Email Template 3',
184
+ 'subject' => 'Exclusive discount for you. Let\'s get things started!',
185
+ 'body' => "<p>Few days back you left {{cart.product.names}} in your cart.</p><p>To help make up your mind, we have added an exclusive 10% discount coupon {{cart.coupon_code}} to your cart.</p><p><a href='{{cart.checkout_url}}' target='_blank' rel='noopener'>Complete Your Purchase Now &gt;&gt;</a></p><p>Hurry! This is a onetime offer and will expire in 24 Hours.</p><p>In case you couldn\'t finish your order due to technical difficulties or because you need some help, just reply to this email we will be happy to help.</p><p>Kind Regards,<br />{{admin.firstname}}<br />{{admin.company}}</p><p>{{cart.unsubscribe}}</p>",
186
+ 'frequency' => 3,
187
+ 'frequency_unit' => 'DAY',
188
+ ),
189
+ );
190
+
191
+ // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
192
+ $template_index = 1;
193
+ $template_meta_index = 1;
194
+ foreach ( $email_templates as $email_template ) {
195
+ $wpdb->query(
196
+ $wpdb->prepare(
197
+ "INSERT INTO $cart_abandonment_template_db (`id`, `template_name`, `email_subject`, `email_body`, `frequency`, `frequency_unit`)
198
+ VALUES ( %d, %s, %s, %s, %d, %s ) ON DUPLICATE KEY UPDATE id = id",
199
+ $force_restore ? null : $template_index++,
200
+ $email_template['template_name'],
201
+ $email_template['subject'],
202
+ $email_template['body'],
203
+ $email_template['frequency'],
204
+ $email_template['frequency_unit']
205
+ )
206
+ );
207
+
208
+ $meta_data = array(
209
+ 'override_global_coupon' => false,
210
+ 'discount_type' => 'percent',
211
+ 'coupon_amount' => 10,
212
+ 'coupon_expiry_date' => '',
213
+ 'coupon_expiry_unit' => 'hours',
214
+ );
215
+
216
+ $email_tmpl_id = $wpdb->insert_id;
217
+
218
+ foreach ( $meta_data as $meta_key => $meta_value ) {
219
+ $wpdb->query(
220
+ $wpdb->prepare(
221
+ "INSERT INTO $cart_abandonment_template_meta_db ( `id`, `email_template_id`, `meta_key`, `meta_value` )
222
+ VALUES ( %d, %d, %s, %s ) ON DUPLICATE KEY UPDATE id = id",
223
+ $force_restore ? null : $template_meta_index++,
224
+ $email_tmpl_id,
225
+ $meta_key,
226
+ $meta_value
227
+ )
228
+ );
229
+ }
230
+ }
231
+ // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
232
+ }
233
+ }
234
+
235
+ Cartflows_Ca_Cart_Abandonment_Db::get_instance();
modules/cart-abandonment/class-cartflows-ca-cart-abandonment-table.php ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Cart Abandonment
4
+ *
5
+ * @package Woocommerce-Cart-Abandonment-Recovery
6
+ */
7
+
8
+ if ( ! class_exists( 'WP_List_Table' ) ) {
9
+ include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
10
+ }
11
+ /**
12
+ * Cart abandonment tracking table class.
13
+ */
14
+ class Cartflows_Ca_Cart_Abandonment_Table extends WP_List_Table {
15
+
16
+
17
+
18
+ /**
19
+ * Constructor function.
20
+ */
21
+ function __construct() {
22
+ global $status, $page;
23
+
24
+ parent::__construct(
25
+ array(
26
+ 'singular' => 'id',
27
+ 'plural' => 'ids',
28
+ )
29
+ );
30
+ }
31
+
32
+ /**
33
+ * Default columns.
34
+ *
35
+ * @param object $item item.
36
+ * @param string $column_name column name.
37
+ */
38
+ function column_default( $item, $column_name ) {
39
+ return $item[ $column_name ];
40
+ }
41
+
42
+ /**
43
+ * Column name surname.
44
+ *
45
+ * @param object $item item.
46
+ * @return string
47
+ */
48
+ function column_nameSurname( $item ) {
49
+
50
+ $item_details = unserialize( $item['other_fields'] );
51
+
52
+ $page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING );
53
+
54
+ $actions = array(
55
+ 'delete' => sprintf( '<a onclick="return confirm(\'Are you sure to delete this order?\');" href="?page=%s&action=delete&id=%s">%s</a>', esc_html( $page ), esc_html( $item['id'] ), __( 'Delete', 'cartflows-ca' ) ),
56
+ );
57
+
58
+ if ( WCF_CART_ABANDONED_ORDER === $item['order_status'] && ! $item['unsubscribed'] ) {
59
+ $actions['unsubscribe'] = sprintf( '<a onclick="return confirm(\'Are you sure to unsubscribe this user? \');" href="?page=%s&action=unsubscribe&id=%s">%s</a>', esc_html( $page ), esc_html( $item['id'] ), __( 'Unsubscribe', 'cartflows-ca' ) );
60
+
61
+ }
62
+
63
+ return sprintf(
64
+ '<span class="dashicons dashicons-admin-users"></span> %s %s %s',
65
+ esc_html( $item_details['wcf_first_name'] ),
66
+ esc_html( $item_details['wcf_last_name'] ),
67
+ $this->row_actions( $actions )
68
+ );
69
+ }
70
+
71
+ /**
72
+ * Rendering Email field
73
+ *
74
+ * @param object $item - row (key, value array).
75
+ * @return HTML
76
+ */
77
+ function column_email( $item ) {
78
+ return sprintf(
79
+ '<a href="mailto:%1$s" title="">%1$s</a>',
80
+ esc_html( $item['email'] )
81
+ );
82
+ }
83
+
84
+ /**
85
+ * Render date column
86
+ *
87
+ * @param object $item - row (key, value array).
88
+ * @return HTML
89
+ */
90
+ function column_time( $item ) {
91
+ $database_time = $item['time'];
92
+ $date_time = new DateTime( $database_time );
93
+ $date = $date_time->format( 'd.m.Y' );
94
+ $time = $date_time->format( 'H:i:s' );
95
+
96
+ return sprintf(
97
+ '<span class="dashicons dashicons-clock"></span> %s %s',
98
+ esc_html( $time ),
99
+ esc_html( $date )
100
+ );
101
+ }
102
+
103
+ /**
104
+ * This is how checkbox column renders.
105
+ *
106
+ * @param object $item item.
107
+ * @return HTML
108
+ */
109
+ function column_cb( $item ) {
110
+ return sprintf(
111
+ '<input type="checkbox" name="id[]" value="%s" />',
112
+ esc_html( $item['id'] )
113
+ );
114
+ }
115
+
116
+ /**
117
+ * [OPTIONAL] Return array of bult actions if has any
118
+ *
119
+ * @return array
120
+ */
121
+ function get_bulk_actions() {
122
+ $actions = array(
123
+ 'delete' => __( 'Delete', 'cartflows-ca' ),
124
+ );
125
+ return $actions;
126
+ }
127
+
128
+ /**
129
+ * Whether the table has items to display or not
130
+ *
131
+ * @return bool
132
+ */
133
+ public function has_items() {
134
+ return ! empty( $this->items );
135
+ }
136
+
137
+ /**
138
+ * Fetch data from the database to render on view.
139
+ *
140
+ * @param string $cart_type abandoned|completed.
141
+ * @param string $from_date from date.
142
+ * @param string $to_date to date.
143
+ */
144
+ function prepare_items( $cart_type = WCF_CART_ABANDONED_ORDER, $from_date = '', $to_date = '' ) {
145
+ global $wpdb;
146
+ $cart_abandonment_table_name = $wpdb->prefix . CARTFLOWS_CA_CART_ABANDONMENT_TABLE;
147
+
148
+ $per_page = 10;
149
+
150
+ $columns = $this->get_columns();
151
+ $hidden = array();
152
+ $sortable = $this->get_sortable_columns();
153
+
154
+ $this->_column_headers = array( $columns, $hidden, $sortable );
155
+
156
+ $this->process_bulk_action();
157
+
158
+ $paged = filter_input( INPUT_GET, 'paged', FILTER_SANITIZE_NUMBER_INT );
159
+ $orderby = filter_input( INPUT_GET, 'orderby', FILTER_SANITIZE_STRING );
160
+ $order = filter_input( INPUT_GET, 'order', FILTER_SANITIZE_STRING );
161
+
162
+ $paged = $paged ? max( 0, $paged - 1 ) : 0;
163
+ $orderby = ( $orderby && in_array( $orderby, array_keys( $this->get_sortable_columns() ), true ) ) ? $orderby : 'id';
164
+ $order = ( $order && in_array( $order, array( 'asc', 'desc' ), true ) ) ? $order : 'desc';
165
+
166
+ $this->items = $wpdb->get_results(
167
+ $wpdb->prepare("SELECT * FROM $cart_abandonment_table_name WHERE `order_status` = %s AND DATE(`time`) >= %s AND DATE(`time`) <= %s ORDER BY $orderby $order LIMIT %d OFFSET %d", $cart_type, $from_date, $to_date, $per_page, $paged * $per_page), ARRAY_A); // phpcs:ignore
168
+
169
+ $total_items = count( $this->items );
170
+
171
+ // [REQUIRED] configure pagination
172
+ $this->set_pagination_args(
173
+ array(
174
+ 'total_items' => $total_items,
175
+ 'per_page' => $per_page,
176
+ 'total_pages' => ceil( $total_items / $per_page ),
177
+ )
178
+ );
179
+ }
180
+
181
+ /**
182
+ * Table columns.
183
+ *
184
+ * @return array
185
+ */
186
+ function get_columns() {
187
+ $columns = array(
188
+ 'cb' => '<input type="checkbox" />',
189
+ 'nameSurname' => __( 'Name', 'cartflows-ca' ),
190
+ 'email' => __( 'Email', 'cartflows-ca' ),
191
+ 'cart_total' => __( 'Cart Total', 'cartflows-ca' ),
192
+ 'order_status' => __( 'Order Status', 'cartflows-ca' ),
193
+ 'time' => __( 'Time', 'cartflows-ca' ),
194
+ );
195
+ return $columns;
196
+ }
197
+
198
+ /**
199
+ * Table sortable columns.
200
+ *
201
+ * @return array
202
+ */
203
+ public function get_sortable_columns() {
204
+ $sortable = array(
205
+ 'nameSurname' => array( 'name', true ),
206
+ 'cart_total' => array( 'cart_total', true ),
207
+ 'cart_total' => array( 'Cart Total', true ),
208
+ 'order_status' => array( 'Order Status', true ),
209
+ 'time' => array( 'time', true ),
210
+ );
211
+ return $sortable;
212
+ }
213
+
214
+ /**
215
+ * Processes bulk actions
216
+ */
217
+ function process_bulk_action() {
218
+ global $wpdb;
219
+ $table_name = $wpdb->prefix . CARTFLOWS_CA_CART_ABANDONMENT_TABLE;
220
+
221
+ if ( 'delete' === $this->current_action() ) {
222
+
223
+ $ids = array();
224
+ if ( isset( $_REQUEST['id'] ) && is_array( $_REQUEST['id'] ) ) {
225
+ $ids = array_map( 'intval', $_REQUEST['id'] );
226
+ }
227
+ $ids = implode( ',', $ids );
228
+
229
+ if ( ! empty( $ids ) ) {
230
+ $wpdb->query("DELETE FROM $table_name WHERE id IN($ids)"); // phpcs:ignore
231
+ }
232
+ }
233
+ }
234
+ }
modules/cart-abandonment/class-cartflows-ca-cart-abandonment.php ADDED
@@ -0,0 +1,1639 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Cart Abandonment
4
+ *
5
+ * @package Woocommerce-Cart-Abandonment-Recovery
6
+ */
7
+
8
+ /**
9
+ * Cart abandonment tracking class.
10
+ */
11
+ class Cartflows_Ca_Cart_Abandonment {
12
+
13
+
14
+
15
+ /**
16
+ * Member Variable
17
+ *
18
+ * @var object instance
19
+ */
20
+ private static $instance;
21
+
22
+ /**
23
+ * Initiator
24
+ */
25
+ public static function get_instance() {
26
+ if ( ! isset( self::$instance ) ) {
27
+ self::$instance = new self;
28
+ }
29
+ return self::$instance;
30
+ }
31
+
32
+ /**
33
+ * Constructor function that initializes required actions and hooks.
34
+ */
35
+ public function __construct() {
36
+
37
+ $this->define_cart_abandonment_constants();
38
+
39
+ // Adding menu to view cart abandonment report.
40
+ add_action( 'admin_menu', array( $this, 'abandoned_cart_tracking_menu' ), 999 );
41
+
42
+ // Adding the styles and scripts for the cart abandonment.
43
+ add_action( 'admin_enqueue_scripts', array( $this, 'load_admin_cart_abandonment_script' ), 20 );
44
+
45
+ if ( wcf_ca()->utils->is_cart_abandonment_tracking_enabled() && ! isset( $_COOKIE['wcf_ca_skip_track_data'] ) ) {
46
+
47
+ add_action( 'woocommerce_update_cart_action_cart_updated', 'on_action_cart_updated', 20, 1 );
48
+
49
+ // Add script to track the cart abandonment.
50
+ add_action( 'woocommerce_after_checkout_form', array( $this, 'cart_abandonment_tracking_script' ) );
51
+
52
+ // Store user details from the current checkout page.
53
+ add_action( 'wp_ajax_cartflows_save_cart_abandonment_data', array( $this, 'save_cart_abandonment_data' ) );
54
+ add_action( 'wp_ajax_nopriv_cartflows_save_cart_abandonment_data', array( $this, 'save_cart_abandonment_data' ) );
55
+
56
+ // GDPR actions.
57
+ add_action( 'wp_ajax_cartflows_skip_cart_tracking_gdpr', array( $this, 'skip_cart_tracking_by_gdpr' ) );
58
+ add_action( 'wp_ajax_nopriv_cartflows_skip_cart_tracking_gdpr', array( $this, 'skip_cart_tracking_by_gdpr' ) );
59
+
60
+ // Delete the stored cart abandonment data once order gets created.
61
+ add_action( 'woocommerce_new_order', array( $this, 'delete_cart_abandonment_data' ) );
62
+ add_action( 'woocommerce_thankyou', array( $this, 'delete_cart_abandonment_data' ) );
63
+
64
+ // Adding filter to restore the data if recreating abandonment order.
65
+ add_filter( 'wp', array( $this, 'restore_cart_abandonment_data' ), 10 );
66
+ add_filter( 'wp', array( $this, 'unsubscribe_cart_abandonment_emails' ), 10 );
67
+
68
+ add_action( 'wp_ajax_wcf_ca_preview_email_send', array( $this, 'send_preview_email' ) );
69
+
70
+ $page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING );
71
+ if ( WCF_CA_PAGE_NAME === $page ) {
72
+ // Adding filter to add new button to add custom fields.
73
+ add_filter( 'mce_buttons', array( $this, 'wcf_filter_mce_button' ) );
74
+ add_filter( 'mce_external_plugins', array( $this, 'wcf_filter_mce_plugin' ) );
75
+ }
76
+
77
+ add_filter( 'cron_schedules', array( $this, 'cartflows_ca_update_order_status_action' ) );
78
+
79
+ // Schedule an action if it's not already scheduled.
80
+ if ( ! wp_next_scheduled( 'cartflows_ca_update_order_status_action' ) ) {
81
+ wp_schedule_event( time(), 'every_fifteen_minutes', 'cartflows_ca_update_order_status_action' );
82
+ }
83
+ add_action( 'cartflows_ca_update_order_status_action', array( $this, 'update_order_status' ) );
84
+
85
+ }
86
+
87
+ }
88
+
89
+ /**
90
+ * Send preview emails.
91
+ */
92
+ public function send_preview_email() {
93
+
94
+ check_ajax_referer( WCF_EMAIL_TEMPLATES_NONCE, 'security' );
95
+ $mail_result = $this->send_email_templates( null, true );
96
+ if ( $mail_result ) {
97
+ wp_send_json_success( __( 'Mail has been sent successfully!', 'cartflows-ca' ) );
98
+ } else {
99
+ wp_send_json_error( __( 'Mail sending failed!', 'cartflows-ca' ) );
100
+ }
101
+ }
102
+
103
+
104
+ /**
105
+ * Delete tracked data and set cookie for the user.
106
+ */
107
+ public function skip_cart_tracking_by_gdpr() {
108
+ check_ajax_referer( 'cartflows_skip_cart_tracking_gdpr', 'security' );
109
+
110
+ global $wpdb;
111
+ $cart_abandonment_table = $wpdb->prefix . CARTFLOWS_CA_CART_ABANDONMENT_TABLE;
112
+
113
+ $session_id = WC()->session->get( 'wcf_session_id' );
114
+ if ( $session_id ) {
115
+ $wpdb->delete( $cart_abandonment_table, array( 'session_id' => sanitize_key( $session_id ) ) );
116
+ }
117
+
118
+ setcookie( 'wcf_ca_skip_track_data', 'true', 0, '/' );
119
+ wp_send_json_success();
120
+
121
+ }
122
+
123
+
124
+ /**
125
+ * Create custom schedule.
126
+ *
127
+ * @return mixed
128
+ */
129
+ function cartflows_ca_update_order_status_action() {
130
+ $schedules['every_fifteen_minutes'] = array(
131
+ 'interval' => 15 * MINUTE_IN_SECONDS,
132
+ 'display' => __( 'Every Fifteen Minutes', 'cartflows-ca' ),
133
+ );
134
+ return $schedules;
135
+ }
136
+
137
+ /**
138
+ * Generate new coupon code for abandoned cart.
139
+ *
140
+ * @param string $discount_type discount type.
141
+ * @param float $amount amount.
142
+ * @param string $expiry expiry.
143
+ */
144
+ function generate_coupon_code( $discount_type, $amount, $expiry = '' ) {
145
+
146
+ $coupon_code = '';
147
+
148
+ if ( $discount_type && $amount ) {
149
+
150
+ $coupon_code = wp_generate_password( 8, false, false );
151
+
152
+ $coupon = array(
153
+ 'post_title' => $coupon_code,
154
+ 'post_content' => '',
155
+ 'post_status' => 'publish',
156
+ 'post_author' => 1,
157
+ 'post_type' => 'shop_coupon',
158
+ );
159
+
160
+ $new_coupon_id = wp_insert_post( $coupon );
161
+
162
+ update_post_meta( $new_coupon_id, 'discount_type', $discount_type );
163
+ update_post_meta( $new_coupon_id, 'description', 'This coupon is for abandoned cart email templates.' );
164
+ update_post_meta( $new_coupon_id, 'coupon_amount', $amount );
165
+ update_post_meta( $new_coupon_id, 'individual_use', 'no' );
166
+ update_post_meta( $new_coupon_id, 'product_ids', '' );
167
+ update_post_meta( $new_coupon_id, 'exclude_product_ids', '' );
168
+ update_post_meta( $new_coupon_id, 'usage_limit', '1' );
169
+ update_post_meta( $new_coupon_id, 'date_expires', $expiry );
170
+ update_post_meta( $new_coupon_id, 'apply_before_tax', 'yes' );
171
+ update_post_meta( $new_coupon_id, 'free_shipping', 'no' );
172
+
173
+ }
174
+
175
+ return $coupon_code;
176
+ }
177
+
178
+ /**
179
+ * Unsubscribe the user from the mailing list.
180
+ */
181
+ function unsubscribe_cart_abandonment_emails() {
182
+
183
+ $unsubscribe = filter_input( INPUT_GET, 'unsubscribe', FILTER_VALIDATE_BOOLEAN );
184
+ $wcf_ac_token = filter_input( INPUT_GET, 'wcf_ac_token', FILTER_SANITIZE_STRING );
185
+ if ( $unsubscribe && $this->is_valid_token( $wcf_ac_token ) ) {
186
+ $token_data = $this->wcf_decode_token( $wcf_ac_token );
187
+ if ( isset( $token_data['wcf_session_id'] ) ) {
188
+ $session_id = $token_data['wcf_session_id'];
189
+
190
+ global $wpdb;
191
+ $cart_abandonment_table = $wpdb->prefix . CARTFLOWS_CA_CART_ABANDONMENT_TABLE;
192
+ $wpdb->update(
193
+ $cart_abandonment_table,
194
+ array( 'unsubscribed' => true ),
195
+ array( 'session_id' => $session_id )
196
+ );
197
+ wp_die( __( 'You have successfully unsubscribed from our email list.', 'cartflows-ca' ), __( 'Unsubscribed', 'cartflows-ca' ) );
198
+
199
+ }
200
+ }
201
+
202
+ }
203
+
204
+
205
+ /**
206
+ * Link JS to mce button.
207
+ *
208
+ * @param array $plugins mce pluggins.
209
+ * @return mixed
210
+ */
211
+ function wcf_filter_mce_plugin( $plugins ) {
212
+ $plugins['cartflows_ac'] = CARTFLOWS_CA_URL . 'admin/assets/js/admin-mce.js';
213
+ return $plugins;
214
+ }
215
+
216
+ /**
217
+ * Register button.
218
+ *
219
+ * @param array $buttons mce buttons.
220
+ * @return mixed
221
+ */
222
+ function wcf_filter_mce_button( $buttons ) {
223
+ array_push( $buttons, 'cartflows_ac' );
224
+ return $buttons;
225
+ }
226
+ /**
227
+ * Initialise all the constants
228
+ */
229
+ function define_cart_abandonment_constants() {
230
+ define( 'CARTFLOWS_CART_ABANDONMENT_TRACKING_DIR', CARTFLOWS_CA_DIR . 'modules/cart-abandonment/' );
231
+ define( 'CARTFLOWS_CART_ABANDONMENT_TRACKING_URL', CARTFLOWS_CA_URL . 'modules/cart-abandonment/' );
232
+ define( 'WCF_CART_ABANDONED_ORDER', 'abandoned' );
233
+ define( 'WCF_CART_COMPLETED_ORDER', 'completed' );
234
+ define( 'WCF_CART_LOST_ORDER', 'lost' );
235
+ define( 'WCF_CART_NORMAL_ORDER', 'normal' );
236
+ define( 'CARTFLOWS_ZAPIER_ACTION_AFTER_TIME', 1800 );
237
+
238
+ define( 'WCF_ACTION_ABANDONED_CARTS', 'abandoned_carts' );
239
+ define( 'WCF_ACTION_RECOVERED_CARTS', 'recovered_carts' );
240
+ define( 'WCF_ACTION_LOST_CARTS', 'lost_carts' );
241
+ define( 'WCF_ACTION_SETTINGS', 'settings' );
242
+ define( 'WCF_ACTION_REPORTS', 'reports' );
243
+
244
+ define( 'WCF_DEFAULT_CUT_OFF_TIME', 15 );
245
+ define( 'WCF_DEFAULT_COUPON_AMOUNT', 10 );
246
+
247
+ define( 'WCF_CA_DATETIME_FORMAT', 'Y-m-d H:i:s' );
248
+ }
249
+
250
+ /**
251
+ * Restore cart abandonemnt data on checkout page.
252
+ *
253
+ * @param array $fields checkout fields values.
254
+ * @return array field values
255
+ */
256
+ function restore_cart_abandonment_data( $fields = array() ) {
257
+ global $woocommerce;
258
+ $result = array();
259
+ // Restore only of user is not logged in.
260
+ $wcf_ac_token = filter_input( INPUT_GET, 'wcf_ac_token', FILTER_SANITIZE_STRING );
261
+ if ( $this->is_valid_token( $wcf_ac_token ) ) {
262
+
263
+ // Check if `wcf_restore_token` exists to restore cart data.
264
+ $token_data = $this->wcf_decode_token( $wcf_ac_token );
265
+
266
+ if ( is_array( $token_data ) && array_key_exists( 'wcf_session_id', $token_data ) ) {
267
+ $result = $this->get_checkout_details( $token_data['wcf_session_id'] );
268
+ if ( isset( $result ) && WCF_CART_ABANDONED_ORDER === $result->order_status || WCF_CART_LOST_ORDER === $result->order_status ) {
269
+ WC()->session->set( 'wcf_session_id', $token_data['wcf_session_id'] );
270
+ }
271
+ }
272
+
273
+ if ( $result ) {
274
+ $cart_content = unserialize( $result->cart_contents );
275
+
276
+ if ( $cart_content ) {
277
+ $woocommerce->cart->empty_cart();
278
+ foreach ( $cart_content as $cart_item ) {
279
+ $id = $cart_item['product_id'];
280
+ $qty = $cart_item['quantity'];
281
+
282
+ $cart_item_data = array();
283
+ if ( isset( $cart_item['cartflows_bump'] ) ) {
284
+ $cart_item_data['cartflows_bump'] = $cart_item['cartflows_bump'];
285
+ }
286
+
287
+ if ( isset( $cart_item['custom_price'] ) ) {
288
+ $cart_item_data['custom_price'] = $cart_item['custom_price'];
289
+ }
290
+
291
+ $woocommerce->cart->add_to_cart( $id, $qty, $cart_item['variation_id'], array(), $cart_item_data );
292
+ }
293
+ }
294
+ $other_fields = unserialize( $result->other_fields );
295
+
296
+ $parts = explode( ',', $other_fields['wcf_location'] );
297
+ if ( count( $parts ) > 1 ) {
298
+ $country = $parts[0];
299
+ $city = trim( $parts[1] );
300
+ } else {
301
+ $country = $parts[0];
302
+ $city = '';
303
+ }
304
+
305
+ foreach ( $other_fields as $key => $value ) {
306
+ $key = str_replace( 'wcf_', '', $key );
307
+ $_POST[ $key ] = sanitize_text_field( $value );
308
+ }
309
+ $_POST['billing_first_name'] = sanitize_text_field( $other_fields['wcf_first_name'] );
310
+ $_POST['billing_last_name'] = sanitize_text_field( $other_fields['wcf_last_name'] );
311
+ $_POST['billing_phone'] = sanitize_text_field( $other_fields['wcf_phone_number'] );
312
+ $_POST['billing_email'] = sanitize_email( $result->email );
313
+ $_POST['billing_city'] = sanitize_text_field( $city );
314
+ $_POST['billing_country'] = sanitize_text_field( $country );
315
+
316
+ }
317
+ }
318
+ return $fields;
319
+ }
320
+ /**
321
+ * Load cart abandonemnt tracking script.
322
+ *
323
+ * @return void
324
+ */
325
+ function cart_abandonment_tracking_script() {
326
+
327
+ global $post;
328
+ wp_enqueue_script(
329
+ 'cartflows-cart-abandonment-tracking',
330
+ CARTFLOWS_CART_ABANDONMENT_TRACKING_URL . 'assets/js/cart-abandonment-tracking.js',
331
+ array( 'jquery' ),
332
+ CARTFLOWS_CA_VER,
333
+ true
334
+ );
335
+
336
+ $vars = array(
337
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
338
+ '_nonce' => wp_create_nonce( 'cartflows_save_cart_abandonment_data' ),
339
+ '_gdpr_nonce' => wp_create_nonce( 'cartflows_skip_cart_tracking_gdpr' ),
340
+ '_post_id' => get_the_ID(),
341
+ '_show_gdpr_message' => ( wcf_ca()->utils->is_gdpr_enabled() && ! isset( $_COOKIE['wcf_ca_skip_track_data'] ) ),
342
+ '_gdpr_message' => get_option( 'wcf_ca_gdpr_message' ),
343
+ '_gdpr_nothanks_msg' => __( 'No Thanks', 'cartflows-ca' ),
344
+ 'enable_ca_tracking' => true,
345
+ );
346
+
347
+ wp_localize_script( 'cartflows-cart-abandonment-tracking', 'CartFlowsProCAVars', $vars );
348
+
349
+ }
350
+
351
+ /**
352
+ * Validate the token before use.
353
+ *
354
+ * @param string $token token form the url.
355
+ * @return bool
356
+ */
357
+ function is_valid_token( $token ) {
358
+ $is_valid = false;
359
+ $token_data = $this->wcf_decode_token( $token );
360
+ if ( is_array( $token_data ) && array_key_exists( 'wcf_session_id', $token_data ) ) {
361
+ $result = $this->get_checkout_details( $token_data['wcf_session_id'] );
362
+ if ( isset( $result ) ) {
363
+ $is_valid = true;
364
+ }
365
+ }
366
+ return $is_valid;
367
+ }
368
+
369
+ /**
370
+ * Execute Zapier webhook for further action inside Zapier.
371
+ *
372
+ * @since 1.0.0
373
+ */
374
+ function update_order_status() {
375
+
376
+ global $wpdb;
377
+ $cart_abandonment_table = $wpdb->prefix . CARTFLOWS_CA_CART_ABANDONMENT_TABLE;
378
+ $email_history_table = $wpdb->prefix . CARTFLOWS_CA_EMAIL_HISTORY_TABLE;
379
+ $minutes = wcf_ca()->utils->get_cart_abandonment_tracking_cut_off_time();
380
+
381
+ $wp_current_datetime = current_time( WCF_CA_DATETIME_FORMAT );
382
+ $abandoned_ids = $wpdb->get_results(
383
+ $wpdb->prepare('SELECT `session_id` FROM `' . $cart_abandonment_table . '` WHERE `order_status` = %s AND ADDDATE( `time`, INTERVAL %d MINUTE) <= %s', WCF_CART_NORMAL_ORDER, $minutes, $wp_current_datetime ), ARRAY_A // phpcs:ignore
384
+ );
385
+
386
+ foreach ( $abandoned_ids as $session_id ) {
387
+
388
+ if ( isset( $session_id['session_id'] ) ) {
389
+
390
+ $current_session_id = $session_id['session_id'];
391
+ $this->schedule_emails( $current_session_id );
392
+
393
+ $coupon_code = '';
394
+ $wcf_ca_coupon_code_status = get_option( 'wcf_ca_coupon_code_status' );
395
+
396
+ if ( 'on' === $wcf_ca_coupon_code_status ) {
397
+ $discount_type = get_option( 'wcf_ca_discount_type' );
398
+ $discount_type = $discount_type ? $discount_type : 'percent';
399
+ $amount = get_option( 'wcf_ca_coupon_amount' );
400
+ $amount = $amount ? $amount : WCF_DEFAULT_COUPON_AMOUNT;
401
+ $coupon_expiry_date = get_option( 'wcf_ca_coupon_expiry' );
402
+ $coupon_expiry_unit = get_option( 'wcf_ca_coupon_expiry_unit' );
403
+ $coupon_expiry_date = $coupon_expiry_date ? strtotime( $wp_current_datetime . ' +' . $coupon_expiry_date . ' ' . $coupon_expiry_unit ) : '';
404
+ $coupon_code = $this->generate_coupon_code( $discount_type, $amount, $coupon_expiry_date );
405
+ }
406
+
407
+ $wpdb->update(
408
+ $cart_abandonment_table,
409
+ array(
410
+ 'order_status' => WCF_CART_ABANDONED_ORDER,
411
+ 'coupon_code' => $coupon_code,
412
+ ),
413
+ array( 'session_id' => $current_session_id )
414
+ );
415
+
416
+ $this->trigger_zapier_webhook( $current_session_id, WCF_CART_ABANDONED_ORDER );
417
+ }
418
+ }
419
+
420
+ /**
421
+ * Send scheduled emails.
422
+ */
423
+ $this->send_emails_to_callback();
424
+
425
+ // Update order status to lost after campaign complete.
426
+ // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
427
+ $wpdb->query(
428
+ $wpdb->prepare(
429
+ "UPDATE $cart_abandonment_table as ca SET order_status = 'lost' WHERE ca.order_status = %s AND DATE(ca.time) <= DATE_SUB( %s , INTERVAL 30 DAY)
430
+ AND ( (SELECT count(*) FROM $email_history_table WHERE ca_session_id = ca.session_id ) =
431
+ (SELECT count(*) FROM $email_history_table WHERE ca_session_id = ca.session_id AND email_sent = 1) )",
432
+ WCF_CART_ABANDONED_ORDER,
433
+ $wp_current_datetime
434
+ )
435
+ );
436
+ // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
437
+ }
438
+
439
+ /**
440
+ * Send zapier webhook.
441
+ *
442
+ * @param string $session_id session id.
443
+ * @param string $order_status order status.
444
+ */
445
+ function trigger_zapier_webhook( $session_id, $order_status ) {
446
+
447
+ $checkout_details = $this->get_checkout_details( $session_id );
448
+
449
+ if ( $checkout_details && wcf_ca()->utils->is_zapier_trigger_enabled() ) {
450
+ $trigger_details = array();
451
+ $url = get_option( 'wcf_ca_zapier_cart_abandoned_webhook' );
452
+
453
+ $other_details = unserialize( $checkout_details->other_fields );
454
+ $trigger_details['first_name'] = $other_details['wcf_first_name'];
455
+ $trigger_details['last_name'] = $other_details['wcf_last_name'];
456
+ $trigger_details['email'] = $checkout_details->email;
457
+ $trigger_details['checkout_url'] = $this->get_checkout_url( $checkout_details->checkout_id, $checkout_details->session_id );
458
+ $trigger_details['product_names'] = $this->get_comma_separated_products( $checkout_details->cart_contents );
459
+ $trigger_details['coupon_code'] = $checkout_details->coupon_code;
460
+ $trigger_details['order_status'] = $order_status;
461
+ $trigger_details['cart_total'] = $checkout_details->cart_total;
462
+
463
+ $parameters = http_build_query( $trigger_details );
464
+ $args = array(
465
+ 'body' => $parameters,
466
+ 'timeout' => '5',
467
+ 'redirection' => '5',
468
+ 'httpversion' => '1.0',
469
+ 'blocking' => true,
470
+ 'headers' => array(),
471
+ 'cookies' => array(),
472
+ );
473
+ wp_remote_post( $url, $args );
474
+
475
+ }
476
+ }
477
+
478
+
479
+ /**
480
+ * Sanitize post array.
481
+ *
482
+ * @return array
483
+ */
484
+ function sanitize_post_data() {
485
+
486
+ $input_post_values = array(
487
+ 'wcf_billing_company' => array(
488
+ 'default' => '',
489
+ 'sanitize' => FILTER_SANITIZE_STRING,
490
+ ),
491
+ 'wcf_email' => array(
492
+ 'default' => '',
493
+ 'sanitize' => FILTER_SANITIZE_EMAIL,
494
+ ),
495
+ 'wcf_billing_address_1' => array(
496
+ 'default' => '',
497
+ 'sanitize' => FILTER_SANITIZE_STRING,
498
+ ),
499
+ 'wcf_billing_address_2' => array(
500
+ 'default' => '',
501
+ 'sanitize' => FILTER_SANITIZE_STRING,
502
+ ),
503
+ 'wcf_billing_state' => array(
504
+ 'default' => '',
505
+ 'sanitize' => FILTER_SANITIZE_STRING,
506
+ ),
507
+ 'wcf_billing_postcode' => array(
508
+ 'default' => '',
509
+ 'sanitize' => FILTER_SANITIZE_STRING,
510
+ ),
511
+ 'wcf_shipping_first_name' => array(
512
+ 'default' => '',
513
+ 'sanitize' => FILTER_SANITIZE_STRING,
514
+ ),
515
+ 'wcf_shipping_last_name' => array(
516
+ 'default' => '',
517
+ 'sanitize' => FILTER_SANITIZE_STRING,
518
+ ),
519
+ 'wcf_shipping_company' => array(
520
+ 'default' => '',
521
+ 'sanitize' => FILTER_SANITIZE_STRING,
522
+ ),
523
+ 'wcf_shipping_country' => array(
524
+ 'default' => '',
525
+ 'sanitize' => FILTER_SANITIZE_STRING,
526
+ ),
527
+ 'wcf_shipping_address_1' => array(
528
+ 'default' => '',
529
+ 'sanitize' => FILTER_SANITIZE_STRING,
530
+ ),
531
+ 'wcf_shipping_address_2' => array(
532
+ 'default' => '',
533
+ 'sanitize' => FILTER_SANITIZE_STRING,
534
+ ),
535
+ 'wcf_shipping_city' => array(
536
+ 'default' => '',
537
+ 'sanitize' => FILTER_SANITIZE_STRING,
538
+ ),
539
+ 'wcf_shipping_state' => array(
540
+ 'default' => '',
541
+ 'sanitize' => FILTER_SANITIZE_STRING,
542
+ ),
543
+ 'wcf_shipping_postcode' => array(
544
+ 'default' => '',
545
+ 'sanitize' => FILTER_SANITIZE_STRING,
546
+ ),
547
+ 'wcf_order_comments' => array(
548
+ 'default' => '',
549
+ 'sanitize' => FILTER_SANITIZE_STRING,
550
+ ),
551
+ 'wcf_name' => array(
552
+ 'default' => '',
553
+ 'sanitize' => FILTER_SANITIZE_STRING,
554
+ ),
555
+ 'wcf_surname' => array(
556
+ 'default' => '',
557
+ 'sanitize' => FILTER_SANITIZE_STRING,
558
+ ),
559
+ 'wcf_phone' => array(
560
+ 'default' => '',
561
+ 'sanitize' => FILTER_SANITIZE_STRING,
562
+ ),
563
+ 'wcf_country' => array(
564
+ 'default' => '',
565
+ 'sanitize' => FILTER_SANITIZE_STRING,
566
+ ),
567
+ 'wcf_city' => array(
568
+ 'default' => '',
569
+ 'sanitize' => FILTER_SANITIZE_STRING,
570
+ ),
571
+ 'wcf_post_id' => array(
572
+ 'default' => 0,
573
+ 'sanitize' => FILTER_SANITIZE_NUMBER_INT,
574
+ ),
575
+ );
576
+
577
+ $sanitized_post = array();
578
+ foreach ( $input_post_values as $key => $input_post_value ) {
579
+
580
+ if ( isset( $_POST[ $key ] ) ) {
581
+ $sanitized_post[ $key ] = filter_input( INPUT_POST, $key, $input_post_value['sanitize'] );
582
+ } else {
583
+ $sanitized_post[ $key ] = $input_post_value['default'];
584
+ }
585
+ }
586
+ return $sanitized_post;
587
+
588
+ }
589
+
590
+
591
+ /**
592
+ * Save cart abandonment tracking and schedule new event.
593
+ *
594
+ * @since 1.0.0
595
+ */
596
+ function save_cart_abandonment_data() {
597
+
598
+ check_ajax_referer( 'cartflows_save_cart_abandonment_data', 'security' );
599
+ $post_data = $this->sanitize_post_data();
600
+ if ( isset( $post_data['wcf_email'] ) ) {
601
+ $user_email = sanitize_email( $post_data['wcf_email'] );
602
+ global $wpdb;
603
+ $cart_abandonment_table = $wpdb->prefix . CARTFLOWS_CA_CART_ABANDONMENT_TABLE;
604
+
605
+ // Verify if email is already exists.
606
+ $session_id = WC()->session->get( 'wcf_session_id' );
607
+ $session_checkout_details = null;
608
+ if ( isset( $session_id ) ) {
609
+ $session_checkout_details = $this->get_checkout_details( $session_id );
610
+ } else {
611
+ $session_checkout_details = $this->get_checkout_details_by_email( $user_email );
612
+ if ( $session_checkout_details ) {
613
+ $session_id = $session_checkout_details->session_id;
614
+ WC()->session->set( 'wcf_session_id', $session_id );
615
+ } else {
616
+ $session_id = md5( uniqid( rand(), true ) );
617
+ }
618
+ }
619
+
620
+ $checkout_details = $this->prepare_abandonment_data( $post_data );
621
+
622
+ if ( isset( $session_checkout_details ) && WCF_CART_COMPLETED_ORDER === $session_checkout_details->order_status ) {
623
+ WC()->session->__unset( 'wcf_session_id' );
624
+ $session_id = md5( uniqid( rand(), true ) );
625
+ }
626
+
627
+ if ( ( ! is_null( $session_id ) ) && ! is_null( $session_checkout_details ) ) {
628
+
629
+ // Updating row in the Database where users Session id = same as prevously saved in Session.
630
+ $wpdb->update(
631
+ $cart_abandonment_table,
632
+ $checkout_details,
633
+ array( 'session_id' => $session_id )
634
+ );
635
+
636
+ } else {
637
+
638
+ $checkout_details['session_id'] = sanitize_text_field( $session_id );
639
+ // Inserting row into Database.
640
+ $wpdb->insert(
641
+ $cart_abandonment_table,
642
+ $checkout_details
643
+ );
644
+
645
+ // Storing session_id in WooCommerce session.
646
+ WC()->session->set( 'wcf_session_id', $session_id );
647
+
648
+ }
649
+
650
+ wp_send_json_success();
651
+ }
652
+ }
653
+
654
+
655
+ /**
656
+ * Prepare cart data to save for abandonment.
657
+ *
658
+ * @param array $post_data post data.
659
+ * @return array
660
+ */
661
+ function prepare_abandonment_data( $post_data = array() ) {
662
+
663
+ if ( function_exists( 'WC' ) ) {
664
+
665
+ // Retrieving cart total value and currency.
666
+ $cart_total = WC()->cart->total;
667
+
668
+ // Retrieving cart products and their quantities.
669
+ $products = WC()->cart->get_cart();
670
+ $current_time = current_time( WCF_CA_DATETIME_FORMAT );
671
+ $other_fields = array(
672
+ 'wcf_billing_company' => $post_data['wcf_billing_company'],
673
+ 'wcf_billing_address_1' => $post_data['wcf_billing_address_1'],
674
+ 'wcf_billing_address_2' => $post_data['wcf_billing_address_2'],
675
+ 'wcf_billing_state' => $post_data['wcf_billing_state'],
676
+ 'wcf_billing_postcode' => $post_data['wcf_billing_postcode'],
677
+ 'wcf_shipping_first_name' => $post_data['wcf_shipping_first_name'],
678
+ 'wcf_shipping_last_name' => $post_data['wcf_shipping_last_name'],
679
+ 'wcf_shipping_company' => $post_data['wcf_shipping_company'],
680
+ 'wcf_shipping_country' => $post_data['wcf_shipping_country'],
681
+ 'wcf_shipping_address_1' => $post_data['wcf_shipping_address_1'],
682
+ 'wcf_shipping_address_2' => $post_data['wcf_shipping_address_2'],
683
+ 'wcf_shipping_city' => $post_data['wcf_shipping_city'],
684
+ 'wcf_shipping_state' => $post_data['wcf_shipping_state'],
685
+ 'wcf_shipping_postcode' => $post_data['wcf_shipping_postcode'],
686
+ 'wcf_order_comments' => $post_data['wcf_order_comments'],
687
+ 'wcf_first_name' => $post_data['wcf_name'],
688
+ 'wcf_last_name' => $post_data['wcf_surname'],
689
+ 'wcf_phone_number' => $post_data['wcf_phone'],
690
+ 'wcf_location' => $post_data['wcf_country'] . ', ' . $post_data['wcf_city'],
691
+ );
692
+
693
+ $checkout_details = array(
694
+ 'email' => $post_data['wcf_email'],
695
+ 'cart_contents' => serialize( $products ),
696
+ 'cart_total' => sanitize_text_field( $cart_total ),
697
+ 'time' => sanitize_text_field( $current_time ),
698
+ 'other_fields' => serialize( $other_fields ),
699
+ 'checkout_id' => $post_data['wcf_post_id'],
700
+ );
701
+ }
702
+ return $checkout_details;
703
+ }
704
+
705
+ /**
706
+ * Deletes cart abandonment tracking and scheduled event.
707
+ *
708
+ * @param int $order_id Order ID.
709
+ * @since 1.0.0
710
+ */
711
+ function delete_cart_abandonment_data( $order_id ) {
712
+ global $wpdb;
713
+ $cart_abandonment_table = $wpdb->prefix . CARTFLOWS_CA_CART_ABANDONMENT_TABLE;
714
+
715
+ if ( isset( WC()->session ) ) {
716
+ $session_id = WC()->session->get( 'wcf_session_id' );
717
+
718
+ if ( isset( $session_id ) ) {
719
+ $checkout_details = $this->get_checkout_details( $session_id );
720
+
721
+ if ( $checkout_details && ( WCF_CART_ABANDONED_ORDER === $checkout_details->order_status || WCF_CART_LOST_ORDER === $checkout_details->order_status ) ) {
722
+
723
+ // Update order status.
724
+ $wpdb->update(
725
+ $cart_abandonment_table,
726
+ array(
727
+ 'order_status' => WCF_CART_COMPLETED_ORDER,
728
+ ),
729
+ array(
730
+ 'session_id' => $session_id,
731
+ )
732
+ );
733
+
734
+ $this->trigger_zapier_webhook( $session_id, WCF_CART_COMPLETED_ORDER );
735
+
736
+ $order = wc_get_order( $order_id );
737
+ $note = __( 'CartFlows says: This order was abandoned & subsequently recovered.', 'cartflows-ca' );
738
+ $order->add_order_note( $note );
739
+ $order->save();
740
+
741
+ } else {
742
+ // Normal checkout.
743
+
744
+ $billing_email = filter_input( INPUT_POST, 'billing_email', FILTER_SANITIZE_EMAIL );
745
+
746
+ if ( $billing_email ) {
747
+ $order_data = $this->get_captured_data_by_email( $billing_email );
748
+
749
+ if ( ! is_null( $order_data ) ) {
750
+ $existing_cart_contents = unserialize( $order_data->cart_contents );
751
+ $order_cart_contents = unserialize( $checkout_details->cart_contents );
752
+ $existing_cart_products = array_keys( (array) $existing_cart_contents );
753
+ $order_cart_products = array_keys( (array) $order_cart_contents );
754
+ if ( $this->check_if_similar_cart( $existing_cart_products, $order_cart_products ) ) {
755
+ $wpdb->update(
756
+ $cart_abandonment_table,
757
+ array(
758
+ 'order_status' => WCF_CART_COMPLETED_ORDER,
759
+ ),
760
+ array(
761
+ 'session_id' => $order_data->session_id,
762
+ )
763
+ );
764
+ }
765
+ }
766
+ }
767
+ $wpdb->delete( $cart_abandonment_table, array( 'session_id' => sanitize_key( $session_id ) ) );
768
+ }
769
+ }
770
+ WC()->session->__unset( 'wcf_session_id' );
771
+ }
772
+ }
773
+
774
+
775
+ /**
776
+ * Compare cart if similar products.
777
+ *
778
+ * @param array $cart_a cart_a.
779
+ * @param array $cart_b cart_b.
780
+ * @return bool
781
+ */
782
+ function check_if_similar_cart( $cart_a, $cart_b ) {
783
+ return (
784
+ is_array( $cart_a )
785
+ && is_array( $cart_b )
786
+ && count( $cart_a ) === count( $cart_b )
787
+ && array_diff( $cart_a, $cart_b ) === array_diff( $cart_b, $cart_a )
788
+ );
789
+ }
790
+
791
+
792
+ /**
793
+ * Get the checkout details for the user.
794
+ *
795
+ * @param string $wcf_session_id checkout page session id.
796
+ * @since 1.0.0
797
+ */
798
+ function get_checkout_details( $wcf_session_id ) {
799
+ global $wpdb;
800
+ $cart_abandonment_table = $wpdb->prefix . CARTFLOWS_CA_CART_ABANDONMENT_TABLE;
801
+ $result = $wpdb->get_row(
802
+ $wpdb->prepare('SELECT * FROM `' . $cart_abandonment_table . '` WHERE session_id = %s', $wcf_session_id ) // phpcs:ignore
803
+ );
804
+ return $result;
805
+ }
806
+
807
+ /**
808
+ * Get the checkout details for the user.
809
+ *
810
+ * @param string $email user email.
811
+ * @since 1.0.0
812
+ */
813
+ function get_checkout_details_by_email( $email ) {
814
+ global $wpdb;
815
+ $cart_abandonment_table = $wpdb->prefix . CARTFLOWS_CA_CART_ABANDONMENT_TABLE;
816
+ $result = $wpdb->get_row(
817
+ $wpdb->prepare('SELECT * FROM `' . $cart_abandonment_table . '` WHERE email = %s AND `order_status` IN ( %s, %s )', $email, WCF_CART_ABANDONED_ORDER, WCF_CART_NORMAL_ORDER ) // phpcs:ignore
818
+ );
819
+ return $result;
820
+ }
821
+
822
+
823
+ /**
824
+ * Get the checkout details for the user.
825
+ *
826
+ * @param string $value value.
827
+ * @since 1.0.0
828
+ */
829
+ function get_captured_data_by_email( $value ) {
830
+ global $wpdb;
831
+ $cart_abandonment_table = $wpdb->prefix . CARTFLOWS_CA_CART_ABANDONMENT_TABLE;
832
+ $result = $wpdb->get_row(
833
+ $wpdb->prepare(
834
+ 'SELECT * FROM `' . $cart_abandonment_table . '` WHERE email = %s AND `order_status` IN (%s, %s) ORDER BY `time` DESC LIMIT 1', $value, WCF_CART_ABANDONED_ORDER, WCF_CART_LOST_ORDER ) // phpcs:ignore
835
+ );
836
+ return $result;
837
+ }
838
+
839
+
840
+
841
+ /**
842
+ * Add submenu to admin menu.
843
+ *
844
+ * @since 1.1.5
845
+ */
846
+ function abandoned_cart_tracking_menu() {
847
+
848
+ $parent_slug = 'woocommerce';
849
+ $page_title = __( 'Cart Abandonment', 'cartflows-ca' );
850
+ $menu_title = __( 'Cart Abandonment', 'cartflows-ca' );
851
+ $capability = 'manage_options';
852
+ $menu_slug = WCF_CA_PAGE_NAME;
853
+ $callback = array( $this, 'render_abandoned_cart_tracking' );
854
+
855
+ add_submenu_page(
856
+ $parent_slug,
857
+ $page_title,
858
+ $menu_title,
859
+ $capability,
860
+ $menu_slug,
861
+ $callback
862
+ );
863
+ }
864
+
865
+ /**
866
+ * Render table view for cart abandonment tracking.
867
+ *
868
+ * @since 1.1.5
869
+ */
870
+ function render_abandoned_cart_tracking() {
871
+
872
+ $wcf_list_table = new Cartflows_Ca_Cart_Abandonment_Table();
873
+
874
+ if ( 'delete' === $wcf_list_table->current_action() ) {
875
+
876
+ $ids = array();
877
+ if ( isset( $_REQUEST['id'] ) && is_array( $_REQUEST['id'] ) ) {
878
+ $ids = array_map( 'intval', $_REQUEST['id'] );
879
+ }
880
+ $deleted_row_count = empty( $ids ) ? 1 : count( $ids );
881
+
882
+ $wcf_list_table->process_bulk_action();
883
+ $message = '<div class="notice notice-success is-dismissible" id="message"><p>' . sprintf( __( 'Items deleted: %d', 'cartflows-ca' ), $deleted_row_count ) . '</p></div>'; // phpcs:ignore
884
+ set_transient( 'wcf_ca_show_message', $message, 5 );
885
+ if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
886
+ wp_safe_redirect( $_SERVER['HTTP_REFERER'] );
887
+ }
888
+ } elseif ( 'unsubscribe' === $wcf_list_table->current_action() ) {
889
+
890
+ global $wpdb;
891
+ $cart_abandonment_table = $wpdb->prefix . CARTFLOWS_CA_CART_ABANDONMENT_TABLE;
892
+ $id = filter_input( INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT );
893
+
894
+ $wpdb->update(
895
+ $cart_abandonment_table,
896
+ array( 'unsubscribed' => true ),
897
+ array( 'id' => $id )
898
+ );
899
+
900
+ $message = '<div class="notice notice-success is-dismissible" id="message"><p>' . sprintf( __( 'User unsubscribed successfully!', 'cartflows-ca' ) ) . '</p></div>'; // phpcs:ignore
901
+ set_transient( 'wcf_ca_show_message', $message, 5 );
902
+ if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
903
+ wp_safe_redirect( $_SERVER['HTTP_REFERER'] );
904
+ }
905
+ }
906
+ ?>
907
+
908
+ <?php
909
+ include_once CARTFLOWS_CART_ABANDONMENT_TRACKING_DIR . 'includes/admin/cartflows-cart-abandonment-tabs.php';
910
+ ?>
911
+ <?php
912
+ }
913
+
914
+ /**
915
+ * Count abandoned carts
916
+ *
917
+ * @since 1.1.5
918
+ */
919
+ function abandoned_cart_count() {
920
+ global $wpdb;
921
+ $cart_abandonment_table_name = $wpdb->prefix . CARTFLOWS_CA_CART_ABANDONMENT_TABLE;
922
+
923
+ $query = $wpdb->prepare( "SELECT COUNT(`id`) FROM {$cart_abandonment_table_name} WHERE `order_status` = %s", WCF_CART_ABANDONED_ORDER ); // phpcs:ignore
924
+ $total_items = $wpdb->get_var( $query ); // phpcs:ignore
925
+ return $total_items;
926
+ }
927
+
928
+ /**
929
+ * Load analytics scripts.
930
+ */
931
+ function load_admin_cart_abandonment_script() {
932
+
933
+ $page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING );
934
+
935
+ if ( ! WCF_CA_PAGE_NAME === $page ) {
936
+ return;
937
+ }
938
+
939
+ // Styles.
940
+ wp_enqueue_style( 'cartflows-cart-abandonment-admin', CARTFLOWS_CA_URL . 'admin/assets/css/admin-cart-abandonment.css', array(), CARTFLOWS_CA_VER );
941
+
942
+ }
943
+
944
+
945
+ /**
946
+ * Render Cart abandonment display button beside title.
947
+ */
948
+ public function setup_cart_abandonment_button() {
949
+
950
+ if ( ! Cartflows_Admin::is_flow_edit_admin() ) {
951
+ return;
952
+ }
953
+
954
+ $reports_btn_markup = '<style>.wrap{ position:relative;}</style>';
955
+ $reports_btn_markup .= "<div class='wcf-reports-button-wrap'>";
956
+ $reports_btn_markup .= "<button class='wcf-cart-abandonment-reports-popup button button-secondary'>";
957
+ $reports_btn_markup .= esc_html( 'View Report', 'cartflows-ca' );
958
+ $reports_btn_markup .= '</button>';
959
+ $reports_btn_markup .= '</div>';
960
+
961
+ echo $reports_btn_markup;
962
+
963
+ }
964
+
965
+ /**
966
+ * Get start and end date for given interval.
967
+ *
968
+ * @param string $interval interval .
969
+ * @return array
970
+ */
971
+ function get_start_end_by_interval( $interval ) {
972
+
973
+ if ( 'today' === $interval ) {
974
+ $start_date = date( 'Y-m-d' );
975
+ $end_date = date( 'Y-m-d' );
976
+ } else {
977
+
978
+ $days = $interval;
979
+
980
+ $start_date = date( 'Y-m-d', strtotime( '-' . $days . ' days' ) );
981
+ $end_date = date( 'Y-m-d' );
982
+ }
983
+
984
+ return array(
985
+ 'start' => $start_date,
986
+ 'end' => $end_date,
987
+ );
988
+ }
989
+
990
+
991
+ /**
992
+ * Get Attributable revenue.
993
+ * Represents the revenue generated by this campaign.
994
+ *
995
+ * @param string $type abondened|completed.
996
+ * @param string $from_date from date.
997
+ * @param string $to_date to date.
998
+ */
999
+ function get_report_by_type( $type = WCF_CART_ABANDONED_ORDER, $from_date, $to_date ) {
1000
+ global $wpdb;
1001
+ $cart_abandonment_table = $wpdb->prefix . CARTFLOWS_CA_CART_ABANDONMENT_TABLE;
1002
+ $minutes = wcf_ca()->utils->get_cart_abandonment_tracking_cut_off_time();
1003
+ $attributable_revenue = $wpdb->get_row(
1004
+ $wpdb->prepare( "SELECT SUM(`cart_total`) as revenue, count('*') as no_of_orders FROM {$cart_abandonment_table} WHERE `order_status` = %s AND DATE(`time`) >= %s AND DATE(`time`) <= %s ", $type, $from_date, $to_date ), // phpcs:ignore
1005
+ ARRAY_A
1006
+ );
1007
+ return $attributable_revenue;
1008
+ }
1009
+
1010
+
1011
+ /**
1012
+ * Get checkout url.
1013
+ *
1014
+ * @param integer $post_id post id.
1015
+ * @param string $session_id session id.
1016
+ * @return string
1017
+ */
1018
+ function get_checkout_url( $post_id, $session_id ) {
1019
+
1020
+ $token = $this->wcf_generate_token( array( 'wcf_session_id' => $session_id ) );
1021
+ $checkout_url = get_permalink( $post_id ) . '?wcf_ac_token=' . $token;
1022
+ return esc_url( $checkout_url );
1023
+ }
1024
+
1025
+ /**
1026
+ * Geberate the token for the given data.
1027
+ *
1028
+ * @param array $data data.
1029
+ */
1030
+ function wcf_generate_token( $data ) {
1031
+ return urlencode( base64_encode( http_build_query( $data ) ) );
1032
+ }
1033
+
1034
+ /**
1035
+ * Decode and get the original contents.
1036
+ *
1037
+ * @param string $token token.
1038
+ */
1039
+ function wcf_decode_token( $token ) {
1040
+ $token = sanitize_text_field( $token );
1041
+ parse_str( base64_decode( urldecode( $token ) ), $token );
1042
+ return $token;
1043
+ }
1044
+
1045
+ /**
1046
+ * Render Cart abandonment tabs.
1047
+ *
1048
+ * @since 1.1.5
1049
+ */
1050
+ function wcf_display_tabs() {
1051
+
1052
+ $action = filter_input( INPUT_GET, 'action', FILTER_SANITIZE_STRING );
1053
+ $sub_action = filter_input( INPUT_GET, 'sub_action', FILTER_SANITIZE_STRING );
1054
+
1055
+ if ( ! $action ) {
1056
+ $action = WCF_ACTION_REPORTS;
1057
+ $active_settings = '';
1058
+ $active_reports = '';
1059
+ $active_email_templates = '';
1060
+ }
1061
+
1062
+ switch ( $action ) {
1063
+ case WCF_ACTION_SETTINGS:
1064
+ $active_settings = 'nav-tab-active';
1065
+ break;
1066
+ case WCF_ACTION_REPORTS:
1067
+ $active_reports = 'nav-tab-active';
1068
+ break;
1069
+ case WCF_ACTION_EMAIL_TEMPLATES:
1070
+ $active_email_templates = 'nav-tab-active';
1071
+ break;
1072
+ default:
1073
+ $active_reports = 'nav-tab-active';
1074
+ break;
1075
+ }
1076
+ // phpcs:disable
1077
+ ?>
1078
+
1079
+
1080
+ <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
1081
+
1082
+ <?php
1083
+ $url = add_query_arg( array(
1084
+ 'page' => WCF_CA_PAGE_NAME,
1085
+ 'action' => WCF_ACTION_REPORTS
1086
+ ), admin_url( '/admin.php' ) )
1087
+ ?>
1088
+ <a href="<?php echo $url; ?>"
1089
+ class="nav-tab
1090
+ <?php
1091
+ if ( isset( $active_reports ) ) {
1092
+ echo $active_reports;}
1093
+ ?>
1094
+ ">
1095
+ <?php _e( 'Report', 'cartflows-ca' ); ?>
1096
+ </a>
1097
+
1098
+ <?php
1099
+ $url = add_query_arg( array(
1100
+ 'page' => WCF_CA_PAGE_NAME,
1101
+ 'action' => WCF_ACTION_EMAIL_TEMPLATES
1102
+ ), admin_url( '/admin.php' ) )
1103
+ ?>
1104
+ <a href="<?php echo $url; ?>"
1105
+ class="nav-tab
1106
+ <?php
1107
+ if ( isset( $active_email_templates ) ) {
1108
+ echo $active_email_templates;}
1109
+ ?>
1110
+ ">
1111
+ <?php _e( 'Emails', 'cartflows-ca' ); ?>
1112
+ </a>
1113
+
1114
+ <?php
1115
+ $url = add_query_arg( array(
1116
+ 'page' => WCF_CA_PAGE_NAME,
1117
+ 'action' => WCF_ACTION_SETTINGS
1118
+ ), admin_url( '/admin.php' ) )
1119
+ ?>
1120
+ <a href="<?php echo $url; ?>"
1121
+ class="nav-tab
1122
+ <?php
1123
+ if ( isset( $active_settings ) ) {
1124
+ echo $active_settings;}
1125
+ ?>
1126
+ ">
1127
+ <?php _e( 'Settings', 'cartflows-ca' ); ?>
1128
+ </a>
1129
+
1130
+ </h2>
1131
+ <?php
1132
+ // phpcs:enable
1133
+ }
1134
+
1135
+ /**
1136
+ * Render Cart abandonment settings.
1137
+ *
1138
+ * @since 1.1.5
1139
+ */
1140
+ function wcf_display_settings() {
1141
+ ?>
1142
+
1143
+ <form method="post" action="options.php">
1144
+ <?php settings_fields( WCF_CA_SETTINGS_OPTION_GROUP ); ?>
1145
+ <?php do_settings_sections( WCF_CA_PAGE_NAME ); ?>
1146
+ <?php submit_button(); ?>
1147
+ </form>
1148
+
1149
+ <?php
1150
+ }
1151
+
1152
+ /**
1153
+ * Render Cart abandonment reports.
1154
+ *
1155
+ * @since 1.1.5
1156
+ */
1157
+ function wcf_display_reports() {
1158
+
1159
+ $filter = filter_input( INPUT_GET, 'filter', FILTER_SANITIZE_STRING );
1160
+ $filter_table = filter_input( INPUT_GET, 'filter_table', FILTER_SANITIZE_STRING );
1161
+
1162
+ if ( ! $filter ) {
1163
+ $filter = 'last_month';
1164
+ }
1165
+ if ( ! $filter_table ) {
1166
+ $filter_table = WCF_CART_ABANDONED_ORDER;
1167
+ }
1168
+
1169
+ $from_date = filter_input( INPUT_GET, 'from_date', FILTER_SANITIZE_STRING );
1170
+ $to_date = filter_input( INPUT_GET, 'to_date', FILTER_SANITIZE_STRING );
1171
+
1172
+ switch ( $filter ) {
1173
+
1174
+ case 'yesterday':
1175
+ $to_date = date( 'Y-m-d', strtotime( '-1 days' ) );
1176
+ $from_date = $to_date;
1177
+ break;
1178
+ case 'today':
1179
+ $to_date = date( 'Y-m-d' );
1180
+ $from_date = $to_date;
1181
+ break;
1182
+ case 'last_week':
1183
+ $from_date = date( 'Y-m-d', strtotime( '-7 days' ) );
1184
+ $to_date = date( 'Y-m-d' );
1185
+ break;
1186
+ case 'last_month':
1187
+ $from_date = date( 'Y-m-d', strtotime( '-1 months' ) );
1188
+ $to_date = date( 'Y-m-d' );
1189
+ break;
1190
+ case 'custom':
1191
+ $to_date = $to_date ? $to_date : date( 'Y-m-d' );
1192
+ $from_date = $from_date ? $from_date : $to_date;
1193
+ break;
1194
+
1195
+ }
1196
+
1197
+ $abandoned_report = $this->get_report_by_type( WCF_CART_ABANDONED_ORDER, $from_date, $to_date );
1198
+ $recovered_report = $this->get_report_by_type( WCF_CART_COMPLETED_ORDER, $from_date, $to_date );
1199
+ $lost_report = $this->get_report_by_type( WCF_CART_LOST_ORDER, $from_date, $to_date );
1200
+
1201
+ $wcf_list_table = new Cartflows_Ca_Cart_Abandonment_Table();
1202
+ $wcf_list_table->prepare_items( $filter_table, $from_date, $to_date );
1203
+
1204
+ $conversion_rate = 0;
1205
+ $total_orders = ( $recovered_report['no_of_orders'] + $abandoned_report['no_of_orders'] + $lost_report['no_of_orders'] );
1206
+ if ( $total_orders ) {
1207
+ $conversion_rate = ( $recovered_report['no_of_orders'] / $total_orders ) * 100;
1208
+ }
1209
+
1210
+ global $woocommerce;
1211
+ $conversion_rate = number_format_i18n( $conversion_rate, 2 );
1212
+ $currency_symbol = get_woocommerce_currency_symbol();
1213
+ include_once CARTFLOWS_CART_ABANDONMENT_TRACKING_DIR . 'includes/admin/cartflows-cart-abandonment-reports.php';
1214
+ }
1215
+
1216
+ /**
1217
+ * Check and show warning message if cart abandonment is disabled.
1218
+ */
1219
+ function wcf_show_warning_ca() {
1220
+ $settings_url = add_query_arg(
1221
+ array(
1222
+ 'page' => WCF_CA_PAGE_NAME,
1223
+ 'action' => WCF_ACTION_SETTINGS,
1224
+ ),
1225
+ admin_url( '/admin.php' )
1226
+ );
1227
+
1228
+ if ( ! wcf_ca()->utils->is_cart_abandonment_tracking_enabled() ) {
1229
+ ?>
1230
+ <div class="notice notice-warning is-dismissible">
1231
+ <p>
1232
+ <?php echo __('Looks like abandonment tracking is disabled! Please enable it from <a href=' . esc_url($settings_url) . '> <strong>settings</strong></a>.', 'cartflows-ca'); // phpcs:ignore
1233
+ ?>
1234
+ </p>
1235
+ </div>
1236
+ <?php
1237
+ }
1238
+ }
1239
+
1240
+ /**
1241
+ * Callback trigger event to send the emails.
1242
+ */
1243
+ function send_emails_to_callback() {
1244
+
1245
+ global $wpdb;
1246
+ $email_history_table = $wpdb->prefix . CARTFLOWS_CA_EMAIL_HISTORY_TABLE;
1247
+ $cart_abandonment_table = $wpdb->prefix . CARTFLOWS_CA_CART_ABANDONMENT_TABLE;
1248
+ $email_template_table = $wpdb->prefix . CARTFLOWS_CA_EMAIL_TEMPLATE_TABLE;
1249
+
1250
+ // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
1251
+ $emails_send_to = $wpdb->get_results(
1252
+
1253
+ $wpdb->prepare(
1254
+ 'SELECT *, EHT.id as email_history_id, ETT.id as email_template_id FROM ' . $email_history_table . ' as EHT
1255
+ INNER JOIN ' . $cart_abandonment_table . ' as CAT ON EHT.`ca_session_id` = CAT.`session_id`
1256
+ INNER JOIN ' . $email_template_table . ' as ETT ON ETT.`id` = EHT.`template_id`
1257
+ WHERE CAT.`order_status` = %s AND CAT.unsubscribed = 0 AND EHT.`email_sent` = 0 AND EHT.`scheduled_time` <= NOW()',
1258
+ WCF_CART_ABANDONED_ORDER
1259
+ )
1260
+ );
1261
+ // phpcs:enable WordPress.DB.PreparedSQL.NotPrepared
1262
+
1263
+ foreach ( $emails_send_to as $email_send_to ) {
1264
+ $email_result = $this->send_email_templates( $email_send_to );
1265
+ if ( $email_result ) {
1266
+ $wpdb->update(
1267
+ $email_history_table,
1268
+ array( 'email_sent' => true ),
1269
+ array( 'id' => $email_send_to->email_history_id )
1270
+ );
1271
+ }
1272
+ }
1273
+ }
1274
+
1275
+
1276
+ /**
1277
+ * Create a dummy object for the preview email.
1278
+ *
1279
+ * @return stdClass
1280
+ */
1281
+ public function create_dummy_session_for_preview_email() {
1282
+
1283
+ $email_data = new stdClass();
1284
+ $current_user = wp_get_current_user();
1285
+ $user_data = array(
1286
+ 'wcf_first_name' => $current_user->user_firstname,
1287
+ 'wcf_last_name' => $current_user->user_lastname,
1288
+ );
1289
+ $email_data->checkout_id = wc_get_page_id( 'checkout' );
1290
+ $email_data->session_id = 'dummy-session-id';
1291
+
1292
+ $email_send_to = filter_input( INPUT_POST, 'email_send_to', FILTER_SANITIZE_EMAIL );
1293
+ $email_data->email = $email_send_to ? $email_send_to : $current_user->user_email;
1294
+ $email_data->email_body = filter_input( INPUT_POST, 'email_body', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
1295
+ $email_data->email_subject = filter_input( INPUT_POST, 'email_subject', FILTER_SANITIZE_STRING );
1296
+ $email_data->email_body = html_entity_decode( $email_data->email_body );
1297
+
1298
+ $email_data->other_fields = serialize( $user_data );
1299
+ if ( ! WC()->cart->get_cart_contents_count() ) {
1300
+ $args = array(
1301
+ 'posts_per_page' => 1,
1302
+ 'orderby' => 'rand',
1303
+ 'post_type' => 'product',
1304
+ 'meta_query' => array(
1305
+ // Exclude out of stock products.
1306
+ array(
1307
+ 'key' => '_stock_status',
1308
+ 'value' => 'outofstock',
1309
+ 'compare' => 'NOT IN',
1310
+ ),
1311
+ ),
1312
+ 'tax_query' => array(
1313
+ array(
1314
+ 'taxonomy' => 'product_type',
1315
+ 'field' => 'slug',
1316
+ 'terms' => 'simple',
1317
+ ),
1318
+ ),
1319
+ );
1320
+
1321
+ $random_products = get_posts( $args );
1322
+ if ( ! empty( $random_products ) ) {
1323
+ $random_product = reset( $random_products );
1324
+ WC()->cart->add_to_cart( $random_product->ID );
1325
+ }
1326
+ }
1327
+ $email_data->cart_contents = serialize( WC()->cart->get_cart() );
1328
+ $email_data->time = current_time( WCF_CA_DATETIME_FORMAT );
1329
+ return $email_data;
1330
+ }
1331
+
1332
+ /**
1333
+ * Callback function to send email templates.
1334
+ *
1335
+ * @param array $email_data email data .
1336
+ * @param boolean $preview_email preview email.
1337
+ * @since 1.0.0
1338
+ */
1339
+ function send_email_templates( $email_data, $preview_email = false ) {
1340
+
1341
+ if ( $preview_email ) {
1342
+ $email_data = $this->create_dummy_session_for_preview_email();
1343
+ }
1344
+
1345
+ if ( filter_var( $email_data->email, FILTER_VALIDATE_EMAIL ) ) {
1346
+
1347
+ $checkout_url = $this->get_checkout_url( $email_data->checkout_id, $email_data->session_id );
1348
+ $other_fields = unserialize( $email_data->other_fields );
1349
+
1350
+ $from_email_name = get_option( 'wcf_ca_from_name' );
1351
+ $reply_name_preview = get_option( 'wcf_ca_from_email' );
1352
+ $from_email_preview = get_option( 'wcf_ca_reply_email' );
1353
+
1354
+ $user_first_name = ucfirst( $other_fields['wcf_first_name'] );
1355
+ $user_first_name = $user_first_name ? $user_first_name : 'there';
1356
+ $user_last_name = ucfirst( $other_fields['wcf_last_name'] );
1357
+ $user_full_name = trim( $user_first_name . ' ' . $user_last_name );
1358
+
1359
+ $subject_email_preview = stripslashes( $email_data->email_subject );
1360
+ $subject_email_preview = convert_smilies( $subject_email_preview );
1361
+ $subject_email_preview = str_replace( '{{customer.firstname}}', $user_first_name, $subject_email_preview );
1362
+ $body_email_preview = convert_smilies( $email_data->email_body );
1363
+ $body_email_preview = str_replace( '{{customer.firstname}}', $user_first_name, $body_email_preview );
1364
+ $body_email_preview = str_replace( '{{customer.lastname}}', $user_last_name, $body_email_preview );
1365
+ $body_email_preview = str_replace( '{{customer.fullname}}', $user_full_name, $body_email_preview );
1366
+
1367
+ if ( $preview_email ) {
1368
+ $coupon_code = 'DUMMY-COUPON';
1369
+ $checkout_url = $checkout_url . base64_encode( 'dummy-token-string' );
1370
+ } else {
1371
+ $email_instance = Cartflows_Ca_Email_Templates::get_instance();
1372
+ $override_global_coupon = $email_instance->get_email_template_meta_by_key( $email_data->email_template_id, 'override_global_coupon' );
1373
+ if ( $override_global_coupon->meta_value ) {
1374
+ $email_history = $email_instance->get_email_history_by_id( $email_data->email_history_id );
1375
+ $coupon_code = $email_history->coupon_code;
1376
+ } else {
1377
+ $coupon_code = $email_data->coupon_code;
1378
+ }
1379
+ }
1380
+
1381
+ $body_email_preview = str_replace( '{{cart.coupon_code}}', $coupon_code, $body_email_preview );
1382
+
1383
+ $current_time_stamp = $email_data->time;
1384
+ $body_email_preview = str_replace( '{{cart.abandoned_date}}', $current_time_stamp, $body_email_preview );
1385
+ $unsubscribe_element = '<a target="_blank" style="color: lightgray" href="' . $checkout_url . '&unsubscribe=true' . '"> Unsubscribe </a>';
1386
+ $body_email_preview = str_replace( '{{cart.unsubscribe}}', $unsubscribe_element, $body_email_preview );
1387
+ $body_email_preview = str_replace( '{{cart.checkout_url}}', $checkout_url, $body_email_preview );
1388
+ $host = parse_url( get_site_url() );
1389
+ $body_email_preview = str_replace( '{{site.url}}', $host['host'], $body_email_preview );
1390
+ $body_email_preview = str_replace( '{{cart.product.names}}', $this->get_comma_separated_products( $email_data->cart_contents ), $body_email_preview );
1391
+
1392
+ $admin_user = get_users(
1393
+ array(
1394
+ 'role' => 'Administrator',
1395
+ 'number' => 1,
1396
+ )
1397
+ );
1398
+ $admin_user = reset( $admin_user );
1399
+ $admin_first_name = $admin_user->user_firstname ? $admin_user->user_firstname : 'Admin';
1400
+ $body_email_preview = str_replace( '{{admin.firstname}}', $admin_first_name, $body_email_preview );
1401
+ $body_email_preview = str_replace( '{{admin.company}}', get_bloginfo( 'name' ), $body_email_preview );
1402
+
1403
+ $headers = 'From: ' . $from_email_name . ' <' . $from_email_preview . '>' . "\r\n";
1404
+ $headers .= 'Content-Type: text/html' . "\r\n";
1405
+ $headers .= 'Reply-To: ' . $reply_name_preview . ' ' . "\r\n";
1406
+ $var = $this->get_email_product_block( $email_data->cart_contents );
1407
+
1408
+ $body_email_preview = str_replace( '{{cart.product.table}}', $var, $body_email_preview );
1409
+ $mail_result = wp_mail( $email_data->email, $subject_email_preview, stripslashes( $body_email_preview ), $headers );
1410
+ if ( $mail_result ) {
1411
+ return true;
1412
+ } else {
1413
+ // Retry sending mail.
1414
+ $mail_result = wp_mail( $email_data->email, $subject_email_preview, stripslashes( $body_email_preview ), $headers );
1415
+ if ( ! $preview_email ) {
1416
+ return true;
1417
+ }
1418
+ return false;
1419
+ }
1420
+ } else {
1421
+ return false;
1422
+ }
1423
+
1424
+ }
1425
+
1426
+ /**
1427
+ * Generate comma separated products.
1428
+ *
1429
+ * @param object $cart_contents user cart details.
1430
+ */
1431
+ function get_comma_separated_products( $cart_contents ) {
1432
+ $cart_comma_string = '';
1433
+ if ( ! $cart_contents ) {
1434
+ return $cart_comma_string;
1435
+ }
1436
+ $cart_data = unserialize( $cart_contents );
1437
+
1438
+ $cart_length = count( $cart_data );
1439
+ $index = 0;
1440
+ foreach ( $cart_data as $key => $product ) {
1441
+
1442
+ $cart_comma_string = $cart_comma_string . $product['data']->get_title();
1443
+ if ( ( $cart_length - 2 ) === $index ) {
1444
+ $cart_comma_string = $cart_comma_string . ' & ';
1445
+ } elseif ( ( $cart_length - 1 ) !== $index ) {
1446
+ $cart_comma_string = $cart_comma_string . ', ';
1447
+ }
1448
+ $index++;
1449
+ }
1450
+ return $cart_comma_string;
1451
+
1452
+ }
1453
+
1454
+ /**
1455
+ * Generate the view for email product cart block.
1456
+ *
1457
+ * @param object $cart_contents user cart contents details.
1458
+ * @return string
1459
+ */
1460
+ function get_email_product_block( $cart_contents ) {
1461
+
1462
+ $cart_items = unserialize( $cart_contents );
1463
+ $currency_symbol = get_woocommerce_currency_symbol();
1464
+ $tr = '';
1465
+ $total = 0;
1466
+ foreach ( $cart_items as $cart_item ) {
1467
+
1468
+ $total = $total + $cart_item['line_subtotal'];
1469
+ $tr = $tr . '<tr style="color: #636363; border: 1px solid #e5e5e5;" align="center">
1470
+ <td style="color: #636363; border: 1px solid #e5e5e5; "><img class="demo_img" width="42" height="42" src=" ' . esc_url( get_the_post_thumbnail_url( $cart_item['product_id'] ) ) . ' "/></td>
1471
+ <td style="color: #636363; border: 1px solid #e5e5e5; ">' . $cart_item['data']->get_title() . '</td>
1472
+ <td style="color: #636363; border: 1px solid #e5e5e5; "> ' . $cart_item['quantity'] . ' </td>
1473
+ <td style="color: #636363; border: 1px solid #e5e5e5; ">' . $currency_symbol . $cart_item['line_total'] . '</td>
1474
+ <td style="color: #636363; border: 1px solid #e5e5e5; " >' . $currency_symbol . $cart_item['line_subtotal'] . '</td>
1475
+ </tr> ';
1476
+ }
1477
+
1478
+ return '<h3>' . __( 'Your Shopping Cart', 'cartflows-ca' ) . '</h3>
1479
+ <table align="left" cellpadding="20" cellspacing="0" style="float: none; border: 1px solid #e5e5e5;">
1480
+ <tr align="center">
1481
+ <th style="color: #636363; border: 1px solid #e5e5e5; ">' . __( 'Item', 'cartflows-ca' ) . '</th>
1482
+ <th style="color: #636363; border: 1px solid #e5e5e5; ">' . __( 'Name', 'cartflows-ca' ) . '</th>
1483
+ <th style="color: #636363; border: 1px solid #e5e5e5; ">' . __( 'Quantity', 'cartflows-ca' ) . '</th>
1484
+ <th style="color: #636363; border: 1px solid #e5e5e5; ">' . __( 'Price', 'cartflows-ca' ) . '</th>
1485
+ <th style="color: #636363; border: 1px solid #e5e5e5; ">' . __( 'Line Subtotal', 'cartflows-ca' ) . '</th>
1486
+ </tr> ' . $tr . '
1487
+ <tr align="center">
1488
+ <td colspan="4" style="color: #636363; border: 1px solid #e5e5e5; ">' . __( 'Cart Total', 'cartflows-ca' ) . '</td>
1489
+ <td style="color: #636363; border: 1px solid #e5e5e5; ">' . $currency_symbol . $total . '</td>
1490
+ </tr>
1491
+ </table>';
1492
+
1493
+ }
1494
+
1495
+ /**
1496
+ * Copied WC function for date parameter addition.
1497
+ *
1498
+ * @param string $customer_email customer email.
1499
+ * @param int $user_id user id.
1500
+ * @param int $product_id product id.
1501
+ * @param int $days days.
1502
+ * @return array|bool|mixed|void
1503
+ */
1504
+ function wcf_ca_wc_customer_bought_product( $customer_email, $user_id, $product_id, $days = 365 ) {
1505
+ global $wpdb;
1506
+
1507
+ $result = apply_filters( 'woocommerce_pre_customer_bought_product', null, $customer_email, $user_id, $product_id );
1508
+
1509
+ if ( null !== $result ) {
1510
+ return $result;
1511
+ }
1512
+
1513
+ $transient_name = 'wc_customer_bought_product_' . md5( $customer_email . $user_id );
1514
+ $transient_version = WC_Cache_Helper::get_transient_version( 'orders' );
1515
+ $transient_value = get_transient( $transient_name );
1516
+
1517
+ if ( isset( $transient_value['value'], $transient_value['version'] ) && $transient_value['version'] === $transient_version ) {
1518
+ $result = $transient_value['value'];
1519
+ } else {
1520
+ $customer_data = array( $user_id );
1521
+
1522
+ if ( $user_id ) {
1523
+ $user = get_user_by( 'id', $user_id );
1524
+
1525
+ if ( isset( $user->user_email ) ) {
1526
+ $customer_data[] = $user->user_email;
1527
+ }
1528
+ }
1529
+
1530
+ if ( is_email( $customer_email ) ) {
1531
+ $customer_data[] = $customer_email;
1532
+ }
1533
+
1534
+ $customer_data = array_map( 'esc_sql', array_filter( array_unique( $customer_data ) ) );
1535
+ $statuses = array_map( 'esc_sql', wc_get_is_paid_statuses() );
1536
+
1537
+ if ( count( $customer_data ) === 0 ) {
1538
+ return false;
1539
+ }
1540
+ // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
1541
+ $result = $wpdb->get_col(
1542
+ "
1543
+ SELECT im.meta_value FROM {$wpdb->posts} AS p
1544
+ INNER JOIN {$wpdb->postmeta} AS pm ON p.ID = pm.post_id
1545
+ INNER JOIN {$wpdb->prefix}woocommerce_order_items AS i ON p.ID = i.order_id
1546
+ INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS im ON i.order_item_id = im.order_item_id
1547
+ WHERE p.post_status IN ( 'wc-" . implode( "','wc-", $statuses ) . "' )
1548
+ AND pm.meta_key IN ( '_billing_email', '_customer_user' )
1549
+ AND im.meta_key IN ( '_product_id', '_variation_id' )
1550
+ AND im.meta_value != 0
1551
+ AND pm.meta_value IN ( '" . implode( "','", $customer_data ) . "'
1552
+ AND p.post_date > '" . date( 'Y-m-d', strtotime( '-' . $days . ' days' ) ) . "' )
1553
+ "
1554
+ );
1555
+ // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
1556
+ $result = array_map( 'absint', $result );
1557
+
1558
+ $transient_value = array(
1559
+ 'version' => $transient_version,
1560
+ 'value' => $result,
1561
+ );
1562
+
1563
+ set_transient( $transient_name, $transient_value, DAY_IN_SECONDS * 30 );
1564
+ }
1565
+ return in_array( absint( $product_id ), $result, true );
1566
+ }
1567
+ /**
1568
+ * Schedule events for the abadoned carts to send emails.
1569
+ *
1570
+ * @param integer $session_id user session id.
1571
+ */
1572
+ function schedule_emails( $session_id ) {
1573
+
1574
+ $checkout_details = $this->get_checkout_details( $session_id );
1575
+
1576
+ $user_exist = get_user_by( 'email', $checkout_details->email );
1577
+ // Don't schedule emails if products are already purchased.
1578
+ if ( $user_exist ) {
1579
+ $purchasing_products = unserialize( $checkout_details->cart_contents );
1580
+ $already_purchased = true;
1581
+ foreach ( $purchasing_products as $purchasing_product ) {
1582
+ if ( isset( $purchasing_product['product_id'] ) ) {
1583
+ $has_already_purchased = $this->wcf_ca_wc_customer_bought_product( $user_exist->user_email, $user_exist->ID, $purchasing_product['product_id'], 30 );
1584
+ if ( ! $has_already_purchased ) {
1585
+ $already_purchased = false;
1586
+ break;
1587
+ }
1588
+ }
1589
+ }
1590
+ if ( $already_purchased ) {
1591
+ return;
1592
+ }
1593
+ }
1594
+
1595
+ $email_tmpl = Cartflows_Ca_Email_Templates::get_instance();
1596
+ $templates = $email_tmpl->fetch_all_active_templates();
1597
+
1598
+ global $wpdb;
1599
+
1600
+ $email_history_table = $wpdb->prefix . CARTFLOWS_CA_EMAIL_HISTORY_TABLE;
1601
+
1602
+ foreach ( $templates as $template ) {
1603
+
1604
+ $timestamp_str = '+' . $template->frequency . ' ' . $template->frequency_unit . 'S';
1605
+ $scheduled_time = date( WCF_CA_DATETIME_FORMAT, strtotime( $checkout_details->time . $timestamp_str ) );
1606
+ $discount_type = $email_tmpl->get_email_template_meta_by_key( $template->id, 'discount_type' );
1607
+ $discount_type = isset( $discount_type->meta_value ) ? $discount_type->meta_value : '';
1608
+ $amount = $email_tmpl->get_email_template_meta_by_key( $template->id, 'coupon_amount' );
1609
+ $amount = isset( $amount->meta_value ) ? $amount->meta_value : '';
1610
+
1611
+ $coupon_expiry_date = $email_tmpl->get_email_template_meta_by_key( $template->id, 'coupon_expiry_date' );
1612
+ $coupon_expiry_unit = $email_tmpl->get_email_template_meta_by_key( $template->id, 'coupon_expiry_unit' );
1613
+ $coupon_expiry_date = isset( $coupon_expiry_date->meta_value ) ? $coupon_expiry_date->meta_value : '';
1614
+ $coupon_expiry_unit = isset( $coupon_expiry_unit->meta_value ) ? $coupon_expiry_unit->meta_value : 'hours';
1615
+
1616
+ $coupon_expiry_date = $coupon_expiry_date ? strtotime( $scheduled_time, strtotime( '+' . $coupon_expiry_date . ' ' . $coupon_expiry_unit ) ) : '';
1617
+
1618
+ $override_global_coupon = $email_tmpl->get_email_template_meta_by_key( $template->id, 'override_global_coupon' );
1619
+
1620
+ $new_coupon_code = '';
1621
+ if ( $override_global_coupon->meta_value ) {
1622
+ $new_coupon_code = $this->generate_coupon_code( $discount_type, $amount, $coupon_expiry_date );
1623
+ }
1624
+
1625
+ $wpdb->replace(
1626
+ $email_history_table,
1627
+ array(
1628
+ 'template_id' => $template->id,
1629
+ 'ca_session_id' => $checkout_details->session_id,
1630
+ 'coupon_code' => $new_coupon_code,
1631
+ 'scheduled_time' => $scheduled_time,
1632
+ )
1633
+ );
1634
+ }
1635
+ }
1636
+
1637
+ }
1638
+
1639
+ Cartflows_Ca_Cart_Abandonment::get_instance();
modules/cart-abandonment/class-cartflows-ca-email-templates-table.php ADDED
@@ -0,0 +1,258 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Cart Abandonment
4
+ *
5
+ * @package Woocommerce-Cart-Abandonment-Recovery
6
+ */
7
+
8
+ if ( ! class_exists( 'WP_List_Table' ) ) {
9
+ include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
10
+ }
11
+
12
+ /**
13
+ * Cart abandonment templates table class.
14
+ */
15
+ class Cartflows_Ca_Email_Templates_Table extends WP_List_Table {
16
+
17
+
18
+
19
+
20
+ /**
21
+ * URL of this page
22
+ *
23
+ * @var string
24
+ * @since 2.5.2
25
+ */
26
+ public $base_url;
27
+
28
+ /**
29
+ * Constructor function.
30
+ */
31
+ function __construct() {
32
+ global $status, $page;
33
+
34
+ parent::__construct(
35
+ array(
36
+ 'singular' => 'id',
37
+ 'plural' => 'ids',
38
+ )
39
+ );
40
+
41
+ $this->base_url = admin_url( 'admin.php?page=' . WCF_CA_PAGE_NAME . '&action=' . WCF_ACTION_EMAIL_TEMPLATES );
42
+
43
+ }
44
+
45
+ /**
46
+ * Default columns.
47
+ *
48
+ * @param object $item item.
49
+ * @param string $column_name column name.
50
+ */
51
+ function column_default( $item, $column_name ) {
52
+ return $item[ $column_name ];
53
+ }
54
+
55
+ /**
56
+ * This is how id column renders.
57
+ *
58
+ * @param object $item item.
59
+ * @return HTML
60
+ */
61
+ function column_template_name( $item ) {
62
+
63
+ $row_actions['edit'] = '<a href="' . wp_nonce_url(
64
+ add_query_arg(
65
+ array(
66
+ 'action' => WCF_ACTION_EMAIL_TEMPLATES,
67
+ 'sub_action' => WCF_SUB_ACTION_EDIT_EMAIL_TEMPLATES,
68
+ 'id' => $item['id'],
69
+ ),
70
+ $this->base_url
71
+ ),
72
+ WCF_EMAIL_TEMPLATES_NONCE
73
+ ) . '">' . __( 'Edit', 'cartflows-ca' ) . '</a>';
74
+
75
+ $row_actions['delete'] = '<a onclick="return confirm(\'Are you sure to delete this email template?\');" href="' . wp_nonce_url(
76
+ add_query_arg(
77
+ array(
78
+ 'action' => WCF_ACTION_EMAIL_TEMPLATES,
79
+ 'sub_action' => WCF_SUB_ACTION_DELETE_EMAIL_TEMPLATES,
80
+ 'id' => $item['id'],
81
+ ),
82
+ $this->base_url
83
+ ),
84
+ WCF_EMAIL_TEMPLATES_NONCE
85
+ ) . '">' . __( 'Delete', 'cartflows-ca' ) . '</a>';
86
+
87
+ $row_actions['clone'] = '<a href="' . wp_nonce_url(
88
+ add_query_arg(
89
+ array(
90
+ 'action' => WCF_ACTION_EMAIL_TEMPLATES,
91
+ 'sub_action' => WCF_SUB_ACTION_CLONE_EMAIL_TEMPLATES,
92
+ 'id' => $item['id'],
93
+ ),
94
+ $this->base_url
95
+ ),
96
+ WCF_EMAIL_TEMPLATES_NONCE
97
+ ) . '">' . __( 'Clone', 'cartflows-ca' ) . '</a>';
98
+
99
+ return sprintf( '%s %s', esc_html( $item['template_name'] ), $this->row_actions( $row_actions ) );
100
+ }
101
+
102
+ /**
103
+ * This is how checkbox column renders.
104
+ *
105
+ * @param object $item item.
106
+ * @return HTML
107
+ */
108
+ function column_cb( $item ) {
109
+ return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item['id'] ) );
110
+ }
111
+
112
+ /**
113
+ * [OPTIONAL] Return array of bult actions if has any
114
+ *
115
+ * @return array
116
+ */
117
+ function get_bulk_actions() {
118
+ $actions = array(
119
+ WCF_ACTION_EMAIL_TEMPLATES => __( 'Delete', 'cartflows-ca' ),
120
+ );
121
+ return $actions;
122
+ }
123
+
124
+ /**
125
+ * Whether the table has items to display or not
126
+ *
127
+ * @return bool
128
+ */
129
+ public function has_items() {
130
+ return ! empty( $this->items );
131
+ }
132
+
133
+ /**
134
+ * Fetch data from the database to render on view.
135
+ *
136
+ * @param string $cart_type abandoned|completed.
137
+ */
138
+ function prepare_items( $cart_type = WCF_CART_ABANDONED_ORDER ) {
139
+ global $wpdb;
140
+ $cart_abandonment_template_table_name = $wpdb->prefix . CARTFLOWS_CA_EMAIL_TEMPLATE_TABLE;
141
+
142
+ $per_page = 10;
143
+
144
+ $columns = $this->get_columns();
145
+ $hidden = array();
146
+ $sortable = $this->get_sortable_columns();
147
+
148
+ $this->_column_headers = array( $columns, $hidden, $sortable );
149
+
150
+ $this->process_bulk_action();
151
+
152
+ $total_items = $wpdb->get_var("SELECT COUNT(id) FROM $cart_abandonment_template_table_name"); // phpcs:ignore
153
+
154
+ $paged = filter_input( INPUT_GET, 'paged', FILTER_SANITIZE_NUMBER_INT );
155
+ $orderby = filter_input( INPUT_GET, 'orderby', FILTER_SANITIZE_STRING );
156
+ $order = filter_input( INPUT_GET, 'order', FILTER_SANITIZE_STRING );
157
+
158
+ $paged = $paged ? max( 0, $paged - 1 ) : 0;
159
+ $orderby = ( $orderby && in_array( $orderby, array_keys( $this->get_sortable_columns() ), true ) ) ? $orderby : 'id';
160
+ $order = ( $order && in_array( $order, array( 'asc', 'desc' ), true ) ) ? $order : 'desc';
161
+
162
+ // [REQUIRED] configure pagination
163
+ $this->set_pagination_args(
164
+ array(
165
+ 'total_items' => $total_items,
166
+ 'per_page' => $per_page,
167
+ 'total_pages' => ceil( $total_items / $per_page ),
168
+ )
169
+ );
170
+
171
+ $this->items = $wpdb->get_results(
172
+ $wpdb->prepare("SELECT * FROM $cart_abandonment_template_table_name ORDER BY $orderby $order LIMIT %d OFFSET %d", $per_page, $paged * $per_page), ARRAY_A); // phpcs:ignore
173
+ }
174
+
175
+ /**
176
+ * Table columns.
177
+ *
178
+ * @return array
179
+ */
180
+ function get_columns() {
181
+ $columns = array(
182
+ 'cb' => '<input type="checkbox" />',
183
+ 'template_name' => __( 'Template Name', 'cartflows-ca' ),
184
+ 'email_subject' => __( 'Email Subject', 'cartflows-ca' ),
185
+ 'trigger_time' => __( 'Trigger After', 'cartflows-ca' ),
186
+ 'is_activated' => __( 'Is Activated?', 'cartflows-ca' ),
187
+
188
+ );
189
+ return $columns;
190
+ }
191
+
192
+
193
+ /**
194
+ * Column name trigger_time.
195
+ *
196
+ * @param object $item item.
197
+ * @return string
198
+ */
199
+ function column_trigger_time( $item ) {
200
+
201
+ return sprintf(
202
+ '%d %s',
203
+ esc_html( $item['frequency'] ),
204
+ ' - ' . esc_html( $item['frequency_unit'] )
205
+ );
206
+ }
207
+
208
+ /**
209
+ * Column name trigger_time.
210
+ *
211
+ * @param object $item item.
212
+ * @return string
213
+ */
214
+ function column_is_activated( $item ) {
215
+
216
+ return sprintf( '%s', esc_html( $item['is_activated'] ? 'YES' : 'NO' ) );
217
+ }
218
+
219
+ /**
220
+ * Table sortable columns.
221
+ *
222
+ * @return array
223
+ */
224
+ public function get_sortable_columns() {
225
+ $sortable = array(
226
+ 'id' => array( 'id', true ),
227
+ 'template_name' => array( 'Template Name', true ),
228
+ 'email_subject' => array( 'Email Subject', true ),
229
+ );
230
+ return $sortable;
231
+ }
232
+
233
+ /**
234
+ * Processes bulk actions
235
+ */
236
+ function process_bulk_action() {
237
+ global $wpdb;
238
+ $table_name = $wpdb->prefix . CARTFLOWS_CA_EMAIL_TEMPLATE_TABLE;
239
+ $action = filter_input( INPUT_GET, 'sub_action', FILTER_SANITIZE_STRING );
240
+
241
+ if ( WCF_SUB_ACTION_DELETE_BULK_EMAIL_TEMPLATES === $action ) {
242
+ $ids = array();
243
+ if ( isset( $_REQUEST['id'] ) && is_array( $_REQUEST['id'] ) ) {
244
+ $ids = array_map( 'intval', $_REQUEST['id'] );
245
+ }
246
+ $ids = implode( ',', $ids );
247
+
248
+ if ( ! empty( $ids ) ) {
249
+ $wpdb->query("DELETE FROM $table_name WHERE id IN($ids)"); // phpcs:ignore
250
+ }
251
+ }
252
+
253
+ }
254
+
255
+
256
+ }
257
+
258
+
modules/cart-abandonment/class-cartflows-ca-email-templates.php ADDED
@@ -0,0 +1,983 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Cart Abandonment
4
+ *
5
+ * @package Woocommerce-Cart-Abandonment-Recovery
6
+ */
7
+
8
+ define( 'CARTFLOWS_EMAIL_TEMPLATE_DIR', CARTFLOWS_CA_DIR . 'modules/cart-abandonment/' );
9
+ define( 'CARTFLOWS_EMAIL_TEMPLATE_URL', CARTFLOWS_CA_URL . 'modules/cart-abandonment/' );
10
+
11
+ /**
12
+ * Class for analytics tracking.
13
+ */
14
+ class Cartflows_Ca_Email_Templates {
15
+
16
+
17
+
18
+ /**
19
+ * Member Variable
20
+ *
21
+ * @var object instance
22
+ */
23
+ private $wpdb;
24
+
25
+ /**
26
+ * Member Variable
27
+ *
28
+ * @var object instance
29
+ */
30
+ private static $instance;
31
+
32
+ /**
33
+ * Member Variable
34
+ *
35
+ * @var object instance
36
+ */
37
+ public $email_history_table;
38
+
39
+ /**
40
+ * Table name for email templates
41
+ *
42
+ * @var string
43
+ */
44
+ public $cart_abandonment_template_table_name;
45
+
46
+ /**
47
+ * Table name for email templates meta table
48
+ *
49
+ * @var string
50
+ */
51
+ public $email_templates_meta_table;
52
+
53
+ /**
54
+ * Initiator
55
+ */
56
+ public static function get_instance() {
57
+ if ( ! isset( self::$instance ) ) {
58
+ self::$instance = new self;
59
+ }
60
+ return self::$instance;
61
+ }
62
+
63
+ /**
64
+ * Constructor function that initializes required actions and hooks
65
+ */
66
+ public function __construct() {
67
+ $this->define_template_constants();
68
+ global $wpdb;
69
+ $this->cart_abandonment_template_table_name = $wpdb->prefix . CARTFLOWS_CA_EMAIL_TEMPLATE_TABLE;
70
+ $this->email_templates_meta_table = $wpdb->prefix . CARTFLOWS_CA_EMAIL_TEMPLATE_META_TABLE;
71
+ $this->email_history_table = $wpdb->prefix . CARTFLOWS_CA_EMAIL_HISTORY_TABLE;
72
+ $this->wpdb = $wpdb;
73
+
74
+ $this->fetch_all_active_templates();
75
+ add_action( 'admin_enqueue_scripts', __class__ . '::load_email_templates_script', 15 );
76
+ }
77
+
78
+
79
+ /**
80
+ * Add email template JS script.
81
+ */
82
+ public static function load_email_templates_script() {
83
+
84
+ $page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING );
85
+
86
+ if ( ! WCF_CA_PAGE_NAME === $page ) {
87
+ return;
88
+ }
89
+
90
+ wp_enqueue_script( 'jquery-ui-datepicker' );
91
+ wp_enqueue_style( 'jquery-ui-style' );
92
+
93
+ wp_enqueue_script(
94
+ 'cartflows-ca-email-tmpl-settings',
95
+ CARTFLOWS_CA_URL . 'admin/assets/js/admin-email-templates.js',
96
+ array( 'jquery' ),
97
+ CARTFLOWS_CA_VER
98
+ );
99
+
100
+ $vars = array(
101
+ 'settings_url' => add_query_arg(
102
+ array(
103
+ 'page' => WCF_CA_PAGE_NAME,
104
+ 'action' => WCF_ACTION_SETTINGS,
105
+ ),
106
+ admin_url( '/admin.php' )
107
+ ),
108
+ );
109
+
110
+ wp_localize_script( 'cartflows-ca-email-tmpl-settings', 'CAEmailTemplate', $vars );
111
+
112
+ $current_user = wp_get_current_user();
113
+ $vars = array(
114
+ 'email' => $current_user->user_email,
115
+ 'name' => $current_user->user_firstname,
116
+ 'surname' => $current_user->user_lastname,
117
+ 'phone' => get_user_meta( $current_user->ID, 'billing_phone', true ),
118
+ 'billing_company' => get_user_meta( $current_user->ID, 'billing_company', true ),
119
+ 'billing_address_1' => get_user_meta( $current_user->ID, 'billing_address_1', true ),
120
+ 'billing_address_2' => get_user_meta( $current_user->ID, 'billing_address_2', true ),
121
+ 'billing_state' => get_user_meta( $current_user->ID, 'billing_state', true ),
122
+ 'billing_postcode' => get_user_meta( $current_user->ID, 'billing_postcode', true ),
123
+ 'shipping_first_name' => $current_user->user_firstname,
124
+ 'shipping_last_name' => $current_user->user_lastname,
125
+ 'shipping_company' => get_user_meta( $current_user->ID, 'shipping_company', true ),
126
+ 'shipping_address_1' => get_user_meta( $current_user->ID, 'shipping_address_1', true ),
127
+ 'shipping_address_2' => get_user_meta( $current_user->ID, 'shipping_address_2', true ),
128
+ 'shipping_city' => get_user_meta( $current_user->ID, 'shipping_city', true ),
129
+ 'shipping_state' => get_user_meta( $current_user->ID, 'shipping_state', true ),
130
+ 'shipping_postcode' => get_user_meta( $current_user->ID, 'shipping_postcode', true ),
131
+ 'woo_currency_symbol' => get_woocommerce_currency_symbol(),
132
+ );
133
+ wp_localize_script( 'cartflows-ca-email-tmpl-settings', 'CartFlowsCADetails', $vars );
134
+
135
+ }
136
+
137
+ /**
138
+ * Initialise all the constants
139
+ */
140
+ public function define_template_constants() {
141
+ define( 'WCF_CA_PAGE_NAME', 'cartflows_abandoned_cart_tracking' );
142
+
143
+ define( 'WCF_CA_GENERAL_SETTINGS_SECTION', 'cartflows_cart_abandonment_settings_section' );
144
+ define( 'WCF_CA_EMAIL_SETTINGS_SECTION', 'cartflows_email_template_settings_section' );
145
+ define( 'WCF_CA_COUPON_CODE_SECTION', 'cartflows_coupon_code_settings_section' );
146
+ define( 'WCF_CA_ZAPIER_SETTINGS_SECTION', 'cartflows_zapier_settings_section' );
147
+ define( 'WCF_CA_GDPR_SETTINGS_SECTION', 'cartflows_gdpr_settings_section' );
148
+
149
+ define( 'WCF_CA_SETTINGS_OPTION_GROUP', 'cartflows-cart-abandonment-settings' );
150
+ define( 'WCF_CA_EMAIL_SETTINGS_OPTION_GROUP', 'cartflows-cart-abandonment-email-settings' );
151
+
152
+ define( 'WCF_ACTION_EMAIL_TEMPLATES', 'email_tmpl' );
153
+
154
+ define( 'WCF_SUB_ACTION_ADD_EMAIL_TEMPLATES', 'add_email_tmpl' );
155
+ define( 'WCF_SUB_ACTION_EDIT_EMAIL_TEMPLATES', 'edit_email_tmpl' );
156
+ define( 'WCF_SUB_ACTION_DELETE_EMAIL_TEMPLATES', 'delete_email_tmpl' );
157
+ define( 'WCF_SUB_ACTION_CLONE_EMAIL_TEMPLATES', 'clone_email_tmpl' );
158
+ define( 'WCF_SUB_ACTION_DELETE_BULK_EMAIL_TEMPLATES', 'delete_bulk_email_tmpl' );
159
+ define( 'WCF_SUB_ACTION_SAVE_EMAIL_TEMPLATES', 'save_email_template' );
160
+ define( 'WCF_SUB_ACTION_RESTORE_EMAIL_TEMPLATES', 'restore_default_email_tmpl' );
161
+
162
+ define( 'WCF_SUB_ACTION_CART_ABANDONMENT_SETTINGS', 'cart_abandonment_settings' );
163
+ define( 'WCF_SUB_ACTION_EMAIL_SETTINGS', 'email_settings' );
164
+ define( 'WCF_SUB_ACTION_COUPON_CODE_SETTINGS', 'coupon_code_settings' );
165
+ define( 'WCF_SUB_ACTION_ZAPIER_SETTINGS', 'zapier_settings' );
166
+
167
+ define( 'WCF_EMAIL_TEMPLATES_NONCE', 'email_template_nonce' );
168
+
169
+ }
170
+
171
+ /**
172
+ * Show success messages for email templates.
173
+ */
174
+ function show_messages() {
175
+
176
+ $wcf_ca_template_created = filter_input( INPUT_GET, 'wcf_ca_template_created', FILTER_SANITIZE_STRING );
177
+ $wcf_ca_template_cloned = filter_input( INPUT_GET, 'wcf_ca_template_cloned', FILTER_SANITIZE_STRING );
178
+ $wcf_ca_template_deleted = filter_input( INPUT_GET, 'wcf_ca_template_deleted', FILTER_SANITIZE_STRING );
179
+ $wcf_ca_template_updated = filter_input( INPUT_GET, 'wcf_ca_template_updated', FILTER_SANITIZE_STRING );
180
+ $wcf_ca_template_restored = filter_input( INPUT_GET, 'wcf_ca_template_restored', FILTER_SANITIZE_STRING );
181
+
182
+ ?>
183
+ <?php if ( 'YES' === $wcf_ca_template_created ) { ?>
184
+ <div id="message" class="notice notice-success is-dismissible">
185
+ <p>
186
+ <strong>
187
+ <?php _e( 'The Email Template has been successfully added.', 'cartflows-ca' ); ?>
188
+ </strong>
189
+ </p>
190
+ </div>
191
+ <?php } ?>
192
+
193
+ <?php if ( 'YES' === $wcf_ca_template_cloned ) { ?>
194
+ <div id="message" class="notice notice-success is-dismissible">
195
+ <p>
196
+ <strong>
197
+ <?php _e( 'The Email Template has been cloned successfully.', 'cartflows-ca' ); ?>
198
+ </strong>
199
+ </p>
200
+ </div>
201
+ <?php } ?>
202
+
203
+ <?php if ( 'YES' === $wcf_ca_template_deleted ) { ?>
204
+ <div id="message" class="notice notice-success is-dismissible">
205
+ <p>
206
+ <strong>
207
+ <?php _e( 'The Email Template has been successfully deleted.', 'cartflows-ca' ); ?>
208
+ </strong>
209
+ </p>
210
+ </div>
211
+ <?php } ?>
212
+ <?php if ( 'YES' === $wcf_ca_template_updated ) { ?>
213
+ <div id="message" class="notice notice-success is-dismissible">
214
+ <p>
215
+ <strong>
216
+ <?php _e( 'The Email Template has been successfully updated.', 'cartflows-ca' ); ?>
217
+ </strong>
218
+ </p>
219
+ </div>
220
+ <?php } ?>
221
+
222
+ <?php if ( 'YES' === $wcf_ca_template_restored ) { ?>
223
+ <div id="message" class="notice notice-success is-dismissible">
224
+ <p>
225
+ <strong>
226
+ <?php _e( 'Default Email Templates has been restored successfully.', 'cartflows-ca' ); ?>
227
+ </strong>
228
+ </p>
229
+ </div>
230
+ <?php } ?>
231
+ <?php
232
+
233
+ }
234
+
235
+ /**
236
+ * Delete bulk email templates.
237
+ */
238
+ function delete_bulk_templates() {
239
+ $wcf_template_list = new Cartflows_Ca_Email_Templates_Table();
240
+ $wcf_template_list->process_bulk_action();
241
+ $param = array(
242
+ 'page' => WCF_CA_PAGE_NAME,
243
+ 'action' => WCF_ACTION_EMAIL_TEMPLATES,
244
+ 'wcf_ca_template_deleted' => 'YES',
245
+ );
246
+ $redirect_url = add_query_arg( $param, admin_url( '/admin.php' ) );
247
+ wp_safe_redirect( $redirect_url );
248
+ }
249
+
250
+
251
+ /**
252
+ * Delete email templates.
253
+ */
254
+ function delete_single_template() {
255
+
256
+ $id = filter_input( INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT );
257
+ $wpnonce = filter_input( INPUT_GET, '_wpnonce', FILTER_SANITIZE_STRING );
258
+
259
+ if ( $id && $wpnonce && wp_verify_nonce( $wpnonce, WCF_EMAIL_TEMPLATES_NONCE ) ) {
260
+
261
+ $this->wpdb->delete(
262
+ $this->cart_abandonment_template_table_name,
263
+ array( 'id' => $id ),
264
+ '%d'
265
+ );
266
+ $param = array(
267
+ 'page' => WCF_CA_PAGE_NAME,
268
+ 'action' => WCF_ACTION_EMAIL_TEMPLATES,
269
+ 'wcf_ca_template_deleted' => 'YES',
270
+ );
271
+ $redirect_url = add_query_arg( $param, admin_url( '/admin.php' ) );
272
+ wp_safe_redirect( $redirect_url );
273
+
274
+ }
275
+ }
276
+
277
+ /**
278
+ * Delete email templates.
279
+ */
280
+ function clone_email_template() {
281
+
282
+ $id = filter_input( INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT );
283
+ $wpnonce = filter_input( INPUT_GET, '_wpnonce', FILTER_SANITIZE_STRING );
284
+
285
+ if ( $id && $wpnonce && wp_verify_nonce( $wpnonce, WCF_EMAIL_TEMPLATES_NONCE ) ) {
286
+
287
+ $email_template = $this->get_template_by_id( $id );
288
+
289
+ $this->wpdb->insert(
290
+ $this->cart_abandonment_template_table_name,
291
+ array(
292
+ 'template_name' => sanitize_text_field( $email_template->template_name ),
293
+ 'email_subject' => sanitize_text_field( $email_template->email_subject ),
294
+ 'email_body' => $email_template->email_body,
295
+ 'frequency' => intval( sanitize_text_field( $email_template->frequency ) ),
296
+ 'frequency_unit' => sanitize_text_field( $email_template->frequency_unit ),
297
+
298
+ ),
299
+ array( '%s', '%s', '%s', '%d', '%s' )
300
+ );
301
+
302
+ $email_template_id = $this->wpdb->insert_id;
303
+ $meta_data = array(
304
+ 'override_global_coupon' => false,
305
+ 'discount_type' => 'percent',
306
+ 'coupon_amount' => 10,
307
+ 'coupon_expiry_date' => '',
308
+ 'coupon_expiry_unit' => 'hours',
309
+ );
310
+
311
+ foreach ( $meta_data as $mera_key => $meta_value ) {
312
+ $this->add_email_template_meta( $email_template_id, $mera_key, $meta_value );
313
+ }
314
+
315
+ $param = array(
316
+ 'page' => WCF_CA_PAGE_NAME,
317
+ 'action' => WCF_ACTION_EMAIL_TEMPLATES,
318
+ 'wcf_ca_template_cloned' => 'YES',
319
+ );
320
+ $redirect_url = add_query_arg( $param, admin_url( '/admin.php' ) );
321
+ wp_safe_redirect( $redirect_url );
322
+
323
+ }
324
+ }
325
+
326
+ /**
327
+ * Get email template by id.
328
+ *
329
+ * @param int $email_tmpl_id template id.
330
+ */
331
+ function get_email_template_by_id( $email_tmpl_id ) {
332
+
333
+ $query = 'SELECT * FROM ' . $this->cart_abandonment_template_table_name . ' WHERE id = %d ';
334
+ return $this->wpdb->get_row($this->wpdb->prepare($query, $email_tmpl_id)); // phpcs:ignore
335
+
336
+ }
337
+
338
+ /**
339
+ * Render email template add/edit form.
340
+ *
341
+ * @param string $sub_action sub_action.
342
+ */
343
+ function render_email_template_form( $sub_action = WCF_SUB_ACTION_ADD_EMAIL_TEMPLATES ) {
344
+
345
+ $id = filter_input( INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT );
346
+
347
+ if ( $id ) {
348
+ $results = $this->get_email_template_by_id( $id );
349
+ }
350
+
351
+ ?>
352
+
353
+ <div id="content">
354
+
355
+ <?php
356
+ $param = array(
357
+ 'page' => WCF_CA_PAGE_NAME,
358
+ 'action' => WCF_ACTION_EMAIL_TEMPLATES,
359
+ 'sub_action' => WCF_SUB_ACTION_SAVE_EMAIL_TEMPLATES,
360
+ );
361
+ $save_template_url = esc_url( add_query_arg( $param, admin_url( '/admin.php' ) ) );
362
+ ?>
363
+
364
+ <form method="post" action="<?php echo $save_template_url; ?>" id="wcf_settings">
365
+ <input type="hidden" name="sub_action" value="<?php echo $sub_action; ?>"/>
366
+ <?php
367
+ $id_by = '';
368
+ if ( isset( $id ) ) {
369
+ $id_by = $id;
370
+ }
371
+ ?>
372
+ <input type="hidden" name="id" value="<?php echo $id_by; ?>"/>
373
+ <?php
374
+
375
+ $button_sub_action = 'save';
376
+ $display_message = 'Add New Email Template:';
377
+
378
+ if ( WCF_SUB_ACTION_EDIT_EMAIL_TEMPLATES === $sub_action ) {
379
+ $button_sub_action = 'update';
380
+ $display_message = 'Edit Email Template:';
381
+ }
382
+ print'<input type="hidden" name="wcf_settings_frm" value="' . $button_sub_action . '">';
383
+ ?>
384
+ <div id="poststuff">
385
+ <div> <!-- <div class="postbox" > -->
386
+ <h3><?php _e($display_message, 'cartflows-ca'); // phpcs:ignore ?></h3>
387
+ <hr/>
388
+ <div>
389
+ <table class="form-table" id="addedit_template">
390
+ <tr>
391
+ <th>
392
+ <label for="wcf_email_subject"><b><?php _e( 'Activate Template now?', 'cartflows-ca' ); ?></b></label>
393
+ </th>
394
+ <td>
395
+ <?php
396
+ $is_activated = '';
397
+ $active_status = 0;
398
+ if ( WCF_SUB_ACTION_EDIT_EMAIL_TEMPLATES === $sub_action && $results && isset( $results->is_activated ) ) {
399
+ $active_status = stripslashes( $results->is_activated );
400
+ $is_activated = $active_status ? 'on' : 'off';
401
+
402
+ }
403
+ print'<button type="button" class="wcf-ca-switch wcf-toggle-template-status" wcf-template-id="1" wcf-ca-template-switch="' . $is_activated . '"> ' . $is_activated . ' </button>';
404
+ print'<input type="hidden" name="wcf_activate_email_template" id="wcf_activate_email_template" value="' . $active_status . '" />';
405
+ ?>
406
+
407
+ </td>
408
+ </tr>
409
+
410
+ <tr>
411
+ <th>
412
+ <label for="wcf_template_name"><b><?php _e( 'Template Name:', 'cartflows-ca' ); ?></b></label>
413
+ </th>
414
+ <td>
415
+ <?php
416
+ $template_name = '';
417
+ if ( WCF_SUB_ACTION_EDIT_EMAIL_TEMPLATES === $sub_action && $results && isset( $results->template_name ) ) {
418
+ $template_name = $results->template_name;
419
+ }
420
+ print'<input type="text" name="wcf_template_name" id="wcf_template_name" class="wcf-ca-trigger-input" value="' . $template_name . '">';
421
+ ?>
422
+ </td>
423
+ </tr>
424
+
425
+ <tr>
426
+ <th>
427
+ <label for="wcf_email_subject"><b><?php _e( 'Email Subject:', 'cartflows-ca' ); ?></b></label>
428
+ </th>
429
+ <td>
430
+ <?php
431
+ $subject_edit = '';
432
+ if ( WCF_SUB_ACTION_EDIT_EMAIL_TEMPLATES === $sub_action && $results && isset( $results->email_subject ) ) {
433
+ $subject_edit = stripslashes( $results->email_subject );
434
+ }
435
+ print'<input type="text" name="wcf_email_subject" id="wcf_email_subject" class="wcf-ca-trigger-input" value="' . $subject_edit . '">';
436
+ ?>
437
+ </td>
438
+ </tr>
439
+
440
+ <tr>
441
+ <th>
442
+ <label for="wcf_email_body"><b><?php _e( 'Email Body:', 'cartflows-ca' ); ?></b></label>
443
+ </th>
444
+ <td>
445
+ <?php
446
+ $initial_data = '';
447
+ if ( WCF_SUB_ACTION_EDIT_EMAIL_TEMPLATES === $sub_action && $results && isset( $results->email_body ) ) {
448
+ $initial_data = stripslashes( $results->email_body );
449
+ }
450
+
451
+ wp_editor(
452
+ $initial_data,
453
+ 'wcf_email_body',
454
+ array(
455
+ 'media_buttons' => true,
456
+ 'textarea_rows' => 15,
457
+ 'tabindex' => 4,
458
+ 'tinymce' => array(
459
+ 'theme_advanced_buttons1' => 'bold,italic,underline,|,bullist,numlist,blockquote,|,link,unlink,|,spellchecker,fullscreen,|,formatselect,styleselect',
460
+ ),
461
+ )
462
+ );
463
+
464
+ ?>
465
+ <?php echo stripslashes( get_option( 'wcf_email_body' ) ); ?>
466
+ </td>
467
+ </tr>
468
+
469
+ <tr>
470
+ <th>
471
+ <label for="wcf_override_global_coupon"><b><?php _e( 'Create Coupon', 'cartflows-ca' ); ?></b></label>
472
+ </th>
473
+ <td>
474
+ <?php
475
+
476
+ $wcf_override_global_coupon = '';
477
+ if ( WCF_SUB_ACTION_EDIT_EMAIL_TEMPLATES === $sub_action && $results ) {
478
+ $wcf_override_global_coupon = $this->get_email_template_meta_by_key( $results->id, 'override_global_coupon' );
479
+ if ( isset( $wcf_override_global_coupon->meta_value ) ) {
480
+ $wcf_override_global_coupon = $wcf_override_global_coupon->meta_value ? 'checked' : '';
481
+ }
482
+ }
483
+
484
+ print'<input ' . $wcf_override_global_coupon . ' id="wcf_override_global_coupon" name="wcf_override_global_coupon" type="checkbox" value="" /><label for="wcf_override_global_coupon"> Allows you to send new coupon only for this template. </label>';
485
+ ?>
486
+ </td>
487
+ </tr>
488
+
489
+ <tr>
490
+ <th>
491
+ <label for="wcf_email_discount_type"><b><?php _e( 'Discount Type', 'cartflows-ca' ); ?></b></label>
492
+ </th>
493
+ <td>
494
+ <?php
495
+
496
+ $wcf_email_discount_type = 'percent';
497
+ if ( WCF_SUB_ACTION_EDIT_EMAIL_TEMPLATES === $sub_action && $results ) {
498
+ $wcf_email_discount_type = $this->get_email_template_meta_by_key( $results->id, 'discount_type' );
499
+ if ( isset( $wcf_email_discount_type->meta_value ) ) {
500
+ $wcf_email_discount_type = $wcf_email_discount_type->meta_value;
501
+ }
502
+ }
503
+
504
+ $dropdown_options = array(
505
+ 'percent' => 'Percentage discount',
506
+ 'fixed_cart' => 'Fixed cart discount',
507
+ );
508
+
509
+ echo '<select id="wcf_email_discount_type" name="wcf_email_discount_type">';
510
+ foreach ( $dropdown_options as $key => $value ) {
511
+ $is_selected = $key === $wcf_email_discount_type ? 'selected' : '';
512
+ echo '<option ' . $is_selected . ' value=' . $key . '>' . $value . '</option>';
513
+
514
+ }
515
+ echo '</select>';
516
+
517
+ ?>
518
+ </td>
519
+ </tr>
520
+
521
+ <tr>
522
+ <th>
523
+ <label for="wcf_email_discount_amount"><b><?php _e( 'Coupon Amount', 'cartflows-ca' ); ?></b></label>
524
+ </th>
525
+ <td>
526
+ <?php
527
+ $wcf_email_discount_amount = 10;
528
+ if ( WCF_SUB_ACTION_EDIT_EMAIL_TEMPLATES === $sub_action && $results ) {
529
+ $wcf_email_discount_amount = $this->get_email_template_meta_by_key( $results->id, 'coupon_amount' );
530
+ if ( isset( $wcf_email_discount_amount->meta_value ) ) {
531
+ $wcf_email_discount_amount = $wcf_email_discount_amount->meta_value;
532
+ }
533
+ }
534
+ print'<input class="wcf-ca-trigger-input wcf-ca-email-inputs" type="number" id="wcf_email_discount_amount" name="wcf_email_discount_amount" value="' . $wcf_email_discount_amount . '">';
535
+ ?>
536
+ </td>
537
+ </tr>
538
+
539
+ <tr>
540
+ <th>
541
+ <label for="wcf_email_coupon_expiry_date"><b><?php _e( 'Coupon expiry date', 'cartflows-ca' ); ?></b></label>
542
+ </th>
543
+ <td>
544
+ <?php
545
+ $wcf_email_coupon_expiry_date = 0;
546
+ $coupon_expiry_unit = 'hours';
547
+
548
+ if ( WCF_SUB_ACTION_EDIT_EMAIL_TEMPLATES === $sub_action && $results ) {
549
+ $wcf_email_coupon_expiry_date = $this->get_email_template_meta_by_key( $results->id, 'coupon_expiry_date' );
550
+ $wcf_email_coupon_expiry_unit = $this->get_email_template_meta_by_key( $results->id, 'coupon_expiry_unit' );
551
+
552
+ if ( isset( $wcf_email_coupon_expiry_date->meta_value ) ) {
553
+ $wcf_email_coupon_expiry_date = $wcf_email_coupon_expiry_date->meta_value;
554
+ }
555
+ if ( isset( $wcf_email_coupon_expiry_unit->meta_value ) ) {
556
+ $coupon_expiry_unit = $wcf_email_coupon_expiry_unit->meta_value;
557
+ }
558
+ }
559
+ print'<input type="number" class="wcf-ca-trigger-input wcf-ca-coupon-inputs" id="wcf_email_coupon_expiry_date" name="wcf_email_coupon_expiry_date" value="' . intval( $wcf_email_coupon_expiry_date ) . '" autocomplete="off" />';
560
+ $items = array(
561
+ 'hours' => 'Hour(s)',
562
+ 'days' => 'Day(s)',
563
+ );
564
+ echo "<select id='wcf_coupon_expiry_unit' name='wcf_coupon_expiry_unit'>";
565
+ foreach ( $items as $key => $item ) {
566
+ $selected = ( $coupon_expiry_unit === $key ) ? 'selected="selected"' : '';
567
+ echo "<option value='$key' $selected>$item</option>";
568
+ }
569
+ echo '</select>';
570
+
571
+ echo " <span class='description'> Enter zero (0) to restrict coupon from expiring </span>"
572
+ ?>
573
+ </td>
574
+ </tr>
575
+
576
+ <tr>
577
+ <th>
578
+ <label for="wcf_email_subject"><b><?php _e( 'Send This Email', 'cartflows-ca' ); ?></b></label>
579
+ </th>
580
+ <td>
581
+ <?php
582
+ $frequency_edit = '';
583
+ if ( WCF_SUB_ACTION_EDIT_EMAIL_TEMPLATES === $sub_action && $results && isset( $results->frequency ) ) {
584
+ $frequency_edit = $results->frequency;
585
+ }
586
+ print'<input style="width:15%" type="number" name="wcf_email_frequency" id="wcf_email_frequency" class="wcf-ca-trigger-input" value="' . $frequency_edit . '">';
587
+ ?>
588
+
589
+ <select name="wcf_email_frequency_unit" id="wcf_email_frequency_unit">
590
+ <?php
591
+ $frequency_unit = '';
592
+ if ( WCF_SUB_ACTION_EDIT_EMAIL_TEMPLATES === $sub_action && $results && isset( $results->frequency_unit ) ) {
593
+ $frequency_unit = $results->frequency_unit;
594
+ }
595
+ $days_or_hours = array(
596
+ 'MINUTE' => 'Minute(s)',
597
+ 'HOUR' => 'Hour(s)',
598
+ 'DAY' => 'Day(s)',
599
+ );
600
+ foreach ( $days_or_hours as $k => $v ) {
601
+ printf(
602
+ "<option %s value='%s'>%s</option>\n",
603
+ selected( $k, $frequency_unit, false ),
604
+ esc_attr( $k ),
605
+ $v
606
+ );
607
+ }
608
+ ?>
609
+ </select>
610
+ <span class="description">
611
+ <?php _e( 'after cart is abandoned.', 'cartflows-ca' ); ?>
612
+ </span>
613
+
614
+
615
+ </td>
616
+ </tr>
617
+
618
+ <tr>
619
+ <?php $current_user = wp_get_current_user(); ?>
620
+ <th>
621
+ <label for="wcf_email_preview"><b><?php _e( 'Send Test Email To:', 'cartflows-ca' ); ?></b></label>
622
+ </th>
623
+ <td>
624
+ <input class="wcf-ca-trigger-input" type="text" id="wcf_send_test_email" name="send_test_email" value="<?php echo $current_user->user_email; ?>" class="wcf-ca-trigger-input">
625
+ <input class="button" type="button" value="Send a test email" id="wcf_preview_email"/> <br/>
626
+
627
+ <label id="mail_response_msg"> </label>
628
+ </td>
629
+ </tr>
630
+
631
+ </table>
632
+ </div>
633
+ </div>
634
+ </div>
635
+ <?php wp_nonce_field( WCF_EMAIL_TEMPLATES_NONCE, '_wpnonce' ); ?>
636
+ <p class="submit">
637
+ <?php
638
+ $button_value = 'Save Changes';
639
+ if ( WCF_SUB_ACTION_EDIT_EMAIL_TEMPLATES === $sub_action ) {
640
+ $button_value = 'Update Changes';
641
+ }
642
+ ?>
643
+ <input type="submit" name="Submit" class="button-primary" value="<?php echo $button_value; ?>"/>
644
+ </p>
645
+ </form>
646
+ </div>
647
+ <?php
648
+
649
+ }
650
+
651
+
652
+ /**
653
+ * Sanitize email post data.
654
+ *
655
+ * @return array
656
+ */
657
+ function sanitize_email_post_data() {
658
+
659
+ $input_post_values = array(
660
+ 'wcf_email_subject' => array(
661
+ 'default' => '',
662
+ 'sanitize' => FILTER_SANITIZE_STRING,
663
+ ),
664
+ 'wcf_email_body' => array(
665
+ 'default' => '',
666
+ 'sanitize' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
667
+ ),
668
+ 'wcf_template_name' => array(
669
+ 'default' => '',
670
+ 'sanitize' => FILTER_SANITIZE_STRING,
671
+ ),
672
+ 'wcf_email_frequency' => array(
673
+ 'default' => 30,
674
+ 'sanitize' => FILTER_SANITIZE_NUMBER_INT,
675
+ ),
676
+ 'wcf_email_frequency_unit' => array(
677
+ 'default' => 'MINUTE',
678
+ 'sanitize' => FILTER_SANITIZE_STRING,
679
+ ),
680
+ 'wcf_activate_email_template' => array(
681
+ 'default' => 0,
682
+ 'sanitize' => FILTER_SANITIZE_NUMBER_INT,
683
+ ),
684
+
685
+ 'wcf_email_discount_type' => array(
686
+ 'default' => 'percent',
687
+ 'sanitize' => FILTER_SANITIZE_STRING,
688
+ ),
689
+ 'wcf_email_discount_amount' => array(
690
+ 'default' => 10,
691
+ 'sanitize' => FILTER_SANITIZE_NUMBER_INT,
692
+ ),
693
+ 'wcf_email_coupon_expiry_date' => array(
694
+ 'default' => '',
695
+ 'sanitize' => FILTER_SANITIZE_STRING,
696
+ ),
697
+ 'wcf_coupon_expiry_unit' => array(
698
+ 'default' => 'hours',
699
+ 'sanitize' => FILTER_SANITIZE_STRING,
700
+ ),
701
+ 'id' => array(
702
+ 'default' => null,
703
+ 'sanitize' => FILTER_SANITIZE_NUMBER_INT,
704
+ ),
705
+ );
706
+
707
+ $sanitized_post = array();
708
+ foreach ( $input_post_values as $key => $input_post_value ) {
709
+
710
+ if ( isset( $_POST[ $key ] ) ) {
711
+ $sanitized_post[ $key ] = filter_input( INPUT_POST, $key, $input_post_value['sanitize'] );
712
+ } else {
713
+ $sanitized_post[ $key ] = $input_post_value['default'];
714
+ }
715
+ }
716
+
717
+ $sanitized_post['wcf_override_global_coupon'] = isset( $_POST['wcf_override_global_coupon'] ) ? true : false;
718
+ $sanitized_post['wcf_email_body'] = html_entity_decode( $sanitized_post['wcf_email_body'] );
719
+
720
+ return $sanitized_post;
721
+
722
+ }
723
+
724
+
725
+ /**
726
+ * Add email template callback ajax.
727
+ */
728
+ function add_email_template() {
729
+
730
+ $sanitized_post = $this->sanitize_email_post_data();
731
+ $this->wpdb->insert(
732
+ $this->cart_abandonment_template_table_name,
733
+ array(
734
+ 'template_name' => $sanitized_post['wcf_template_name'],
735
+ 'email_subject' => $sanitized_post['wcf_email_subject'],
736
+ 'email_body' => wpautop( $sanitized_post['wcf_email_body'] ),
737
+ 'frequency' => $sanitized_post['wcf_email_frequency'],
738
+ 'frequency_unit' => $sanitized_post['wcf_email_frequency_unit'],
739
+ 'is_activated' => $sanitized_post['wcf_activate_email_template'],
740
+ ),
741
+ array( '%s', '%s', '%s', '%d', '%s', '%d' )
742
+ );
743
+
744
+ $email_template_id = $this->wpdb->insert_id;
745
+ $meta_data = array(
746
+ 'override_global_coupon' => $sanitized_post['wcf_override_global_coupon'],
747
+ 'discount_type' => $sanitized_post['wcf_email_discount_type'],
748
+ 'coupon_amount' => $sanitized_post['wcf_email_discount_amount'],
749
+ 'coupon_expiry_date' => $sanitized_post['wcf_email_coupon_expiry_date'],
750
+ 'coupon_expiry_unit' => $sanitized_post['wcf_coupon_expiry_unit'],
751
+ );
752
+
753
+ foreach ( $meta_data as $mera_key => $meta_value ) {
754
+ $this->add_email_template_meta( $email_template_id, $mera_key, $meta_value );
755
+ }
756
+
757
+ $param = array(
758
+ 'page' => WCF_CA_PAGE_NAME,
759
+ 'action' => WCF_ACTION_EMAIL_TEMPLATES,
760
+ 'sub_action' => WCF_SUB_ACTION_EDIT_EMAIL_TEMPLATES,
761
+ 'id' => $email_template_id,
762
+ 'wcf_ca_template_created' => 'YES',
763
+ );
764
+ $redirect_url = add_query_arg( $param, admin_url( '/admin.php' ) );
765
+ wp_safe_redirect( $redirect_url );
766
+
767
+ }
768
+
769
+ /**
770
+ * Edit email template callback ajax.
771
+ */
772
+ function edit_email_template() {
773
+ $sanitized_post = $this->sanitize_email_post_data();
774
+ $email_template_id = $sanitized_post['id'];
775
+
776
+ $this->wpdb->update(
777
+ $this->cart_abandonment_template_table_name,
778
+ array(
779
+ 'template_name' => $sanitized_post['wcf_template_name'],
780
+ 'email_subject' => $sanitized_post['wcf_email_subject'],
781
+ 'email_body' => wpautop( $sanitized_post['wcf_email_body'] ),
782
+ 'frequency' => $sanitized_post['wcf_email_frequency'],
783
+ 'frequency_unit' => $sanitized_post['wcf_email_frequency_unit'],
784
+ 'is_activated' => $sanitized_post['wcf_activate_email_template'],
785
+ ),
786
+ array( 'id' => $email_template_id ),
787
+ array( '%s', '%s', '%s', '%d', '%s', '%d' ),
788
+ array( '%d' )
789
+ );
790
+
791
+ $meta_data = array(
792
+ 'override_global_coupon' => $sanitized_post['wcf_override_global_coupon'],
793
+ 'discount_type' => $sanitized_post['wcf_email_discount_type'],
794
+ 'coupon_amount' => $sanitized_post['wcf_email_discount_amount'],
795
+ 'coupon_expiry_date' => $sanitized_post['wcf_email_coupon_expiry_date'],
796
+ 'coupon_expiry_unit' => $sanitized_post['wcf_coupon_expiry_unit'],
797
+ );
798
+ foreach ( $meta_data as $mera_key => $meta_value ) {
799
+ $this->update_email_template_meta( $email_template_id, $mera_key, $meta_value );
800
+ }
801
+
802
+ $param = array(
803
+ 'page' => WCF_CA_PAGE_NAME,
804
+ 'action' => WCF_ACTION_EMAIL_TEMPLATES,
805
+ 'sub_action' => WCF_SUB_ACTION_EDIT_EMAIL_TEMPLATES,
806
+ 'id' => $email_template_id,
807
+ 'wcf_ca_template_updated' => 'YES',
808
+ );
809
+ $redirect_url = add_query_arg( $param, admin_url( '/admin.php' ) );
810
+
811
+ wp_safe_redirect( $redirect_url );
812
+
813
+ }
814
+
815
+ /**
816
+ * Restore default email templates.
817
+ */
818
+ public function restore_email_templates() {
819
+
820
+ $wpnonce = filter_input( INPUT_GET, '_wpnonce', FILTER_SANITIZE_STRING );
821
+
822
+ if ( $wpnonce && wp_verify_nonce( $wpnonce, WCF_EMAIL_TEMPLATES_NONCE ) ) {
823
+
824
+ include_once CARTFLOWS_CA_DIR . 'modules/cart-abandonment/class-cartflows-ca-cart-abandonment-db.php';
825
+ $db = Cartflows_Ca_Cart_Abandonment_Db::get_instance();
826
+ $db->template_table_seeder( true );
827
+
828
+ $param = array(
829
+ 'page' => WCF_CA_PAGE_NAME,
830
+ 'action' => WCF_ACTION_EMAIL_TEMPLATES,
831
+ 'wcf_ca_template_restored' => 'YES',
832
+ );
833
+ $redirect_url = add_query_arg( $param, admin_url( '/admin.php' ) );
834
+ wp_safe_redirect( $redirect_url );
835
+ }
836
+
837
+ }
838
+
839
+ /**
840
+ * Update the meta values.
841
+ *
842
+ * @param integer $email_template_id email template id.
843
+ * @param string $meta_key meta key.
844
+ * @param string $meta_value meta value.
845
+ */
846
+ function update_email_template_meta( $email_template_id, $meta_key, $meta_value ) {
847
+
848
+ $template_meta = $this->get_email_template_meta_by_key( $email_template_id, $meta_key );
849
+
850
+ if ( $template_meta ) {
851
+ $this->wpdb->update(
852
+ $this->email_templates_meta_table,
853
+ array(
854
+ 'meta_value' => sanitize_text_field( $meta_value ),
855
+ ),
856
+ array(
857
+ 'email_template_id' => $email_template_id,
858
+ 'meta_key' => sanitize_text_field( $meta_key ),
859
+ )
860
+ );
861
+ } else {
862
+ $this->add_email_template_meta( $email_template_id, $meta_key, $meta_value );
863
+ }
864
+
865
+ }
866
+
867
+
868
+ /**
869
+ * Add the meta values.
870
+ *
871
+ * @param integer $email_template_id email template id.
872
+ * @param string $meta_key meta key.
873
+ * @param string $meta_value meta value.
874
+ */
875
+ function add_email_template_meta( $email_template_id, $meta_key, $meta_value ) {
876
+ $this->wpdb->insert(
877
+ $this->email_templates_meta_table,
878
+ array(
879
+ 'email_template_id' => $email_template_id,
880
+ 'meta_key' => sanitize_text_field( $meta_key ),
881
+ 'meta_value' => sanitize_text_field( $meta_value ),
882
+ )
883
+ );
884
+ }
885
+
886
+ /**
887
+ * Get the meta values.
888
+ *
889
+ * @param integer $email_template_id email template id.
890
+ * @param string $meta_key meta key.
891
+ */
892
+ function get_email_template_meta_by_key( $email_template_id, $meta_key ) {
893
+ return $this->wpdb->get_row(
894
+ $this->wpdb->prepare( "select * from $this->email_templates_meta_table where email_template_id = %d AND meta_key = %s", $email_template_id, $meta_key ) // phpcs:ignore
895
+ );
896
+ }
897
+
898
+ /**
899
+ * Render email template grid.
900
+ */
901
+ function show_email_template_data_table() {
902
+ $wcf_template_list = new Cartflows_Ca_Email_Templates_Table();
903
+ $wcf_template_list->prepare_items();
904
+ $page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING );
905
+ ?>
906
+ <div class="wrap">
907
+ <form id="wcf-cart-abandonment-template-table" method="GET">
908
+ <input type="hidden" name="page" value="<?php echo esc_html( $page ); ?>"/>
909
+ <input type="hidden" name="action" value="<?php echo esc_html( WCF_ACTION_EMAIL_TEMPLATES ); ?>"/>
910
+ <input type="hidden" name="sub_action" value="<?php echo esc_html( WCF_SUB_ACTION_DELETE_BULK_EMAIL_TEMPLATES ); ?>"/>
911
+ <?php $wcf_template_list->display(); ?>
912
+ </form>
913
+ </div>
914
+ <?php
915
+ }
916
+
917
+ /**
918
+ * Render 'Add Email Template button'.
919
+ */
920
+ public function show_add_new_template_button() {
921
+ $param = array(
922
+ 'page' => WCF_CA_PAGE_NAME,
923
+ 'action' => WCF_ACTION_EMAIL_TEMPLATES,
924
+ 'sub_action' => WCF_SUB_ACTION_ADD_EMAIL_TEMPLATES,
925
+ );
926
+
927
+ $add_new_template_url = wp_nonce_url( add_query_arg( $param, admin_url( '/admin.php' ) ), WCF_EMAIL_TEMPLATES_NONCE );
928
+
929
+ $param['sub_action'] = WCF_SUB_ACTION_RESTORE_EMAIL_TEMPLATES;
930
+ $restore_template_url = wp_nonce_url( add_query_arg( $param, admin_url( '/admin.php' ) ), WCF_EMAIL_TEMPLATES_NONCE );
931
+
932
+ ?>
933
+ <div class="wcf-ca-report-btn">
934
+ <div class="wcf-ca-left-report-field-group">
935
+ <a style="cursor: pointer" href="<?php echo $add_new_template_url; ?>" class="button-secondary"><?php _e( 'Create New Template', 'cartflows-ca' ); ?></a>
936
+ </div>
937
+ <div class="wcf-ca-right-report-field-group">
938
+ <a onclick="return confirm('Are you sure to restore email templates?');" style="cursor: pointer" href="<?php echo $restore_template_url; ?>" class="button-secondary"><?php _e( ' Restore Default Templates', 'cartflows-ca' ); ?></a>
939
+ </div>
940
+ </div>
941
+ <?php
942
+ }
943
+
944
+ /**
945
+ * Get all active templates.
946
+ *
947
+ * @return array|object|null
948
+ */
949
+ public function fetch_all_active_templates() {
950
+ $result = $this->wpdb->get_results(
951
+ $this->wpdb->prepare('SELECT * FROM `' . $this->cart_abandonment_template_table_name . '` WHERE is_activated = %s', true) // phpcs:ignore
952
+ );
953
+ return $result;
954
+ }
955
+
956
+ /**
957
+ * Get specific template by id.
958
+ *
959
+ * @param integer $tmpl_id template id.
960
+ * @return array|object|void|null
961
+ */
962
+ public function get_template_by_id( $tmpl_id ) {
963
+ $result = $this->wpdb->get_row(
964
+ $this->wpdb->prepare('SELECT * FROM `' . $this->cart_abandonment_template_table_name . '` WHERE id = %s', $tmpl_id) // phpcs:ignore
965
+ );
966
+ return $result;
967
+ }
968
+
969
+ /**
970
+ * Get the email history.
971
+ *
972
+ * @param integer $email_history_id email history id.
973
+ * @return array|object|void|null
974
+ */
975
+ public function get_email_history_by_id( $email_history_id ) {
976
+ $result = $this->wpdb->get_row(
977
+ $this->wpdb->prepare('SELECT * FROM `' . $this->email_history_table . '` WHERE id = %s', $email_history_id) // phpcs:ignore
978
+ );
979
+ return $result;
980
+ }
981
+ }
982
+
983
+ Cartflows_Ca_Email_Templates::get_instance();
modules/cart-abandonment/class-cartflows-ca-module-loader.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Cart Abandonment DB
4
+ *
5
+ * @package Woocommerce-Cart-Abandonment-Recovery
6
+ */
7
+
8
+ /**
9
+ * Cart Abandonment DB class.
10
+ */
11
+ class Cartflows_Ca_Module_Loader {
12
+
13
+
14
+
15
+ /**
16
+ * Member Variable
17
+ *
18
+ * @var object instance
19
+ */
20
+ private static $instance;
21
+
22
+ /**
23
+ * Initiator
24
+ */
25
+ public static function get_instance() {
26
+ if ( ! isset( self::$instance ) ) {
27
+ self::$instance = new self;
28
+ }
29
+ return self::$instance;
30
+ }
31
+
32
+ /**
33
+ * Constructor
34
+ */
35
+ public function __construct() {
36
+
37
+ $this->load_module_files();
38
+ }
39
+
40
+
41
+ /**
42
+ * Load required files for module.
43
+ */
44
+ function load_module_files() {
45
+
46
+ /* Cart abandonment templates class */
47
+ include_once CARTFLOWS_CA_DIR . 'modules/cart-abandonment/class-cartflows-ca-email-templates.php';
48
+
49
+ /* Cart abandonment templates table */
50
+ include_once CARTFLOWS_CA_DIR . 'modules/cart-abandonment/class-cartflows-ca-email-templates-table.php';
51
+
52
+ /* Cart abandonment tracking */
53
+ include_once CARTFLOWS_CA_DIR . 'modules/cart-abandonment/class-cartflows-ca-cart-abandonment.php';
54
+
55
+ /* Cart abandonment tracking table */
56
+ include_once CARTFLOWS_CA_DIR . 'modules/cart-abandonment/class-cartflows-ca-cart-abandonment-table.php';
57
+
58
+ }
59
+
60
+ }
61
+
62
+ Cartflows_Ca_Module_Loader::get_instance();
modules/cart-abandonment/includes/admin/cartflows-cart-abandonment-reports.php ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Cartflows view for cart abandonment reports.
4
+ *
5
+ * @package Woocommerce-Cart-Abandonment-Recovery
6
+ */
7
+
8
+ ?>
9
+
10
+ <div class="wcf-ca-report-btn">
11
+
12
+ <div class="wcf-ca-left-report-field-group">
13
+ <button onclick="window.location.search += '&filter=today';"
14
+ class="button <?php echo 'today' === $filter ? 'button-primary' : 'button-secondary'; ?>"> Today
15
+ </button>
16
+
17
+ <button onclick="window.location.search += '&filter=yesterday';"
18
+ class="button <?php echo 'yesterday' === $filter ? 'button-primary' : 'button-secondary'; ?>"> Yesterday
19
+ </button>
20
+
21
+ <button onclick="window.location.search += '&filter=last_week';"
22
+ class="button <?php echo 'last_week' === $filter ? 'button-primary' : 'button-secondary'; ?>"> Last Week
23
+ </button>
24
+
25
+ <button onclick="window.location.search += '&filter=last_month';"
26
+ class="button <?php echo 'last_month' === $filter ? 'button-primary' : 'button-secondary'; ?> "> Last Month
27
+ </button>
28
+ </div>
29
+
30
+ <div class="wcf-ca-right-report-field-group">
31
+
32
+ <input class="wcf-ca-filter-input" type="text" id="wcf_ca_custom_filter_from" placeholder="YYYY-MM-DD" value="<?php echo $from_date; ?>"/>
33
+ <input class="wcf-ca-filter-input" type="text" id="wcf_ca_custom_filter_to" placeholder="YYYY-MM-DD" value="<?php echo $to_date; ?>" />
34
+ <button id="wcf_ca_custom_filter"
35
+ class="button <?php echo 'custom' === $filter ? 'button-primary' : 'button-secondary'; ?> "> Custom Filter
36
+ </button>
37
+
38
+ </div>
39
+
40
+ </div>
41
+
42
+ <div class="wcf-ca-grid-container">
43
+
44
+ <div class="wcf-ca-ibox">
45
+ <div class="wcf-ca-ibox-title">
46
+ <h3> <?php _e( 'Recoverable Orders', 'cartflows-ca' ); ?> </h3>
47
+ </div>
48
+ <div class="wcf-ca-ibox-content">
49
+ <h1> <?php echo $abandoned_report['no_of_orders']; ?> </h1>
50
+ <small> <?php _e( 'Total Recoverable Orders.', 'cartflows-ca' ); ?> </small>
51
+ </div>
52
+ </div>
53
+
54
+ <div class="wcf-ca-ibox">
55
+ <div class="wcf-ca-ibox-title"><h3><?php _e( 'Recovered Orders', 'cartflows-ca' ); ?></h3></div>
56
+ <div class="wcf-ca-ibox-content"><h1><?php echo $recovered_report['no_of_orders']; ?></h1>
57
+ <small> <?php _e( 'Total Recovered Orders.', 'cartflows-ca' ); ?> </small>
58
+ </div>
59
+ </div>
60
+
61
+ <div class="wcf-ca-ibox">
62
+ <div class="wcf-ca-ibox-title"><h3><?php _e( 'Lost Orders', 'cartflows-ca' ); ?></h3></div>
63
+ <div class="wcf-ca-ibox-content"><h1
64
+ ><?php echo $lost_report['no_of_orders']; ?></h1>
65
+ <small> <?php _e( 'Total Lost Orders.', 'cartflows-ca' ); ?> </small>
66
+ </div>
67
+ </div>
68
+
69
+ </div>
70
+
71
+ <div class="wcf-ca-grid-container">
72
+
73
+ <div class="wcf-ca-ibox">
74
+ <div class="wcf-ca-ibox-title"><h3> <?php _e( 'Recoverable Revenue', 'cartflows-ca' ); ?> </h3></div>
75
+ <div class="wcf-ca-ibox-content">
76
+ <h1>
77
+ <?php echo $currency_symbol . number_format_i18n( $abandoned_report['revenue'], 2 ); ?>
78
+ </h1>
79
+ <small> <?php _e( 'Total Recoverable Revenue.', 'cartflows-ca' ); ?> </small>
80
+ </div>
81
+ </div>
82
+
83
+ <div class="wcf-ca-ibox">
84
+ <div class="wcf-ca-ibox-title"><h3><?php _e( 'Recovered Revenue', 'cartflows-ca' ); ?></h3></div>
85
+ <div class="wcf-ca-ibox-content"><h1>
86
+ <?php
87
+ echo $currency_symbol . number_format_i18n( $recovered_report['revenue'], 2 );
88
+ ?>
89
+ </h1>
90
+ <small> <?php _e( 'Total Recovered Revenue.', 'cartflows-ca' ); ?> </small>
91
+ </div>
92
+ </div>
93
+
94
+ <div class="wcf-ca-ibox">
95
+ <div class="wcf-ca-ibox-title"><h3> <?php _e( 'Recovery Rate', 'cartflows-ca' ); ?> </h3></div>
96
+ <div class="wcf-ca-ibox-content"><h1><?php echo $conversion_rate . '%'; ?></h1>
97
+ <small><?php _e( 'Total Percentage Of Recovered Orders After Abandonment.', 'cartflows-ca' ); ?> </small>
98
+ </div>
99
+ </div>
100
+
101
+ </div>
102
+
103
+ <hr/>
104
+
105
+ <div class="wcf-ca-report-btn">
106
+ <div class="wcf-ca-left-report-field-group">
107
+ <button onclick="window.location.search += '&filter_table=<?php echo WCF_CART_ABANDONED_ORDER; ?>';"
108
+ class="button <?php echo WCF_CART_ABANDONED_ORDER === $filter_table ? 'button-primary' : 'button-secondary'; ?> "> Recoverable Orders
109
+ </button>
110
+ <button onclick="window.location.search += '&filter_table=<?php echo WCF_CART_COMPLETED_ORDER; ?>';"
111
+ class="button <?php echo WCF_CART_COMPLETED_ORDER === $filter_table ? 'button-primary' : 'button-secondary'; ?>"> Recovered Orders
112
+ </button>
113
+ <button onclick="window.location.search += '&filter_table=<?php echo WCF_CART_LOST_ORDER; ?>';"
114
+ class="button <?php echo WCF_CART_LOST_ORDER === $filter_table ? 'button-primary' : 'button-secondary'; ?>"> Lost Orders
115
+ </button>
116
+ </div>
117
+ </div>
118
+
119
+
120
+
121
+ <?php
122
+ if ( count( $wcf_list_table->items ) ) {
123
+ $page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING );
124
+
125
+ ?>
126
+
127
+ <form id="wcf-cart-abandonment-table" method="GET">
128
+ <input type="hidden" name="page" value="<?php echo esc_html( $page ); ?>"/>
129
+ <?php $wcf_list_table->display(); ?>
130
+ </form>
131
+
132
+ <?php
133
+ } else {
134
+
135
+ echo "<div style='text-align: center;'> <strong> " . __( 'No Orders Found.', 'cartflows-ca' ) . '</strong> </div>';
136
+
137
+ }
138
+
139
+ ?>
modules/cart-abandonment/includes/admin/cartflows-cart-abandonment-tabs.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Cartflows view for cart abandonment tabs.
4
+ *
5
+ * @package Woocommerce-Cart-Abandonment-Recovery
6
+ */
7
+
8
+ ?>
9
+ <div class="wrap">
10
+ <h1 id="wcf_cart_abandonment_tracking_table"><?php echo __( 'Woocommerce Cart Abandonment Recovery ', 'cartflows-ca' ); ?></h1>
11
+ <?php
12
+
13
+ $action = filter_input( INPUT_GET, 'action', FILTER_SANITIZE_STRING );
14
+ $sub_action = filter_input( INPUT_GET, 'sub_action', FILTER_SANITIZE_STRING );
15
+
16
+ if ( ! $action ) {
17
+ $action = WCF_ACTION_REPORTS;
18
+ }
19
+
20
+ $this->wcf_display_tabs();
21
+ $this->wcf_show_warning_ca();
22
+ ?>
23
+ <?php
24
+ echo get_transient( 'wcf_ca_show_message' );
25
+ ?>
26
+
27
+ <?php if ( WCF_ACTION_SETTINGS === $action ) : ?>
28
+ <?php
29
+ $this->wcf_display_settings();
30
+ ?>
31
+ <?php endif; ?>
32
+
33
+ <?php if ( WCF_ACTION_REPORTS === $action ) : ?>
34
+ <?php $this->wcf_display_reports(); ?>
35
+ <?php endif; ?>
36
+
37
+ <?php if ( WCF_ACTION_EMAIL_TEMPLATES === $action ) : ?>
38
+
39
+ <?php
40
+ $email_template_class_inst = Cartflows_Ca_Email_Templates::get_instance();
41
+ $email_template_class_inst->show_messages();
42
+ switch ( $sub_action ) {
43
+ case WCF_SUB_ACTION_DELETE_BULK_EMAIL_TEMPLATES:
44
+ $email_template_class_inst->delete_bulk_templates();
45
+ break;
46
+ case WCF_SUB_ACTION_DELETE_EMAIL_TEMPLATES:
47
+ $email_template_class_inst->delete_single_template();
48
+ break;
49
+ case WCF_SUB_ACTION_CLONE_EMAIL_TEMPLATES:
50
+ $email_template_class_inst->clone_email_template();
51
+ break;
52
+ case WCF_SUB_ACTION_ADD_EMAIL_TEMPLATES:
53
+ case WCF_SUB_ACTION_EDIT_EMAIL_TEMPLATES:
54
+ $email_template_class_inst->render_email_template_form( $sub_action );
55
+ break;
56
+ case WCF_SUB_ACTION_RESTORE_EMAIL_TEMPLATES:
57
+ $email_template_class_inst->restore_email_templates();
58
+ break;
59
+
60
+ case WCF_SUB_ACTION_SAVE_EMAIL_TEMPLATES:
61
+ check_ajax_referer( WCF_EMAIL_TEMPLATES_NONCE, '_wpnonce' );
62
+
63
+ $wcf_settings_frm = filter_input( INPUT_POST, 'wcf_settings_frm', FILTER_SANITIZE_STRING );
64
+ $id = filter_input( INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT );
65
+
66
+ if ( 'save' === $wcf_settings_frm ) {
67
+ $email_template_class_inst->add_email_template();
68
+ } elseif ( 'update' === $wcf_settings_frm && $id ) {
69
+ $email_template_class_inst->edit_email_template();
70
+ }
71
+ break;
72
+ default:
73
+ $email_template_class_inst->show_add_new_template_button();
74
+ $email_template_class_inst->show_email_template_data_table();
75
+ break;
76
+ }
77
+
78
+ ?>
79
+
80
+
81
+ <?php endif; ?>
82
+
83
+ </div>
readme.txt ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === WooCommerce Cart Abandonment Recovery ===
2
+ Contributors: brainstormforce, wpcrafter
3
+ Donate link: https://www.paypal.me/BrainstormForce
4
+ Tags: woocommerce, cart abandonment, cart recovery
5
+ Requires at least: 4.4
6
+ Tested up to: 5.2
7
+ Stable tag: 1.0.0
8
+ Requires PHP: 5.6
9
+ License: GPLv2 or later
10
+ License URI: https://www.gnu.org/licenses/gpl-2.0.html
11
+
12
+ Recover your lost revenue. Capture email address of users on the checkout page and send follow up emails if they don't complete the purchase.
13
+
14
+ == Description ==
15
+ WooCommerce Cart Abandonment Recovery plugin is best plugin to capture email address of users on the checkout page and send follow up emails if they don't complete the purchase. Ultimately, it will recover your lost revenue.
16
+
17
+
18
+ == Installation ==
19
+
20
+ 1. Upload `woocommerce-cart-abandonment-recovery.zip` to the `/wp-content/plugins/` directory
21
+ 2. Activate the plugin through the 'Plugins' menu in WordPress
22
+
23
+ == Frequently Asked Questions ==
24
+
25
+ = Does this plugin work with CartFlows? =
26
+
27
+ Yes, of course. We have built it in a way that it will work with CartFlows as well as with WooCommerce.
28
+
29
+ == Screenshots ==
30
+
31
+ == Changelog ==
32
+
33
+ = Version 1.0.0 - Monday, 27th May 2019 =
34
+ * Initial Release
35
+
36
+ == Upgrade Notice ==
uninstall.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Woocommerce Cart Abandonment Recovery
4
+ * Unscheduling the events.
5
+ *
6
+ * @package Woocommerce-Cart-Abandonment-Recovery
7
+ */
8
+
9
+ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
10
+ exit;
11
+ }
12
+
13
+
14
+ wp_clear_scheduled_hook( 'cartflows_ca_update_order_status_action' );
woo-cart-abandonment-recovery.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin Name: WooCommerce Cart Abandonment Recovery
4
+ * Plugin URI: https://cartflows.com/
5
+ * Description: Recover your lost revenue. Capture email address of users on the checkout page and send follow up emails if they don't complete the purchase.
6
+ * Version: 1.0.0
7
+ * Author: CartFlows Inc
8
+ * Author URI: https://cartflows.com/
9
+ * Text Domain: cartflows-ca
10
+ * WC requires at least: 3.0
11
+ * WC tested up to: 3.6.3
12
+ *
13
+ * @package Woocommerce-Cart-Abandonment-Recovery
14
+ */
15
+
16
+ /**
17
+ * Set constants.
18
+ */
19
+ define( 'CARTFLOWS_CA_FILE', __FILE__ );
20
+
21
+ /**
22
+ * Loader
23
+ */
24
+ require_once 'classes/class-cartflows-ca-loader.php';