-
Notifications
You must be signed in to change notification settings - Fork 0
/
woocommerce-order-transfer.php
672 lines (550 loc) · 25.7 KB
/
woocommerce-order-transfer.php
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
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
<?php
/*
Plugin Name: WooCommerce Order Transfer
Plugin URI: https://github.com/gsdefender/woocommerce-order-transfer
Description: WooCommerce plugin to allow transfering a pending order to another user upon checkout
Version: 0.1.1
Author: Emanuele Cipolla
Author URI: https://emanuelecipolla.net/
License: GPLv3
Text Domain: woocommerce-order-transfer
Domain Path: /lang
*/
defined('ABSPATH') or exit;
// Make sure WooCommerce is active
if (!in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
return;
}
/**
* Add the gateway to WC Available Gateways
*
* @param array $gateways all available WC gateways
* @return array $gateways all WC gateways + offline gateway
* @since 0.1.0
*/
function wc_order_transfer_add_to_gateways($gateways)
{
$gateways['woocommerce-order-transfer'] = 'WC_Gateway_Order_Transfer';
return $gateways;
}
add_filter('woocommerce_payment_gateways', 'wc_order_transfer_add_to_gateways');
add_filter('woocommerce_available_payment_gateways', 'filter_gateways');
function filter_gateways($gateways)
{
$url_arr = explode('/', $_SERVER['REQUEST_URI']);
if ($url_arr[1] == 'checkout' && $url_arr[2] == 'order-pay' && is_user_logged_in()) {
$order_id = intval($url_arr[3]);
$order = wc_get_order($order_id);
$dest_user_id = $order->get_meta('_dest_user_id', true, 'view');
$dest_account_email = $order->get_meta('_dest_account_email', true, 'view');
if (!empty($dest_user_id) || !empty($dest_account_email)) {
unset($gateways['order_transfer_gateway']);
}
}
return $gateways;
}
/**
* Adds plugin page links
*
* @param array $links all plugin links
* @return array $links all plugin links + our custom links (i.e., "Settings")
* @since 0.1.0
*/
function wc_order_transfer_gateway_plugin_links($links)
{
$plugin_links = array(
'<a href="' . admin_url('admin.php?page=wc-settings&tab=checkout§ion=order_transfer_gateway') . '">' . __('Configure', 'woocommerce-order-transfer') . '</a>'
);
return $plugin_links;
}
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'wc_order_transfer_gateway_plugin_links');
/**
* Order Transfer Gateway
*
* Provides a virtual gateway to transfer orders to another customer.
* We load it later to ensure WC is loaded first since we're extending it.
*
* @class WC_Gateway_Order_Transfer
* @extends WC_Payment_Gateway
* @version 0.1.0
* @package WooCommerce/Classes/Payment
* @author Emanuele Cipolla <[email protected]>
*/
add_action('plugins_loaded', 'wc_order_transfer_gateway_init', 11);
function wc_order_transfer_gateway_init()
{
load_plugin_textdomain('woocommerce-order-transfer', FALSE, basename(dirname(__FILE__)) . '/lang/');
class WC_Gateway_Order_Transfer extends WC_Payment_Gateway
{
/**
* Constructor for the gateway.
*/
public function __construct()
{
$this->id = 'order_transfer_gateway';
$this->icon = apply_filters('woocommerce_order_transfer_icon', '');
$this->has_fields = false;
$this->method_title = __('Order transfer', 'woocommerce-order-transfer');
$this->method_description = __('Allows transferring orders to another customer. Orders are marked as "on-hold" when received.', 'woocommerce-order-transfer');
$this->order_button_text = __('Transfer order', 'woocommerce-order-transfer');
// Load the settings.
$this->init_form_fields();
$this->init_settings();
// Define user set variables
$this->title = $this->get_option('title');
$this->description = $this->get_option('description');
$this->instructions = $this->get_option('instructions', $this->description);
// Actions
add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
add_action('woocommerce_checkout_create_order', array($this, 'save_order_payment_type_meta_data'), 10, 2);
add_action('woocommerce_thankyou_' . $this->id, array($this, 'thankyou_page'), 10, 1);
// Customer Emails
add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3);
}
/**
* Initialize Gateway Settings Form Fields
*/
public function init_form_fields()
{
$this->form_fields = apply_filters('wc_order_transfer_form_fields', array(
'enabled' => array(
'title' => __('Enable/Disable', 'woocommerce-order-transfer'),
'type' => 'checkbox',
'label' => __('Enable order transfer', 'woocommerce-order-transfer'),
'default' => 'yes'
),
'title' => array(
'title' => __('Title', 'woocommerce-order-transfer'),
'type' => 'text',
'description' => __('This controls the title for the payment method the customer sees during checkout.', 'woocommerce-order-transfer'),
'default' => __('Order transfer', 'woocommerce-order-transfer'),
'desc_tip' => true,
),
'description' => array(
'title' => __('Description', 'woocommerce-order-transfer'),
'type' => 'textarea',
'description' => __('Payment method description that the customer will see on your checkout.', 'woocommerce-order-transfer'),
'default' => __('Please transfer this order to another user', 'woocommerce-order-transfer'),
'desc_tip' => true,
),
'instructions' => array(
'title' => __('Instructions', 'woocommerce-order-transfer'),
'type' => 'textarea',
'description' => __('Instructions that will be added to the thank you page and emails. Use [dest_email] to substitute destination email address.', 'woocommerce-order-transfer'),
'default' => '',
'desc_tip' => true,
),
));
}
/**
* Output the "payment type" radio buttons fields in checkout.
*/
public function payment_fields()
{
if ($description = $this->get_description()) {
echo wpautop(wptexturize($description));
}
echo '<style>#dest_account_email_field label.input { display:inline-block; margin:0 .8em 0 .4em}</style>';
woocommerce_form_field('dest_account_email', array(
'type' => 'email',
'required' => true,
'class' => array('dest_account_email form-row-wide'),
'label' => __('E-mail address', $this->domain),
'validate' => array('email')
), null);
}
public function validate_fields()
{
if (empty($_POST['dest_account_email'])) {
wc_add_notice(__('Destination email address is required', 'woocommerce-order-transfer'), 'error');
return false;
} else if (!filter_var($_POST['dest_account_email'], FILTER_VALIDATE_EMAIL)) {
wc_add_notice(__('Invalid destination email address', 'woocommerce-order-transfer'), 'error');
return false;
} else {
$current_user = wp_get_current_user();
$user_email = $current_user->user_email;
if (strcmp($user_email, $_POST['dest_account_email']) == 0) {
wc_add_notice(__('You cannot transfer an order to yourself', 'woocommerce-order-transfer'), 'error');
return false;
}
}
return true;
}
/**
* Save the chosen payment type as order meta data.
*
* @param object $order
* @param array $data
*/
public function save_order_payment_type_meta_data($order, $data)
{
if ($data['payment_method'] === $this->id && isset($_POST['dest_account_email'])) {
$order->update_meta_data('_src_user_id', get_post_meta($this->id, '_customer_user', true));
$user = get_user_by('email', $_POST['dest_account_email']);
$dest_user_id = null;
if ($user !== false) {
$dest_user_id = $user->ID;
}
$order->update_meta_data('_dest_user_id', $dest_user_id);
$order->update_meta_data('_dest_account_email', esc_attr($_POST['dest_account_email']));
}
}
/**
* Output for the order received page.
*/
public function thankyou_page($order_id)
{
if ($this->instructions) {
$order = wc_get_order($order_id);
$dest_account_email = $order->get_meta('_dest_account_email', true, 'view');
echo wpautop(wptexturize($this->format_instructions($order)));
}
}
/**
* Add content to the WC emails.
*
* @access public
* @param WC_Order $order
* @param bool $sent_to_admin
* @param bool $plain_text
*/
public function email_instructions($order, $sent_to_admin, $plain_text = false)
{
if ($this->instructions && !$sent_to_admin && $this->id === $order->payment_method && $order->has_status('on-hold')) {
echo wpautop(wptexturize($this->format_instructions($order))) . PHP_EOL;
}
}
private function format_instructions($order) {
$dest_account_email = $order->get_meta('_dest_account_email', true, 'view');
$instructions = str_replace("[dest_email]", $dest_account_email, $this->instructions);
return $instructions;
}
/**
* Process the payment and return the result
*
* @param int $order_id
* @return array
*/
public function process_payment($order_id)
{
$order = wc_get_order($order_id);
// Mark as on-hold (we're awaiting the transfer confirmation)
$order->update_status('on-hold', __('Awaiting order transfer confirmation.', 'woocommerce-order-transfer'));
// Reduce stock levels
wc_reduce_stock_levels($order->get_id());
// Remove cart
WC()->cart->empty_cart();
// Return thankyou redirect
return array(
'result' => 'success',
'redirect' => $this->get_return_url($order)
);
}
} // end \WC_Gateway_Order_Transfer class
}
function wc_order_transfer_add_my_account_order_actions($actions, $order)
{
$dest_user_id = $order->get_meta('_dest_user_id', true, 'view');
$dest_account_email = $order->get_meta('_dest_account_email', true, 'view');
$order_to_be_transferred = !empty($dest_user_id) || !empty($dest_account_email);
if($order_to_be_transferred)
{
if ($order->has_status('on-hold')) {
$current_user = wp_get_current_user();
$current_user_id = (isset($current_user->ID) ? (int)$current_user->ID : 0);
if ($dest_user_id === $current_user_id ||
strcmp($dest_account_email, $current_user->user_email) == 0) {
$my_account_page_url = get_permalink(get_option('woocommerce_myaccount_page_id'));
$actions['accept-transfer'] = array(
'url' => $my_account_page_url . 'accept-order-transfer/' . $order->ID,
'name' => __('Accept transfer', 'woocommerce-order-transfer'),
);
$actions['decline-transfer'] = array(
'url' => $my_account_page_url . 'decline-order-transfer/' . $order->ID,
'name' => __('Decline transfer', 'woocommerce-order-transfer'),
);
}
} else if ($order->has_status('processing')) {
$actions['edit-order'] = array(
'url' => wp_nonce_url(add_query_arg(array('order_again' => $order->get_id(), 'edit_order' => $order->get_id())), 'woocommerce-order_again'),
'name' => __('Edit transferred products', 'woocommerce-order-transfer')
);
unset($actions['view']); // There is nothing useful in view action for order transfers.
}
}
return $actions;
}
add_filter('woocommerce_my_account_my_orders_actions', 'wc_order_transfer_add_my_account_order_actions', 10, 2);
/**
* Handle custom query using our own metadata variables.
* @param array $query - Args for WP_Query.
* @param array $query_vars - Query vars from WC_Order_Query.
* @return array modified $query
*/
function wc_order_transfer_handle_custom_query_var($query, $query_vars)
{
$custom_vars = array('_src_user_id', '_dest_user_id',
'_dest_account_email');
foreach ($custom_vars as $custom_var) {
if (!empty($query_vars[$custom_var])) {
$query['meta_query'][] = array(
'key' => $custom_var,
'value' => esc_attr($query_vars[$custom_var]),
);
}
}
return $query;
}
add_filter('woocommerce_order_data_store_cpt_get_orders_query', 'wc_order_transfer_handle_custom_query_var', 10, 2);
// ------------------
// 1. Register new endpoint to use for My Account page
// Note: Resave Permalinks or it will give 404 error
function wc_order_transfer_add_endpoints()
{
add_rewrite_endpoint('order-transfer-requests', EP_ROOT | EP_PAGES);
add_rewrite_endpoint('accept-order-transfer', EP_ROOT | EP_PAGES);
add_rewrite_endpoint('decline-order-transfer', EP_ROOT | EP_PAGES);
}
add_action('init', 'wc_order_transfer_add_endpoints');
// ------------------
// 2. Add new query var
function wc_order_transfer_order_transfer_requests_query_vars($vars)
{
$vars[] = 'order-transfer-requests';
return $vars;
}
function wc_order_transfer_accept_order_transfer_query_vars($vars)
{
$vars[] = 'accept-order-transfer';
return $vars;
}
function wc_order_transfer_decline_order_transfer_query_vars($vars)
{
$vars[] = 'decline-order-transfer';
return $vars;
}
add_filter('query_vars', 'wc_order_transfer_order_transfer_requests_query_vars', 0);
add_filter('query_vars', 'wc_order_transfer_accept_order_transfer_query_vars', 0);
add_filter('query_vars', 'wc_order_transfer_decline_order_transfer_query_vars', 0);
// ------------------
// 3. Insert the new endpoint into the My Account menu
function array_insert_after(array $array, $key, array $new)
{
$keys = array_keys($array);
$index = array_search($key, $keys);
$pos = false === $index ? count($array) : $index + 1;
return array_merge(array_slice($array, 0, $pos), $new, array_slice($array, $pos));
}
function wc_order_transfer_add_order_transfer_requests_link_my_account($items)
{
$items = array_insert_after($items, 'orders', array('order-transfer-requests' => __('Order transfer requests', 'woocommerce-order-transfer')));
return $items;
}
add_filter('woocommerce_account_menu_items', 'wc_order_transfer_add_order_transfer_requests_link_my_account', 99, 1);
// ------------------
// 4. Add content to the new endpoint
function wc_order_transfer_order_transfer_requests_content()
{
$current_user = wp_get_current_user();
$order_search_params = array(
'status' => 'on-hold',
'limit' => -1,
'orderby' => 'date',
'payment_method' => 'order_transfer_gateway',
'meta_query' =>
array(
'relation' => 'OR',
[
'key' => '_dest_user_id',
'compare' => '=',
'value' => $current_user->ID,
],
[
'key' => '_dest_account_email',
'value' => $current_user->user_email,
'compare' => '='
])
);
$_orders = wc_get_orders($order_search_params);
$orders = array();
foreach ($_orders as $_order) {
$actions = wc_get_account_orders_actions($_order);
unset($actions['view']);
if (count($actions) != 0) array_push($orders, array('order' => $_order, 'actions' => $actions));
}
$has_orders = !empty($orders);
echo '<h3>' . __('Order transfer requests', 'woocommerce-order-transfer') . '</h3>';
if ($has_orders) : ?>
<table class="woocommerce-orders-table woocommerce-MyAccount-orders shop_table shop_table_responsive my_account_orders account-orders-table">
<thead>
<tr>
<?php foreach (wc_get_account_orders_columns() as $column_id => $column_name) : ?>
<th class="woocommerce-orders-table__header woocommerce-orders-table__header-<?php echo esc_attr($column_id); ?>">
<span class="nobr"><?php echo esc_html($column_name); ?></span></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php
foreach ($orders as $_order) {
$order = $_order['order'];
$actions = $_order['actions'];
$item_count = $order->get_item_count() - $order->get_item_count_refunded();
?>
<tr class="woocommerce-orders-table__row woocommerce-orders-table__row--status-<?php echo esc_attr($order->get_status()); ?> order">
<?php foreach (wc_get_account_orders_columns() as $column_id => $column_name) : ?>
<td class="woocommerce-orders-table__cell woocommerce-orders-table__cell-<?php echo esc_attr($column_id); ?>"
data-title="<?php echo esc_attr($column_name); ?>">
<?php if (has_action('woocommerce_my_account_my_orders_column_' . $column_id)) : ?>
<?php do_action('woocommerce_my_account_my_orders_column_' . $column_id, $order); ?>
<?php elseif ('order-number' === $column_id) : ?>
<a href="<?php echo esc_url($order->get_view_order_url()); ?>">
<?php echo esc_html(_x('#', 'hash before order number', 'woocommerce') . $order->get_order_number()); ?>
</a>
<?php elseif ('order-date' === $column_id) : ?>
<time datetime="<?php echo esc_attr($order->get_date_created()->date('c')); ?>"><?php echo esc_html(wc_format_datetime($order->get_date_created())); ?></time>
<?php elseif ('order-status' === $column_id) : ?>
<?php echo esc_html(wc_get_order_status_name($order->get_status())); ?>
<?php elseif ('order-total' === $column_id) : ?>
<?php
/* translators: 1: formatted order total 2: total order items */
echo wp_kses_post(sprintf(_n('%1$s for %2$s item', '%1$s for %2$s items', $item_count, 'woocommerce'), $order->get_formatted_order_total(), $item_count));
?>
<?php elseif ('order-actions' === $column_id) : ?>
<?php
$actions = wc_get_account_orders_actions($order);
unset($actions['view']);
if (!empty($actions)) {
foreach ($actions as $key => $action) { // phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited
echo '<a href="' . esc_url($action['url']) . '" class="woocommerce-button button ' . sanitize_html_class($key) . '">' . esc_html($action['name']) . '</a>';
}
}
?>
<?php endif; ?>
</td>
<?php endforeach; ?>
</tr>
<?php
}
?>
</tbody>
</table>
<?php else : ?>
<div class="woocommerce-message woocommerce-message--info woocommerce-Message woocommerce-Message--info woocommerce-info">
<?php esc_html_e('No order transfer requests for you.', 'woocommerce-order-transfer'); ?>
</div>
<?php endif;
}
add_action('woocommerce_account_order-transfer-requests_endpoint', 'wc_order_transfer_order_transfer_requests_content');
// Note: add_action must follow 'woocommerce_account_{your-endpoint-slug}_endpoint' format
add_action('template_redirect', function () {
global $wp_query;
$my_account_page_url = get_permalink(get_option('woocommerce_myaccount_page_id'));
if (isset($wp_query->query_vars['accept-order-transfer'])) {
$order_id = $wp_query->query_vars['accept-order-transfer'];
if (!empty($order_id)) {
$order = wc_get_order($order_id);
$order->set_payment_method('');
$order->set_billing_address_1('');
$order->set_billing_address_2('');
$order->set_billing_city('');
$order->set_billing_company('');
$order->set_billing_country('');
$order->set_billing_email('');
$order->set_billing_first_name('');
$order->set_billing_last_name('');
$order->set_billing_phone('');
$order->set_billing_postcode('');
$order->set_billing_state('');
$order->set_shipping_address_1('');
$order->set_shipping_address_2('');
$order->set_shipping_city('');
$order->set_shipping_company('');
$order->set_shipping_country('');
$order->set_shipping_first_name('');
$order->set_shipping_last_name('');
$order->set_shipping_postcode('');
$order->set_shipping_state('');
$order->set_customer_id(get_current_user_id());
$order->save();
$order->update_status('processing', $note = __('Transfer accepted.', 'woocommerce-order-transfer'));
}
wp_redirect($my_account_page_url . "orders");
exit;
} else if (isset($wp_query->query_vars['decline-order-transfer'])) {
$order_id = $wp_query->query_vars['decline-order-transfer'];
if (!empty($order_id)) {
$order = wc_get_order($order_id);
$order->update_status('cancelled', $note = __('Transfer declined.', 'woocommerce-order-transfer'));
}
wp_redirect($my_account_page_url);
exit;
}
return;
});
add_action('woocommerce_cart_loaded_from_session', 'wc_order_transfer_detect_edit_order');
function wc_order_transfer_detect_edit_order($cart)
{
if ( isset( $_GET['edit_order'], $_GET['_wpnonce'] ) && is_user_logged_in() && wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), 'woocommerce-order_again' ) )
WC()->session->set( 'edit_order', absint( $_GET['edit_order'] ) );
}
// ----------------
// 6. Save Order Action if New Order is Placed
add_action('woocommerce_checkout_update_order_meta', 'wc_order_transfer_save_edit_order');
function wc_order_transfer_save_edit_order($order_id)
{
$edited = WC()->session->get('edit_order');
if (!empty($edited)) {
// update this new order
update_post_meta($order_id, '_edit_order', $edited);
$neworder = new WC_Order($order_id);
$oldorder_edit = get_edit_post_link($edited);
$neworder->add_order_note(__('Order placed after transfer. Old order number: ', 'woocommerce-order-transfer') . '<a href="' . $oldorder_edit . '">' . $edited . '</a>');
// cancel previous order
$oldorder = new WC_Order($edited);
$neworder_edit = get_edit_post_link($order_id);
$oldorder->update_status('cancelled', __('Order cancelled after transfer. New order number: ', 'woocommerce-order-transfer') . '<a href="' . $neworder_edit . '">' . $order_id . '</a> -');
}
}
register_activation_hook(__FILE__, 'woocommerce_order_transfer_activation');
function woocommerce_order_transfer_activation()
{
if (!wp_next_scheduled('woocommerce_order_transfer_hourly_jobs')) {
wp_schedule_event(time(), 'hourly', 'woocommerce_order_transfer_hourly_jobs');
}
}
add_action('woocommerce_order_transfer_hourly_jobs', 'check_expired_order_transfers');
function check_expired_order_transfers()
{
$order_search_params = array(
'status' => 'on-hold',
'limit' => -1,
'orderby' => 'date',
'payment_method' => 'order_transfer_gateway',
'date_before' => strtotime("-1 day")
);
$_orders = wc_get_orders($order_search_params);
foreach ($_orders as $_order) {
$_order->update_status('cancelled', $note = __('Transfer automatically declined.'));
}
}
// ----------------
// 1. Allow Order Again for Processing Status
add_filter( 'woocommerce_valid_order_statuses_for_order_again', 'wc_order_transfer_order_again_statuses' );
function wc_order_transfer_order_again_statuses( $statuses ) {
$statuses[] = 'processing';
return $statuses;
}
function wc_order_transfer_notification_email( $recipient, $order )
{
$payment_method = $order->get_payment_method();
if ($payment_method === 'order_transfer_gateway') {
$dest_account_email = $order->get_meta('_dest_account_email', true, 'view');
if (!empty($dest_account_email)) {
$recipient .= ", " . $dest_account_email;
}
}
return $recipient;
}
add_filter('woocommerce_email_recipient_customer_completed_order', 'wc_order_transfer_notification_email', 1, 2);