affiliates-woocommerce.php
34.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
<?php
/**
* affiliates-woocommerce.php
*
* Copyright (c) 2012-2015 www.itthinx.com
*
* This code is provided subject to the license granted.
* Unauthorized use and distribution is prohibited.
* Parts of this code are released under the GNU General Public License.
* See COPYRIGHT.txt and LICENSE.txt.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This header and all notices must be kept intact.
*
* @author itthinx
* @package affiliates-woocommerce
* @since affiliates-woocommerce 1.0.0
*
* Plugin Name: Affiliates WooCommerce Integration
* Plugin URI: http://www.itthinx.com/plugins/affiliates-woocommerce
* Description: Integrates Affiliates Pro or Affiliates Enterprise and WooCommerce
* Author: itthinx
* Author URI: http://www.itthinx.com
* Version: 1.6.0
*/
define('AFF_WOOCOMMERCE_VERSION', '1.6.0');
if (!function_exists('itthinx_plugins')) {
require_once 'itthinx/itthinx.php';
} itthinx_plugins(__FILE__);
define('AFF_WOOCOMMERCE_FILE', __FILE__);
define('AFF_WOOCOMMERCE_PLUGIN_DOMAIN', 'affiliates-woocommerce');
class Affiliates_WooCommerce_Integration {
const IXAPWO39 = 'cancelled';
const IXAPWO40 = 'completed';
const IXAPWO41 = 'failed';
const IXAPWO42 = 'on-hold';
const IXAPWO43 = 'pending';
const IXAPWO44 = 'processing';
const IXAPWO45 = 'refunded';
const IXAPWO46 = 'processing_status';
const IXAPWO47 = 'shop_order';
const PLUGIN_OPTIONS = 'affiliates_woocommerce';
const IXAPWO48 = 'auto_cancelled';
const IXAPWO49 = 'auto_completed';
const IXAPWO50 = 'auto_failed';
const IXAPWO51 = 'auto_on_hold';
const IXAPWO52 = 'auto_pending';
const IXAPWO53 = 'auto_processing';
const IXAPWO54 = 'auto_refunded';
const IXAPWO55 = true;
const IXAPWO56 = 'enable_product_rates';
const IXAPWO57 = false;
const IXAPWO5 = 'default_rate';
const IXAPWO58 = 'enable_recurring_referrals';
const IXAPWO59 = false;
const IXAPWO60 = 'recurring_referrals_timeout';
const IXAPWO61 = 0;
const IXAPWO62 = 'aff_woo_admin_nonce';
const IXAPWO63 = 'set_admin_options';
private static $IXAPWO64 = array('affiliates-admin-referrals', 'affiliates-admin-hits', 'affiliates-admin-hits-affiliate');
private static $IXAPWO65 = array();
public static function admin_notices() {
if (!empty(self::$IXAPWO65)) {
foreach (self::$IXAPWO65 as $IXAPWO66) {
echo $IXAPWO66;
}
}
}
public static function init() {
add_action('admin_notices', array(__CLASS__, 'admin_notices'));
if (self::check_dependencies()) {
$IXAPWO3 = get_option(self::PLUGIN_OPTIONS, array());
add_action('woocommerce_checkout_order_processed', array(__CLASS__, 'woocommerce_checkout_order_processed'));
if (isset($IXAPWO3[self::IXAPWO58]) ? $IXAPWO3[self::IXAPWO58] : self::IXAPWO59) {
add_action('woocommerce_subscriptions_renewal_order_created', array(__CLASS__, 'woocommerce_subscriptions_renewal_order_created'), 10, 4);
} $IXAPWO67 = isset($IXAPWO3[self::IXAPWO48]) ? $IXAPWO3[self::IXAPWO48] : self::IXAPWO55;
$IXAPWO68 = isset($IXAPWO3[self::IXAPWO49]) ? $IXAPWO3[self::IXAPWO49] : self::IXAPWO55;
$IXAPWO69 = isset($IXAPWO3[self::IXAPWO50]) ? $IXAPWO3[self::IXAPWO50] : self::IXAPWO55;
$IXAPWO70 = isset($IXAPWO3[self::IXAPWO51]) ? $IXAPWO3[self::IXAPWO51] : self::IXAPWO55;
$IXAPWO71 = isset($IXAPWO3[self::IXAPWO52]) ? $IXAPWO3[self::IXAPWO52] : self::IXAPWO55;
$IXAPWO72 = isset($IXAPWO3[self::IXAPWO53]) ? $IXAPWO3[self::IXAPWO53] : self::IXAPWO55;
$IXAPWO73 = isset($IXAPWO3[self::IXAPWO54]) ? $IXAPWO3[self::IXAPWO54] : self::IXAPWO55;
if ($IXAPWO67) {
add_action('woocommerce_order_status_' . self::IXAPWO39, array(__CLASS__, 'order_status_cancelled'));
} if ($IXAPWO68) {
add_action('woocommerce_order_status_' . self::IXAPWO40, array(__CLASS__, 'order_status_completed'));
} if ($IXAPWO69) {
add_action('woocommerce_order_status_' . self::IXAPWO41, array(__CLASS__, 'order_status_failed'));
} if ($IXAPWO70) {
add_action('woocommerce_order_status_' . self::IXAPWO42, array(__CLASS__, 'order_status_on_hold'));
} if ($IXAPWO71) {
add_action('woocommerce_order_status_' . self::IXAPWO43, array(__CLASS__, 'order_status_pending'));
} if ($IXAPWO72) {
add_action('woocommerce_order_status_' . self::IXAPWO44, array(__CLASS__, 'order_status_processing'));
} if ($IXAPWO73) {
add_action('woocommerce_order_status_' . self::IXAPWO45, array(__CLASS__, 'order_status_refunded'));
} add_filter('post_type_link', array(__CLASS__, 'post_type_link'), 10, 4);
add_action('affiliates_admin_menu', array(__CLASS__, 'affiliates_admin_menu'));
add_filter('affiliates_footer', array(__CLASS__, 'affiliates_footer'));
$IXAPWO74 = isset($IXAPWO3[self::IXAPWO56]) ? $IXAPWO3[self::IXAPWO56] : self::IXAPWO57;
if ($IXAPWO74) {
if (is_admin()) {
include_once( 'class-affiliates-wc-product.php' );
} include_once( 'class-affiliates-wc-method.php' );
}
}
}
public static function check_dependencies($IXAPWO75 = false) {
$IXAPWO2 = true;
$active_plugins = get_option('active_plugins', array());
if (is_multisite()) {
$IXAPWO76 = get_site_option('active_sitewide_plugins', array());
$IXAPWO76 = array_keys($IXAPWO76);
$active_plugins = array_merge($active_plugins, $IXAPWO76);
} $IXAPWO77 = in_array('affiliates-pro/affiliates-pro.php', $active_plugins) || in_array('affiliates-enterprise/affiliates-enterprise.php', $active_plugins);
$IXAPWO78 = in_array('woocommerce/woocommerce.php', $active_plugins);
if (!$IXAPWO77) {
self::$IXAPWO65[] = "<div class='error'>" . __('<strong>Affiliates WooCommerce Integration</strong> plugin requires an appropriate Affiliates plugin to be activated: <a href="http://www.itthinx.com/plugins/affiliates-pro" target="_blank">Affiliates Pro</a> or <a href="http://www.itthinx.com/plugins/affiliates-enterprise" target="_blank">Affiliates Enterprise</a>.', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . "</div>";
} if (!$IXAPWO78) {
self::$IXAPWO65[] = "<div class='error'>" . __('The <strong>Affiliates WooCommerce Integration</strong> plugin requires the <a href="http://wordpress.org/extend/plugins/woocommerce" target="_blank">WooCommerce</a> plugin to be activated.', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . "</div>";
} if (!$IXAPWO77 || !$IXAPWO78) {
if ($IXAPWO75) {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
deactivate_plugins(array(__FILE__));
} $IXAPWO2 = false;
} return $IXAPWO2;
}
public static function affiliates_admin_menu() {
$IXAPWO79 = add_submenu_page('affiliates-admin', __('Affiliates WooCommerce Integration', AFF_WOOCOMMERCE_PLUGIN_DOMAIN), __('WooCommerce Integration', AFF_WOOCOMMERCE_PLUGIN_DOMAIN), AFFILIATES_ADMINISTER_OPTIONS, 'affiliates-admin-woocommerce', array(__CLASS__, 'affiliates_admin_woocommerce'));
$IXAPWO80[] = $IXAPWO79;
add_action('admin_print_styles-' . $IXAPWO79, 'affiliates_admin_print_styles');
add_action('admin_print_scripts-' . $IXAPWO79, 'affiliates_admin_print_scripts');
}
public static function affiliates_admin_woocommerce() {
$IXAPWO81 = '';
if (!current_user_can(AFFILIATES_ADMINISTER_OPTIONS)) {
wp_die(__('Access denied.', AFF_WOOCOMMERCE_PLUGIN_DOMAIN));
} $IXAPWO3 = get_option(self::PLUGIN_OPTIONS, array());
if (isset($_POST['submit'])) {
if (wp_verify_nonce($_POST[self::IXAPWO62], self::IXAPWO63)) {
$IXAPWO3[self::IXAPWO48] = !empty($_POST[self::IXAPWO48]);
$IXAPWO3[self::IXAPWO49] = !empty($_POST[self::IXAPWO49]);
$IXAPWO3[self::IXAPWO50] = !empty($_POST[self::IXAPWO50]);
$IXAPWO3[self::IXAPWO51] = !empty($_POST[self::IXAPWO51]);
$IXAPWO3[self::IXAPWO52] = !empty($_POST[self::IXAPWO52]);
$IXAPWO3[self::IXAPWO53] = !empty($_POST[self::IXAPWO53]);
$IXAPWO3[self::IXAPWO54] = !empty($_POST[self::IXAPWO54]);
switch ($_POST[self::IXAPWO46]) {
case AFFILIATES_REFERRAL_STATUS_ACCEPTED : case AFFILIATES_REFERRAL_STATUS_PENDING : $IXAPWO3[self::IXAPWO46] = $_POST[self::IXAPWO46];
break;
} $IXAPWO3[self::IXAPWO56] = !empty($_POST[self::IXAPWO56]);
if (!empty($_POST[self::IXAPWO5])) {
$IXAPWO4 = trim($_POST[self::IXAPWO5]);
if ($IXAPWO4 = Affiliates_Attributes::validate_value('referral.rate', $IXAPWO4)) {
$IXAPWO3[self::IXAPWO5] = $IXAPWO4;
} else {
unset($IXAPWO3[self::IXAPWO5]);
}
} else {
unset($IXAPWO3[self::IXAPWO5]);
} $IXAPWO3[self::IXAPWO58] = !empty($_POST[self::IXAPWO58]);
$IXAPWO82 = self::IXAPWO61;
if (!empty($_POST[self::IXAPWO60])) {
$IXAPWO82 = intval($_POST[self::IXAPWO60]);
if ($IXAPWO82 < 0) {
$IXAPWO82 = 0;
}
} $IXAPWO3[self::IXAPWO60] = $IXAPWO82;
} update_option(self::PLUGIN_OPTIONS, $IXAPWO3);
} $IXAPWO67 = isset($IXAPWO3[self::IXAPWO48]) ? $IXAPWO3[self::IXAPWO48] : self::IXAPWO55;
$IXAPWO68 = isset($IXAPWO3[self::IXAPWO49]) ? $IXAPWO3[self::IXAPWO49] : self::IXAPWO55;
$IXAPWO69 = isset($IXAPWO3[self::IXAPWO50]) ? $IXAPWO3[self::IXAPWO50] : self::IXAPWO55;
$IXAPWO70 = isset($IXAPWO3[self::IXAPWO51]) ? $IXAPWO3[self::IXAPWO51] : self::IXAPWO55;
$IXAPWO71 = isset($IXAPWO3[self::IXAPWO52]) ? $IXAPWO3[self::IXAPWO52] : self::IXAPWO55;
$IXAPWO72 = isset($IXAPWO3[self::IXAPWO53]) ? $IXAPWO3[self::IXAPWO53] : self::IXAPWO55;
$IXAPWO73 = isset($IXAPWO3[self::IXAPWO54]) ? $IXAPWO3[self::IXAPWO54] : self::IXAPWO55;
$IXAPWO83 = isset($IXAPWO3[self::IXAPWO46]) ? $IXAPWO3[self::IXAPWO46] : AFFILIATES_REFERRAL_STATUS_ACCEPTED;
$IXAPWO74 = isset($IXAPWO3[self::IXAPWO56]) ? $IXAPWO3[self::IXAPWO56] : self::IXAPWO57;
$IXAPWO4 = isset($IXAPWO3[self::IXAPWO5]) ? $IXAPWO3[self::IXAPWO5] : '';
$IXAPWO84 = isset($IXAPWO3[self::IXAPWO58]) ? $IXAPWO3[self::IXAPWO58] : self::IXAPWO59;
$IXAPWO85 = isset($IXAPWO3[self::IXAPWO60]) ? $IXAPWO3[self::IXAPWO60] : self::IXAPWO61;
echo '<div>' . '<h2>' . __('Affiliates WooCommerce Integration', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '</h2>' . '</div>';
$IXAPWO81 .= '<form action="" name="options" method="post">';
$IXAPWO81 .= '<div>';
$IXAPWO81 .= '<h3>' . __('Auto-adjustments of referrals', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '</h3>';
$IXAPWO81 .= '<p>' . __('The default referral status as determined in <em>Settings > Referrals</em> applies unless the following are enabled.', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '</p>';
$IXAPWO81 .= '<h4>' . __('Cancelled orders', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '</h4>';
$IXAPWO81 .= '<p>';
$IXAPWO81 .= '<input name="' . self::IXAPWO48 . '" type="checkbox" ' . ( $IXAPWO67 ? ' checked="checked" ' : '' ) . ' />';
$IXAPWO81 .= ' ';
$IXAPWO81 .= '<label for="' . self::IXAPWO48 . '">' . __('Auto-adjust referral status when an order is cancelled', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '</label>';
$IXAPWO81 .= '</p>';
$IXAPWO81 .= '<p class="description">' . __('The referrals related to the order will be rejected automatically, unless they are closed.', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '</p>';
$IXAPWO81 .= '<h4>' . __('Completed orders', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '</h4>';
$IXAPWO81 .= '<p>';
$IXAPWO81 .= '<input name="' . self::IXAPWO49 . '" type="checkbox" ' . ( $IXAPWO68 ? ' checked="checked" ' : '' ) . ' />';
$IXAPWO81 .= ' ';
$IXAPWO81 .= '<label for="' . self::IXAPWO49 . '">' . __('Auto-adjust referral status when an order is completed', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '</label>';
$IXAPWO81 .= '</p>';
$IXAPWO81 .= '<p class="description">' . __('The referrals related to the order will be accepted automatically, unless they are closed.', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '</p>';
$IXAPWO81 .= '<h4>' . __('Failed orders', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '</h4>';
$IXAPWO81 .= '<p>';
$IXAPWO81 .= '<input name="' . self::IXAPWO50 . '" type="checkbox" ' . ( $IXAPWO69 ? ' checked="checked" ' : '' ) . ' />';
$IXAPWO81 .= ' ';
$IXAPWO81 .= '<label for="' . self::IXAPWO50 . '">' . __('Auto-adjust referral status when an order has failed', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '</label>';
$IXAPWO81 .= '</p>';
$IXAPWO81 .= '<p class="description">' . __('The referrals related to the order will be rejected automatically, unless they are closed.', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '</p>';
$IXAPWO81 .= '<h4>' . __('Orders on hold', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '</h4>';
$IXAPWO81 .= '<p>';
$IXAPWO81 .= '<input name="' . self::IXAPWO51 . '" type="checkbox" ' . ( $IXAPWO70 ? ' checked="checked" ' : '' ) . ' />';
$IXAPWO81 .= ' ';
$IXAPWO81 .= '<label for="' . self::IXAPWO51 . '">' . __('Auto-adjust referral status when an order is put on hold', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '</label>';
$IXAPWO81 .= '</p>';
$IXAPWO81 .= '<p class="description">' . __('The referrals related to the order will automatically be marked as pending, unless they are closed.', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '</p>';
$IXAPWO81 .= '<h4>' . __('Pending orders', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '</h4>';
$IXAPWO81 .= '<p>';
$IXAPWO81 .= '<input name="' . self::IXAPWO52 . '" type="checkbox" ' . ( $IXAPWO71 ? ' checked="checked" ' : '' ) . ' />';
$IXAPWO81 .= ' ';
$IXAPWO81 .= '<label for="' . self::IXAPWO52 . '">' . __('Auto-adjust referral status when an order is set to pending', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '</label>';
$IXAPWO81 .= '</p>';
$IXAPWO81 .= '<p class="description">' . __('The referrals related to the order will automatically be marked as pending, unless they are closed.', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '</p>';
$IXAPWO81 .= '<h4>' . __('Orders processed', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '</h4>';
$IXAPWO81 .= '<p>';
$IXAPWO81 .= '<input name="' . self::IXAPWO53 . '" type="checkbox" ' . ( $IXAPWO72 ? ' checked="checked" ' : '' ) . ' />';
$IXAPWO81 .= ' ';
$IXAPWO81 .= '<label for="' . self::IXAPWO53 . '">' . __('Auto-adjust referral status when an order is processing', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '</label>';
$IXAPWO81 .= '</p>';
$IXAPWO81 .= '<p>';
$IXAPWO81 .= '<label>';
$IXAPWO81 .= sprintf('<input name="%s" type="radio" value="%s" %s />', self::IXAPWO46, AFFILIATES_REFERRAL_STATUS_PENDING, $IXAPWO83 == AFFILIATES_REFERRAL_STATUS_PENDING ? ' checked="checked" ' : '' );
$IXAPWO81 .= ' ';
$IXAPWO81 .= __('The referrals related to the order will automatically be marked as <em>pending</em>, unless they are closed.', AFF_WOOCOMMERCE_PLUGIN_DOMAIN);
$IXAPWO81 .= '</label>';
$IXAPWO81 .= '<br/>';
$IXAPWO81 .= '<label>';
$IXAPWO81 .= sprintf('<input name="%s" type="radio" value="%s" %s />', self::IXAPWO46, AFFILIATES_REFERRAL_STATUS_ACCEPTED, $IXAPWO83 == AFFILIATES_REFERRAL_STATUS_ACCEPTED ? ' checked="checked" ' : '' );
$IXAPWO81 .= ' ';
$IXAPWO81 .= __('The referrals related to the order will automatically be marked as <em>accepted</em>, unless they are closed.', AFF_WOOCOMMERCE_PLUGIN_DOMAIN);
$IXAPWO81 .= '</label>';
$IXAPWO81 .= '</p>';
$IXAPWO81 .= '<h4>' . __('Refunded orders', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '</h4>';
$IXAPWO81 .= '<p>';
$IXAPWO81 .= '<input name="' . self::IXAPWO54 . '" type="checkbox" ' . ( $IXAPWO73 ? ' checked="checked" ' : '' ) . ' />';
$IXAPWO81 .= ' ';
$IXAPWO81 .= '<label for="' . self::IXAPWO54 . '">' . __('Auto-adjust referral status when an order is refunded', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '</label>';
$IXAPWO81 .= '</p>';
$IXAPWO81 .= '<p class="description">' . __('The referrals related to the order will be rejected automatically, unless they are closed.', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '</p>';
$IXAPWO81 .= '<h3>' . __('Product rates', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '</h3>';
$IXAPWO81 .= '<p>';
$IXAPWO81 .= '<label>';
$IXAPWO81 .= sprintf('<input name="%s" type="checkbox" %s />', self::IXAPWO56, $IXAPWO74 ? ' checked="checked" ' : '' );
$IXAPWO81 .= ' ';
$IXAPWO81 .= __('Enable product referral rates', AFF_WOOCOMMERCE_PLUGIN_DOMAIN);
$IXAPWO81 .= '</label>';
$IXAPWO81 .= '<br/>';
$IXAPWO81 .= '<span class="description">';
$IXAPWO81 .= __('When this option is enabled, you can set referral rates for products.', AFF_WOOCOMMERCE_PLUGIN_DOMAIN);
$IXAPWO81 .= ' ';
$IXAPWO81 .= __('The rate can be set when editing a product, under <strong>Product Data > Affiliates</strong>.', AFF_WOOCOMMERCE_PLUGIN_DOMAIN);
$IXAPWO81 .= '<br/>';
$IXAPWO81 .= __('<strong>Important</strong> : Note that you <strong>must</strong> choose the <code>Affiliates_WC_Method::product_rates</code> method under <strong>Affiliates > Settings > Commissions</strong> for product rates to be applied in general, or specify that method as an attribute for individual affiliates - otherwise the product rates will <strong>not</strong> apply.', AFF_WOOCOMMERCE_PLUGIN_DOMAIN);
$IXAPWO81 .= '</span>';
$IXAPWO81 .= '</p>';
$IXAPWO81 .= '<p>';
$IXAPWO81 .= '<label>';
$IXAPWO81 .= __('Default rate', AFF_WOOCOMMERCE_PLUGIN_DOMAIN);
$IXAPWO81 .= ' ';
$IXAPWO81 .= sprintf('<input name="%s" type="text" value="%s" placeholder="%s" />', self::IXAPWO5, $IXAPWO4, __('not set', AFF_WOOCOMMERCE_PLUGIN_DOMAIN));
$IXAPWO81 .= '</label>';
$IXAPWO81 .= '<br/>';
$IXAPWO81 .= '<span class="description">';
$IXAPWO81 .= __('The default rate is used when no specific product rate applies.', AFF_WOOCOMMERCE_PLUGIN_DOMAIN);
$IXAPWO81 .= '<br/>';
$IXAPWO81 .= __('<strong>Important</strong> : If you do not set a default rate and no product rate applies, the resulting referral amount for an order will be zero.', AFF_WOOCOMMERCE_PLUGIN_DOMAIN);
$IXAPWO81 .= '</span>';
$IXAPWO81 .= '</p>';
$IXAPWO81 .= '<h3>' . __('Recurring Referrals', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '</h3>';
$IXAPWO81 .= '<p>';
$IXAPWO81 .= '<label>';
$IXAPWO81 .= sprintf('<input name="%s" type="checkbox" %s />', self::IXAPWO58, $IXAPWO84 ? ' checked="checked" ' : '' );
$IXAPWO81 .= ' ';
$IXAPWO81 .= __('Enable recurring referrals', AFF_WOOCOMMERCE_PLUGIN_DOMAIN);
$IXAPWO81 .= '</label>';
$IXAPWO81 .= '<br/>';
$IXAPWO81 .= '<span class="description">';
$IXAPWO81 .= __('When this option is enabled, referrals on recurring payments are credited to the affiliate who referred the initial order.', AFF_WOOCOMMERCE_PLUGIN_DOMAIN);
$IXAPWO81 .= ' ';
$IXAPWO81 .= __('This option works with subscriptions provided by the <a href="http://www.woothemes.com/products/woocommerce-subscriptions/">WooCommerce Subscriptions</a> plugin.', AFF_WOOCOMMERCE_PLUGIN_DOMAIN);
$IXAPWO81 .= ' ';
$IXAPWO81 .= __('A referral for the original order must exist and must not have been rejected.', AFF_WOOCOMMERCE_PLUGIN_DOMAIN);
$IXAPWO81 .= '</p>';
$IXAPWO81 .= '<p>';
$IXAPWO81 .= '<label>';
$IXAPWO81 .= __('Limit / Timeout', AFF_WOOCOMMERCE_PLUGIN_DOMAIN);
$IXAPWO81 .= ' ';
$IXAPWO81 .= sprintf('<input name="%s" type="text" value="%s" />', self::IXAPWO60, $IXAPWO85);
$IXAPWO81 .= '</label>';
$IXAPWO81 .= '<br/>';
$IXAPWO81 .= '<span class="description">';
$IXAPWO81 .= __('If set to 0, there is no time limit for referrals on recurring payments granted to the initial affiliate. Any other number will limit new referrals for a subscription to so many days after the initial referral.', AFF_WOOCOMMERCE_PLUGIN_DOMAIN);
$IXAPWO81 .= '</span>';
$IXAPWO81 .= '</p>';
$IXAPWO81 .= '<p>';
$IXAPWO81 .= wp_nonce_field(self::IXAPWO63, self::IXAPWO62, true, false);
$IXAPWO81 .= '<input type="submit" name="submit" value="' . __('Save', AFF_WOOCOMMERCE_PLUGIN_DOMAIN) . '"/>';
$IXAPWO81 .= '</p>';
$IXAPWO81 .= '</div>';
$IXAPWO81 .= '</form>';
echo $IXAPWO81;
affiliates_footer();
}
public static function affiliates_footer($IXAPWO86) {
return $IXAPWO86;
}
public static function post_type_link($post_link, $post, $IXAPWO87, $IXAPWO88) {
$IXAPWO89 = $post_link;
if (isset($post->post_type) && ( $post->post_type == self::IXAPWO47 ) && is_admin() && isset($_REQUEST['page']) && in_array($_REQUEST['page'], self::$IXAPWO64) && ( ( preg_match("/" . self::IXAPWO47 . "=([^&]*)/", $post_link, $IXAPWO90) === 1 ) && isset($IXAPWO90[1]) && ( $IXAPWO90[1] === $post->post_name ) || ( strpos($post_link, 'post_type=' . self::IXAPWO47) !== false ) && ( preg_match('/p=([0-9]+)/', $post_link, $IXAPWO90) === 1 ) && isset($IXAPWO90[1]) && ( $IXAPWO90[1] == $post->ID ) )) {
$IXAPWO89 = admin_url('post.php?post=' . $post->ID . '&action=edit');
} return $IXAPWO89;
}
public static function woocommerce_checkout_order_processed($IXAPWO6) {
self::process_order($IXAPWO6);
}
public static function process_order($IXAPWO6, $IXAPWO91 = null) {
global $affiliates_db;
if ($IXAPWO8 = self::get_order($IXAPWO6)) {
$IXAPWO92 = array();
if (method_exists($IXAPWO8, 'get_used_coupons')) {
$IXAPWO18 = $IXAPWO8->get_used_coupons();
} else {
$IXAPWO18 = get_post_meta($IXAPWO6, 'coupons', true);
} if (!empty($IXAPWO18)) {
if (is_string($IXAPWO18)) {
$IXAPWO18 = explode(",", $IXAPWO18);
} foreach ($IXAPWO18 as $IXAPWO20) {
$IXAPWO20 = trim($IXAPWO20);
$IXAPWO93 = new WC_Coupon($IXAPWO20);
if ($IXAPWO93->id) {
$IXAPWO0 = Affiliates_Attributes_WordPress::get_affiliate_for_coupon($IXAPWO93->code);
if ($IXAPWO0 === null) {
if ($IXAPWO94 = get_post($IXAPWO93->id)) {
$IXAPWO0 = Affiliates_Attributes_WordPress::get_affiliate_for_coupon($IXAPWO94->post_title);
}
} if (( $IXAPWO0 !== null ) && !in_array($IXAPWO0, $IXAPWO92)) {
$IXAPWO92[] = $IXAPWO0;
}
}
}
} $IXAPWO95 = null;
$IXAPWO96 = get_option('woocommerce_currency');
if (method_exists($IXAPWO8, 'get_subtotal')) {
$IXAPWO95 = $IXAPWO8->get_subtotal();
} if (method_exists($IXAPWO8, 'get_total_discount')) {
$IXAPWO95 -= $IXAPWO8->get_total_discount();
if ($IXAPWO95 < 0) {
$IXAPWO95 = 0;
}
} if (method_exists($IXAPWO8, 'get_order_currency')) {
$IXAPWO96 = $IXAPWO8->get_order_currency();
} if ($IXAPWO95 === null) {
$IXAPWO97 = get_post_meta($IXAPWO6, '_order_total', true);
$IXAPWO98 = get_post_meta($IXAPWO6, '_order_tax', true);
$IXAPWO99 = get_post_meta($IXAPWO6, '_order_shipping', true);
$IXAPWO100 = get_post_meta($IXAPWO6, '_order_shipping_tax', true);
$IXAPWO95 = $IXAPWO97 - $IXAPWO98 - $IXAPWO99 - $IXAPWO100;
} $IXAPWO101 = '<a href="' . admin_url('post.php?post=' . $IXAPWO6 . '&action=edit') . '">';
$IXAPWO101 .= sprintf(__('Order #%s', AFF_WOOCOMMERCE_PLUGIN_DOMAIN), $IXAPWO6);
$IXAPWO101 .= "</a>";
$IXAPWO102 = array('order_id' => array('title' => 'Order #', 'domain' => AFF_WOOCOMMERCE_PLUGIN_DOMAIN, 'value' => esc_sql($IXAPWO6)), 'order_total' => array('title' => 'Total', 'domain' => AFF_WOOCOMMERCE_PLUGIN_DOMAIN, 'value' => esc_sql($IXAPWO95)), 'order_currency' => array('title' => 'Currency', 'domain' => AFF_WOOCOMMERCE_PLUGIN_DOMAIN, 'value' => esc_sql($IXAPWO96)), 'order_link' => array('title' => 'Order', 'domain' => AFF_WOOCOMMERCE_PLUGIN_DOMAIN, 'value' => esc_sql($IXAPWO101)));
$IXAPWO103 = new Affiliates_Referral_WordPress();
$post_id = $IXAPWO6;
$IXAPWO104 = sprintf('Order #%s', $IXAPWO6);
if ($IXAPWO91 !== null) {
if (count($IXAPWO91) > 0) {
bcscale(AFFILIATES_REFERRAL_AMOUNT_DECIMALS);
$IXAPWO105 = bcdiv($IXAPWO95, count($IXAPWO91));
$IXAPWO103->add_referrals($IXAPWO91, $post_id, $IXAPWO104, $IXAPWO102, $IXAPWO105, null, $IXAPWO96, null, 'sale');
}
} else if (count($IXAPWO92) > 0) {
bcscale(AFFILIATES_REFERRAL_AMOUNT_DECIMALS);
$IXAPWO105 = bcdiv($IXAPWO95, count($IXAPWO92));
$IXAPWO103->add_referrals($IXAPWO92, $post_id, $IXAPWO104, $IXAPWO102, $IXAPWO105, null, $IXAPWO96, null, 'sale');
} else {
$IXAPWO103->evaluate($post_id, $IXAPWO104, $IXAPWO102, $IXAPWO95, null, $IXAPWO96, null, 'sale');
} $IXAPWO3 = get_option(self::PLUGIN_OPTIONS, array());
switch ($IXAPWO8->status) {
case self::IXAPWO39 : $IXAPWO67 = isset($IXAPWO3[self::IXAPWO48]) ? $IXAPWO3[self::IXAPWO48] : self::IXAPWO55;
if ($IXAPWO67) {
self::order_status_cancelled($IXAPWO6);
} break;
case self::IXAPWO40 : $IXAPWO68 = isset($IXAPWO3[self::IXAPWO49]) ? $IXAPWO3[self::IXAPWO49] : self::IXAPWO55;
if ($IXAPWO68) {
self::order_status_completed($IXAPWO6);
} break;
case self::IXAPWO41 : $IXAPWO69 = isset($IXAPWO3[self::IXAPWO50]) ? $IXAPWO3[self::IXAPWO50] : self::IXAPWO55;
if ($IXAPWO69) {
self::order_status_failed($IXAPWO6);
} break;
case self::IXAPWO42 : $IXAPWO70 = isset($IXAPWO3[self::IXAPWO51]) ? $IXAPWO3[self::IXAPWO51] : self::IXAPWO55;
if ($IXAPWO70) {
self::order_status_on_hold($IXAPWO6);
} break;
case self::IXAPWO43 : $IXAPWO71 = isset($IXAPWO3[self::IXAPWO52]) ? $IXAPWO3[self::IXAPWO52] : self::IXAPWO55;
if ($IXAPWO71) {
self::order_status_pending($IXAPWO6);
} break;
case self::IXAPWO44 : $IXAPWO72 = isset($IXAPWO3[self::IXAPWO53]) ? $IXAPWO3[self::IXAPWO53] : self::IXAPWO55;
if ($IXAPWO72) {
self::order_status_processing($IXAPWO6);
} break;
case self::IXAPWO45 : $IXAPWO73 = isset($IXAPWO3[self::IXAPWO54]) ? $IXAPWO3[self::IXAPWO54] : self::IXAPWO55;
if ($IXAPWO73) {
self::order_status_refunded($IXAPWO6);
} break;
}
}
}
public static function woocommerce_subscriptions_renewal_order_created($IXAPWO106, $IXAPWO107, $IXAPWO13, $IXAPWO108) {
$IXAPWO3 = get_option(self::PLUGIN_OPTIONS, array());
$IXAPWO84 = isset($IXAPWO3[self::IXAPWO58]) ? $IXAPWO3[self::IXAPWO58] : self::IXAPWO59;
$IXAPWO85 = isset($IXAPWO3[self::IXAPWO60]) ? $IXAPWO3[self::IXAPWO60] : self::IXAPWO61;
if (!$IXAPWO84) {
return;
} $IXAPWO109 = $IXAPWO107->id;
global $affiliates_db;
$IXAPWO110 = $affiliates_db->get_tablename('referrals');
$IXAPWO111 = $affiliates_db->get_objects("SELECT * FROM $IXAPWO110 WHERE post_id = %d AND type = 'sale' AND status != %s", intval($IXAPWO109), AFFILIATES_REFERRAL_STATUS_REJECTED);
if (count($IXAPWO111) > 0) {
$IXAPWO91 = array();
$IXAPWO112 = time();
$IXAPWO113 = absint(isset($IXAPWO3[self::IXAPWO60]) ? $IXAPWO3[self::IXAPWO60] : self::IXAPWO61 );
foreach ($IXAPWO111 as $IXAPWO114) {
if (isset($IXAPWO114->data)) {
$IXAPWO102 = maybe_unserialize($IXAPWO114->data);
if (is_array($IXAPWO102) && key_exists('tier_level', $IXAPWO102)) {
continue;
}
} $IXAPWO0 = $IXAPWO114->affiliate_id;
if ($IXAPWO0 = affiliates_check_affiliate_id($IXAPWO0)) {
if (!in_array($IXAPWO0, $IXAPWO91)) {
$IXAPWO115 = strtotime($IXAPWO114->datetime . " GMT");
if (( $IXAPWO113 == 0 ) || ( ( $IXAPWO112 - $IXAPWO115 ) <= ( AFFILIATES_COOKIE_TIMEOUT_BASE * $IXAPWO113 ) )) {
$IXAPWO91[] = $IXAPWO0;
}
}
}
} if (count($IXAPWO91) > 0) {
self::process_order($IXAPWO106->id, $IXAPWO91);
}
}
}
public static function order_status_cancelled($IXAPWO6) {
global $affiliates_db;
$IXAPWO116 = $affiliates_db->get_tablename("referrals");
$IXAPWO111 = $affiliates_db->get_objects("SELECT referral_id FROM $IXAPWO116 WHERE post_id = %d AND status != %s AND status != %s", intval($IXAPWO6), AFFILIATES_REFERRAL_STATUS_REJECTED, AFFILIATES_REFERRAL_STATUS_CLOSED);
if ($IXAPWO111) {
foreach ($IXAPWO111 as $IXAPWO114) {
try {
$IXAPWO103 = new Affiliates_Referral_WordPress($IXAPWO114->referral_id);
$IXAPWO103->update(array('status' => AFFILIATES_REFERRAL_STATUS_REJECTED));
} catch (Exception $IXAPWO117) {
}
}
}
}
public static function order_status_completed($IXAPWO6) {
global $affiliates_db;
$IXAPWO116 = $affiliates_db->get_tablename("referrals");
$IXAPWO111 = $affiliates_db->get_objects("SELECT referral_id FROM $IXAPWO116 WHERE post_id = %d AND status != %s AND status != %s", intval($IXAPWO6), AFFILIATES_REFERRAL_STATUS_ACCEPTED, AFFILIATES_REFERRAL_STATUS_CLOSED);
if ($IXAPWO111) {
foreach ($IXAPWO111 as $IXAPWO114) {
try {
$IXAPWO103 = new Affiliates_Referral_WordPress($IXAPWO114->referral_id);
$IXAPWO103->update(array('status' => AFFILIATES_REFERRAL_STATUS_ACCEPTED));
} catch (Exception $IXAPWO117) {
}
}
}
}
public static function order_status_failed($IXAPWO6) {
self::order_status_cancelled($IXAPWO6);
}
public static function order_status_on_hold($IXAPWO6) {
self::order_status_pending($IXAPWO6);
}
public static function order_status_pending($IXAPWO6) {
global $affiliates_db;
$IXAPWO116 = $affiliates_db->get_tablename("referrals");
$IXAPWO111 = $affiliates_db->get_objects("SELECT referral_id FROM $IXAPWO116 WHERE post_id = %d AND status != %s AND status != %s", intval($IXAPWO6), AFFILIATES_REFERRAL_STATUS_PENDING, AFFILIATES_REFERRAL_STATUS_CLOSED);
if ($IXAPWO111) {
foreach ($IXAPWO111 as $IXAPWO114) {
try {
$IXAPWO103 = new Affiliates_Referral_WordPress($IXAPWO114->referral_id);
$IXAPWO103->update(array('status' => AFFILIATES_REFERRAL_STATUS_PENDING));
} catch (Exception $IXAPWO117) {
}
}
}
}
public static function order_status_processing($IXAPWO6) {
$IXAPWO3 = get_option(self::PLUGIN_OPTIONS, array());
$IXAPWO83 = isset($IXAPWO3[self::IXAPWO46]) ? $IXAPWO3[self::IXAPWO46] : AFFILIATES_REFERRAL_STATUS_ACCEPTED;
switch ($IXAPWO83) {
case AFFILIATES_REFERRAL_STATUS_PENDING : self::order_status_pending($IXAPWO6);
break;
default : self::order_status_completed($IXAPWO6);
}
}
public static function order_status_refunded($IXAPWO6) {
global $affiliates_db;
$IXAPWO116 = $affiliates_db->get_tablename("referrals");
$IXAPWO111 = $affiliates_db->get_objects("SELECT referral_id FROM $IXAPWO116 WHERE post_id = %d AND status != %s AND status != %s", intval($IXAPWO6), AFFILIATES_REFERRAL_STATUS_REJECTED, AFFILIATES_REFERRAL_STATUS_CLOSED);
if ($IXAPWO111) {
foreach ($IXAPWO111 as $IXAPWO114) {
try {
$IXAPWO103 = new Affiliates_Referral_WordPress($IXAPWO114->referral_id);
$IXAPWO103->update(array('status' => AFFILIATES_REFERRAL_STATUS_REJECTED));
} catch (Exception $IXAPWO117) {
}
}
}
}
public static function get_order($IXAPWO6 = '') {
$IXAPWO2 = null;
if (function_exists('wc_get_order')) {
if ($IXAPWO8 = wc_get_order($IXAPWO6)) {
$IXAPWO2 = $IXAPWO8;
}
} else if (class_exists('WC_Order')) {
$IXAPWO8 = new WC_Order($IXAPWO6);
if ($IXAPWO8->get_order($IXAPWO6)) {
$IXAPWO2 = $IXAPWO8;
}
} else if (class_exists('woocommerce_order')) {
$IXAPWO8 = new woocommerce_order();
if (method_exists($IXAPWO8, 'get_order')) {
if ($IXAPWO8->get_order($IXAPWO6)) {
$IXAPWO2 = $IXAPWO8;
}
}
} return $IXAPWO2;
}
}
Affiliates_WooCommerce_Integration::init();