/var/www/html_us/wp-content/plugins/woocommerce/src/Internal/Admin/Orders/ListTable.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
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
<?php

namespace Automattic\WooCommerce\Internal\Admin\Orders;

use 
Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
use 
Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore;
use 
Automattic\WooCommerce\Utilities\OrderUtil;
use 
WC_Order;
use 
WP_List_Table;
use 
WP_Screen;

/**
 * Admin list table for orders as managed by the OrdersTableDataStore.
 */
class ListTable extends WP_List_Table {

    
/**
     * Order type.
     *
     * @var string
     */
    
private $order_type;

    
/**
     * Request vars.
     *
     * @var array
     */
    
private $request = array();

    
/**
     * Contains the arguments to be used in the order query.
     *
     * @var array
     */
    
private $order_query_args = array();

    
/**
     * Tracks if a filter (ie, date or customer filter) has been applied.
     *
     * @var bool
     */
    
private $has_filter false;

    
/**
     * Page controller instance for this request.
     *
     * @var PageController
     */
    
private $page_controller;

    
/**
     * Tracks whether we're currently inside the trash.
     *
     * @var boolean
     */
    
private $is_trash false;

    
/**
     * Caches order counts by status.
     *
     * @var array
     */
    
private $status_count_cache null;

    
/**
     * Sets up the admin list table for orders (specifically, for orders managed by the OrdersTableDataStore).
     *
     * @see WC_Admin_List_Table_Orders for the corresponding class used in relation to the traditional WP Post store.
     */
    
public function __construct() {
        
parent::__construct(
            array(
                
'singular' => 'order',
                
'plural'   => 'orders',
                
'ajax'     => false,
            )
        );
    }

    
/**
     * Init method, invoked by DI container.
     *
     * @internal This method is not intended to be used directly (except for testing).
     * @param PageController $page_controller Page controller instance for this request.
     */
    
final public function initPageController $page_controller ) {
        
$this->page_controller $page_controller;
    }

    
/**
     * Performs setup work required before rendering the table.
     *
     * @param array $args Args to initialize this list table.
     *
     * @return void
     */
    
public function setup$args = array() ): void {
        
$this->order_type $args['order_type'] ?? 'shop_order';

        
add_action'admin_notices', array( $this'bulk_action_notices' ) );
        
add_filter"manage_{$this->screen->id}_columns", array( $this'get_columns' ), );
        
add_filter'set_screen_option_edit_' $this->order_type '_per_page', array( $this'set_items_per_page' ), 10);
        
add_filter'default_hidden_columns', array( $this'default_hidden_columns' ), 10);
        
add_action'admin_footer', array( $this'enqueue_scripts' ) );
        
add_action'woocommerce_order_list_table_restrict_manage_orders', array( $this'customers_filter' ) );

        
$this->items_per_page();
        
set_screen_options();

        
add_action'manage_' wc_get_page_screen_id$this->order_type ) . '_custom_column', array( $this'render_column' ), 10);
    }

    
/**
     * Generates content for a single row of the table.
     *
     * @since 7.8.0
     *
     * @param \WC_Order $order The current order.
     */
    
public function single_row$order ) {
        
/**
         * Filters the list of CSS class names for a given order row in the orders list table.
         *
         * @since 7.8.0
         *
         * @param string[]  $classes An array of CSS class names.
         * @param \WC_Order $order   The order object.
         */
        
$css_classes apply_filters(
            
'woocommerce_' $this->order_type '_list_table_order_css_classes',
            array(
                
'order-' $order->get_id(),
                
'type-' $order->get_type(),
                
'status-' $order->get_status(),
            ),
            
$order
        
);
        
$css_classes array_uniquearray_map'trim'$css_classes ) );

        
// Is locked?
        
$edit_lock wc_get_container()->getEditLock::class );
        if ( 
$edit_lock->is_locked_by_another_user$order ) ) {
            
$css_classes[] = 'wp-locked';
        }

        echo 
'<tr id="order-' esc_attr$order->get_id() ) . '" class="' esc_attrimplode' '$css_classes ) ) . '">';
        
$this->single_row_columns$order );
        echo 
'</tr>';
    }

    
/**
     * Render individual column.
     *
     * @param string   $column_id Column ID to render.
     * @param WC_Order $order Order object.
     */
    
public function render_column$column_id$order ) {
        if ( ! 
$order ) {
            return;
        }

        if ( 
is_callable( array( $this'render_' $column_id '_column' ) ) ) {
            
call_user_func( array( $this'render_' $column_id '_column' ), $order );
        }
    }

    
/**
     * Handles output for the default column.
     *
     * @param \WC_Order $order       Current WooCommerce order object.
     * @param string    $column_name Identifier for the custom column.
     */
    
public function column_default$order$column_name ) {
        
/**
         * Fires for each custom column for a specific order type. This hook takes precedence over the generic
         * action `manage_{$this->screen->id}_custom_column`.
         *
         * @param string    $column_name Identifier for the custom column.
         * @param \WC_Order $order       Current WooCommerce order object.
         *
         * @since 7.3.0
         */
        
do_action'woocommerce_' $this->order_type '_list_table_custom_column'$column_name$order );

        
/**
         * Fires for each custom column in the Custom Order Table in the administrative screen.
         *
         * @param string    $column_name Identifier for the custom column.
         * @param \WC_Order $order       Current WooCommerce order object.
         *
         * @since 7.0.0
         */
        
do_action"manage_{$this->screen->id}_custom_column"$column_name$order );
    }

    
/**
     * Sets up an items-per-page control.
     */
    
private function items_per_page(): void {
        
add_screen_option(
            
'per_page',
            array(
                
'default' => 20,
                
'option'  => 'edit_' $this->order_type '_per_page',
            )
        );
    }

    
/**
     * Saves the items-per-page setting.
     *
     * @param mixed  $default The default value.
     * @param string $option  The option being configured.
     * @param int    $value   The submitted option value.
     *
     * @return mixed
     */
    
public function set_items_per_page$defaultstring $optionint $value ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.defaultFound -- backwards compat.
        
return 'edit_' $this->order_type '_per_page' === $option absint$value ) : $default;
    }

    
/**
     * Render the table.
     *
     * @return void
     */
    
public function display() {
        
$post_type get_post_type_object$this->order_type );

        
$title         esc_html$post_type->labels->name );
        
$add_new       esc_html$post_type->labels->add_new );
        
$new_page_link $this->page_controller->get_new_page_url$this->order_type );
        
$search_label  '';

        if ( ! empty( 
$this->order_query_args['s'] ) ) {
            
$search_label  '<span class="subtitle">';
            
$search_label .= sprintf(
                
/* translators: %s: Search query. */
                
__'Search results for: %s''woocommerce' ),
                
'<strong>' esc_html$this->order_query_args['s'] ) . '</strong>'
            
);
            
$search_label .= '</span>';
        }

        
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
        
echo wp_kses_post(
            
"
            <div class='wrap'>
                <h1 class='wp-heading-inline'>
{$title}</h1>
                <a href='" 
esc_url$new_page_link ) . "' class='page-title-action'>{$add_new}</a>
                
{$search_label}
                <hr class='wp-header-end'>"
        
);

        if ( 
$this->should_render_blank_state() ) {
            
$this->render_blank_state();
            return;
        }

        
$this->views();

        echo 
'<form id="wc-orders-filter" method="get" action="' esc_urlget_admin_urlnull'admin.php' ) ) . '">';
        
$this->print_hidden_form_fields();
        
$this->search_boxesc_html__'Search orders''woocommerce' ), 'orders-search-input' );

        
parent::display();
        echo 
'</form> </div>';
    }

    
/**
     * Renders advice in the event that no orders exist yet.
     *
     * @return void
     */
    
public function render_blank_state(): void {
        
?>
            <div class="woocommerce-BlankState">

                <h2 class="woocommerce-BlankState-message">
                    <?php esc_html_e'When you receive a new order, it will appear here.''woocommerce' ); ?>
                </h2>

                <div class="woocommerce-BlankState-buttons">
                    <a class="woocommerce-BlankState-cta button-primary button" target="_blank" href="https://woocommerce.com/document/managing-orders/?utm_source=blankslate&utm_medium=product&utm_content=ordersdoc&utm_campaign=woocommerceplugin"><?php esc_html_e'Learn more about orders''woocommerce' ); ?></a>
                </div>

            <?php
            
/**
             * Renders after the 'blank state' message for the order list table has rendered.
             *
             * @since 6.6.1
             */
            
do_action'wc_marketplace_suggestions_orders_empty_state' ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingSinceComment
            
?>

            </div>
        <?php
    
}

    
/**
     * Retrieves the list of bulk actions available for this table.
     *
     * @return array
     */
    
protected function get_bulk_actions() {
        
$selected_status $this->order_query_args['status'] ?? false;

        if ( array( 
'trash' ) === $selected_status ) {
            
$actions = array(
                
'untrash' => __'Restore''woocommerce' ),
                
'delete'  => __'Delete permanently''woocommerce' ),
            );
        } else {
            
$actions = array(
                
'mark_processing' => __'Change status to processing''woocommerce' ),
                
'mark_on-hold'    => __'Change status to on-hold''woocommerce' ),
                
'mark_completed'  => __'Change status to completed''woocommerce' ),
                
'mark_cancelled'  => __'Change status to cancelled''woocommerce' ),
                
'trash'           => __'Move to Trash''woocommerce' ),
            );
        }

        if ( 
wc_string_to_boolget_option'woocommerce_allow_bulk_remove_personal_data''no' ) ) ) {
            
$actions['remove_personal_data'] = __'Remove personal data''woocommerce' );
        }

        return 
$actions;
    }

    
/**
     * Gets a list of CSS classes for the WP_List_Table table tag.
     *
     * @since 7.8.0
     *
     * @return string[] Array of CSS classes for the table tag.
     */
    
protected function get_table_classes() {
        
/**
         * Filters the list of CSS class names for the orders list table.
         *
         * @since 7.8.0
         *
         * @param string[] $classes    An array of CSS class names.
         * @param string   $order_type The order type.
         */
        
$css_classes apply_filters(
            
'woocommerce_' $this->order_type '_list_table_css_classes',
            
array_merge(
                
parent::get_table_classes(),
                array(
                    
'wc-orders-list-table',
                    
'wc-orders-list-table-' $this->order_type,
                )
            ),
            
$this->order_type
        
);

        return 
array_uniquearray_map'trim'$css_classes ) );
    }

    
/**
     * Prepares the list of items for displaying.
     */
    
public function prepare_items() {
        
$limit $this->get_items_per_page'edit_' $this->order_type '_per_page' );

        
$this->order_query_args = array(
            
'limit'    => $limit,
            
'page'     => $this->get_pagenum(),
            
'paginate' => true,
            
'type'     => $this->order_type,
        );

        foreach ( array( 
'status''s''m''_customer_user''search-filter' ) as $query_var ) {
            
$this->request$query_var ] = sanitize_text_fieldwp_unslash$_REQUEST$query_var ] ?? '' ) );
        }

        
/**
         * Allows 3rd parties to filter the initial request vars before defaults and other logic is applied.
         *
         * @param array $request Request to be passed to `wc_get_orders()`.
         *
         * @since 7.3.0
         */
        
$this->request apply_filters'woocommerce_' $this->order_type '_list_table_request'$this->request );

        
$this->set_status_args();
        
$this->set_order_args();
        
$this->set_date_args();
        
$this->set_customer_args();
        
$this->set_search_args();

        
/**
         * Provides an opportunity to modify the query arguments used in the (Custom Order Table-powered) order list
         * table.
         *
         * @since 6.9.0
         *
         * @param array $query_args Arguments to be passed to `wc_get_orders()`.
         */
        
$order_query_args = (array) apply_filters'woocommerce_order_list_table_prepare_items_query_args'$this->order_query_args );

        
/**
         * Same as `woocommerce_order_list_table_prepare_items_query_args` but for a specific order type.
         *
         * @param array $query_args Arguments to be passed to `wc_get_orders()`.
         *
         * @since 7.3.0
         */
        
$order_query_args apply_filters'woocommerce_' $this->order_type '_list_table_prepare_items_query_args'$order_query_args );

        
// We must ensure the 'paginate' argument is set.
        
$order_query_args['paginate'] = true;

        
$orders      wc_get_orders$order_query_args );
        
$this->items $orders->orders;

        
$max_num_pages $orders->max_num_pages;

        
// Check in case the user has attempted to page beyond the available range of orders.
        
if ( === $max_num_pages && $this->order_query_args['page'] > ) {
            
$count_query_args          $order_query_args;
            
$count_query_args['page']  = 1;
            
$count_query_args['limit'] = 1;
            
$order_count               wc_get_orders$count_query_args );
            
$max_num_pages             = (int) ceil$order_count->total $order_query_args['limit'] );
        }

        
$this->set_pagination_args(
            array(
                
'total_items' => $orders->total ?? 0,
                
'per_page'    => $limit,
                
'total_pages' => $max_num_pages,
            )
        );

        
// Are we inside the trash?
        
$this->is_trash 'trash' === $this->request['status'];
    }

    
/**
     * Updates the WC Order Query arguments as needed to support orderable columns.
     */
    
private function set_order_args() {
        
$sortable  $this->get_sortable_columns();
        
$field     sanitize_text_fieldwp_unslash$_GET['orderby'] ?? '' ) );
        
$direction strtouppersanitize_text_fieldwp_unslash$_GET['order'] ?? '' ) ) );

        if ( ! 
in_array$field$sortabletrue ) ) {
            
$this->order_query_args['orderby'] = 'date';
            
$this->order_query_args['order']   = 'DESC';
            return;
        }

        
$this->order_query_args['orderby'] = $field;
        
$this->order_query_args['order']   = in_array$direction, array( 'ASC''DESC' ), true ) ? $direction 'ASC';
    }

    
/**
     * Implements date (month-based) filtering.
     */
    
private function set_date_args() {
        
$year_month sanitize_text_fieldwp_unslash$_GET['m'] ?? '' ) );

        if ( empty( 
$year_month ) || ! preg_match'/^[0-9]{6}$/'$year_month ) ) {
            return;
        }

        
$year  = (int) substr$year_month0);
        
$month = (int) substr$year_month4);

        if ( 
$month || $month 12 ) {
            return;
        }

        
$last_day_of_month                      date_create"$year-$month)->format'Y-m-t' );
        
$this->order_query_args['date_created'] = "$year-$month-01..." $last_day_of_month;
        
$this->has_filter                       true;
    }

    
/**
     * Implements filtering of orders by customer.
     */
    
private function set_customer_args() {
        
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
        
$customer = (int) wp_unslash$_GET['_customer_user'] ?? '' );

        if ( 
$customer ) {
            return;
        }

        
$this->order_query_args['customer'] = $customer;
        
$this->has_filter                   true;
    }

    
/**
     * Implements filtering of orders by status.
     */
    
private function set_status_args() {
        
$status array_filterarray_map'trim', (array) $this->request['status'] ) );

        if ( empty( 
$status ) || in_array'all'$statustrue ) ) {
            
/**
             * Allows 3rd parties to set the default list of statuses for a given order type.
             *
             * @param string[] $statuses Statuses.
             *
             * @since 7.3.0
             */
            
$status apply_filters(
                
'woocommerce_' $this->order_type '_list_table_default_statuses',
                
array_intersect(
                    
array_keyswc_get_order_statuses() ),
                    
get_post_stati( array( 'show_in_admin_all_list' => true ), 'names' )
                )
            );
        } else {
            
$this->has_filter true;
        }

        
$this->order_query_args['status'] = $status;
    }

    
/**
     * Implements order search.
     */
    
private function set_search_args(): void {
        
$search_term trimsanitize_text_field$this->request['s'] ) );

        if ( ! empty( 
$search_term ) ) {
            
$this->order_query_args['s'] = $search_term;
            
$this->has_filter            true;
        }

        
$filter trimsanitize_text_field$this->request['search-filter'] ) );
        if ( ! empty( 
$filter ) ) {
            
$this->order_query_args['search_filter'] = $filter;
        }
    }

    
/**
     * Get the list of views for this table (all orders, completed orders, etc, each with a count of the number of
     * corresponding orders).
     *
     * @return array
     */
    
public function get_views() {
        
$view_links = array();

        
/**
         * Filters the list of available list table view links before the actual query runs.
         * This can be used to, e.g., remove counts from the links.
         *
         * @since 8.6.0
         *
         * @param string[] $views An array of available list table view links.
         */
        
$view_links apply_filters'woocommerce_before_' $this->order_type '_list_table_view_links'$view_links );
        if ( ! empty( 
$view_links ) ) {
            return 
$view_links;
        }

        
$view_counts = array();
        
$statuses    $this->get_visible_statuses();
        
$current     = ! empty( $this->request['status'] ) ? sanitize_text_field$this->request['status'] ) : 'all';
        
$all_count   0;

        foreach ( 
array_keys$statuses ) as $slug ) {
            
$total_in_status $this->count_orders_by_status$slug );

            if ( 
$total_in_status ) {
                
$view_counts$slug ] = $total_in_status;
            }

            if ( ( 
get_post_status_object$slug ) )->show_in_admin_all_list && 'auto-draft' !== $slug ) {
                
$all_count += $total_in_status;
            }
        }

        
$view_links['all'] = $this->get_view_link'all'__'All''woocommerce' ), $all_count'' === $current || 'all' === $current );

        foreach ( 
$view_counts as $slug => $count ) {
            
$view_links$slug ] = $this->get_view_link$slug$statuses$slug ], $count$slug === $current );
        }

        return 
$view_links;
    }

    
/**
     * Count orders by status.
     *
     * @param string|string[] $status The order status we are interested in.
     *
     * @return int
     */
    
private function count_orders_by_status$status ): int {
        global 
$wpdb;

        
// Compute all counts and cache if necessary.
        
if ( is_null$this->status_count_cache ) ) {
            
$orders_table OrdersTableDataStore::get_orders_table_name();

            
$res $wpdb->get_results(
                
$wpdb->prepare(
                    
"SELECT status, COUNT(*) AS cnt FROM {$orders_table} WHERE type = %s GROUP BY status"// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
                    
$this->order_type
                
),
                
ARRAY_A
            
);

            
$this->status_count_cache =
                
$res
                
array_combinearray_column$res'status' ), array_map'absint'array_column$res'cnt' ) ) )
                : array();
        }

        
$status = (array) $status;
        
$count  array_sumarray_intersect_key$this->status_count_cachearray_flip$status ) ) );

        
/**
         * Allows 3rd parties to modify the count of orders by status.
         *
         * @param int      $count  Number of orders for the given status.
         * @param string[] $status List of order statuses in the count.
         * @since 7.3.0
         */
        
return apply_filters(
            
'woocommerce_' $this->order_type '_list_table_order_count',
            
$count,
            
$status
        
);
    }

    
/**
     * Checks whether the blank state should be rendered or not. This depends on whether there are others with a visible
     * status.
     *
     * @return boolean TRUE when the blank state should be rendered, FALSE otherwise.
     */
    
private function should_render_blank_state(): bool {
        
/**
         * Whether we should render a blank state so that custom count queries can be used.
         *
         * @since 8.6.0
         *
         * @param null           $should_render_blank_state `null` will use the built-in counts. Sending a boolean will short-circuit that path.
         * @param object         ListTable The current instance of the class.
        */
        
$should_render_blank_state apply_filters(
            
'woocommerce_' $this->order_type '_list_table_should_render_blank_state',
            
null,
            
$this
        
);

        if ( 
is_bool$should_render_blank_state ) ) {
            return 
$should_render_blank_state;
        }

        return ( ! 
$this->has_filter ) && === $this->count_orders_by_statusarray_keys$this->get_visible_statuses() ) );
    }

    
/**
     * Returns a list of slug and labels for order statuses that should be visible in the status list.
     *
     * @return array slug => label array of order statuses.
     */
    
private function get_visible_statuses(): array {
        return 
array_intersect_key(
            
array_merge(
                
wc_get_order_statuses(),
                array(
                    
'trash'      => ( get_post_status_object'trash' ) )->label,
                    
'draft'      => ( get_post_status_object'draft' ) )->label,
                    
'auto-draft' => ( get_post_status_object'auto-draft' ) )->label,
                )
            ),
            
array_flipget_post_stati( array( 'show_in_admin_status_list' => true ) ) )
        );
    }

    
/**
     * Form a link to use in the list of table views.
     *
     * @param string $slug    Slug used to identify the view (usually the order status slug).
     * @param string $name    Human-readable name of the view (usually the order status label).
     * @param int    $count   Number of items in this view.
     * @param bool   $current If this is the current view.
     *
     * @return string
     */
    
private function get_view_linkstring $slugstring $nameint $countbool $current ): string {
        
$base_url get_admin_urlnull'admin.php?page=wc-orders' . ( 'shop_order' === $this->order_type '' '--' $this->order_type ) );
        
$url      esc_urladd_query_arg'status'$slug$base_url ) );
        
$name     esc_html$name );
        
$count    number_format_i18n$count );
        
$class    $current 'class="current"' '';

        return 
"<a href='$url$class>$name <span class='count'>($count)</span></a>";
    }

    
/**
     * Extra controls to be displayed between bulk actions and pagination.
     *
     * @param string $which Either 'top' or 'bottom'.
     */
    
protected function extra_tablenav$which ) {
        echo 
'<div class="alignleft actions">';

        if ( 
'top' === $which ) {
            
ob_start();

            
$this->months_filter();

            
/**
             * Fires before the "Filter" button on the list table for orders and other order types.
             *
             * @since 7.3.0
             *
             * @param string $order_type  The order type.
             * @param string $which       The location of the extra table nav: 'top' or 'bottom'.
             */
            
do_action'woocommerce_order_list_table_restrict_manage_orders'$this->order_type$which );

            
$output ob_get_clean();

            if ( ! empty( 
$output ) ) {
                echo 
$output// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
                
submit_button__'Filter''woocommerce' ), '''filter_action'false, array( 'id' => 'order-query-submit' ) );
            }
        }

        if ( 
$this->is_trash && $this->has_items() && current_user_can'edit_others_shop_orders' ) ) {
            
submit_button__'Empty Trash''woocommerce' ), 'apply''delete_all'false );
        }

        
/**
         * Fires immediately following the closing "actions" div in the tablenav for the order
         * list table.
         *
         * @since 7.3.0
         *
         * @param string $order_type  The order type.
         * @param string $which       The location of the extra table nav: 'top' or 'bottom'.
         */
        
do_action'woocommerce_order_list_table_extra_tablenav'$this->order_type$which );

        echo 
'</div>';
    }

    
/**
     * Render the months filter dropdown.
     *
     * @return void
     */
    
private function months_filter() {
        global 
$wp_locale;

        
// XXX: [review] we may prefer to move this logic outside of the ListTable class.

        /**
         * Filters whether to remove the 'Months' drop-down from the order list table.
         *
         * @since 8.6.0
         *
         * @param bool   $disable   Whether to disable the drop-down. Default false.
         */
        
if ( apply_filters'woocommerce_' $this->order_type '_list_table_disable_months_filter'false ) ) {
            return;
        }

        
$m = isset( $_GET['m'] ) ? (int) $_GET['m'] : 0;
        echo 
'<select name="m" id="filter-by-date">';
        echo 
'<option ' selected$m0false ) . ' value="0">' esc_html__'All dates''woocommerce' ) . '</option>';

        
$order_dates $this->get_and_maybe_update_months_filter_cache();

        foreach ( 
$order_dates as $date ) {
            
$month           zeroise$date->month);
            
$month_year_text sprintf(
                
/* translators: 1: Month name, 2: 4-digit year. */
                
esc_html_x'%1$s %2$d''order dates dropdown''woocommerce' ),
                
$wp_locale->get_month$month ),
                
$date->year
            
);

            
printf(
                
'<option %1$s value="%2$s">%3$s</option>\n',
                
selected$m$date->year $monthfalse ),
                
esc_attr$date->year $month ),
                
esc_html$month_year_text )
            );
        }

        echo 
'</select>';
    }

    
/**
     * Get order year-months cache. We cache the results in the options table, since these results will change very infrequently.
     * We use the heuristic to always return current year-month when getting from cache to prevent an additional query.
     *
     * @return array List of year-months.
     */
    
protected function get_and_maybe_update_months_filter_cache(): array {
        global 
$wpdb;

        
// We cache in the options table since it's won't be invalidated soon.
        
$cache_option_value_name 'wc_' $this->order_type '_list_table_months_filter_cache_value';
        
$cache_option_date_name  'wc_' $this->order_type '_list_table_months_filter_cache_date';

        
$cached_timestamp get_option$cache_option_date_name);

        
// new day, new cache.
        
if ( === $cached_timestamp || gmdate'j'time() ) !== gmdate'j'$cached_timestamp ) || ( time() - $cached_timestamp ) > 60 60 24 ) {
            
$cached_value false;
        } else {
            
$cached_value get_option$cache_option_value_name );
        }

        if ( 
false !== $cached_value ) {
            
// Always add current year month for cache stability. This allows us to not hydrate the cache on every order update.
            
$current_year_month        = new \stdClass();
            
$current_year_month->year  gmdate'Y'time() );
            
$current_year_month->month gmdate'n'time() );
            if ( 
count$cached_value ) === || (
                
$cached_value[0]->year !== $current_year_month->year ||
                
$cached_value[0]->month !== $current_year_month->month )
            ) {
                
array_unshift$cached_value$current_year_month );
            }
            return 
$cached_value;
        }

        
$orders_table esc_sqlOrdersTableDataStore::get_orders_table_name() );
        
$utc_offset   wc_timezone_offset();

        
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
        
$order_dates $wpdb->get_results(
            
$wpdb->prepare(
                
"
                    SELECT DISTINCT YEAR( t.date_created_local ) AS year,
                                    MONTH( t.date_created_local ) AS month
                    FROM ( SELECT DATE_ADD( date_created_gmt, INTERVAL 
$utc_offset SECOND ) AS date_created_local FROM $orders_table WHERE type = %s AND status != 'trash' ) t
                    ORDER BY year DESC, month DESC
                "
,
                
$this->order_type
            
)
        );

        
update_option$cache_option_date_nametime() );
        
update_option$cache_option_value_name$order_dates );

        return 
$order_dates;
    }

    
/**
     * Render the customer filter dropdown.
     *
     * @return void
     */
    
public function customers_filter() {
        
$user_string '';
        
$user_id     '';

        
// phpcs:disable WordPress.Security.NonceVerification.Recommended
        
if ( ! empty( $_GET['_customer_user'] ) ) {
            
$user_id absint$_GET['_customer_user'] );
            
$user    get_user_by'id'$user_id );

            
$user_string sprintf(
                
/* translators: 1: user display name 2: user ID 3: user email */
                
esc_html__'%1$s (#%2$s &ndash; %3$s)''woocommerce' ),
                
$user->display_name,
                
absint$user->ID ),
                
$user->user_email
            
);
        }

        
// Note: use of htmlspecialchars (below) is to prevent XSS when rendered by selectWoo.
        
?>
        <select class="wc-customer-search" name="_customer_user" data-placeholder="<?php esc_attr_e'Filter by registered customer''woocommerce' ); ?>" data-allow_clear="true">
            <option value="<?php echo esc_attr$user_id ); ?>" selected="selected"><?php echo htmlspecialcharswp_kses_post$user_string ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></option>
        </select>
        <?php
    
}

    
/**
     * Get list columns.
     *
     * @return array
     */
    
public function get_columns() {
        
/**
         * Filters the list of columns.
         *
         * @param array $columns List of sortable columns.
         *
         * @since 7.3.0
         */
        
return apply_filters(
            
'woocommerce_' $this->order_type '_list_table_columns',
            array(
                
'cb'               => '<input type="checkbox" />',
                
'order_number'     => esc_html__'Order''woocommerce' ),
                
'order_date'       => esc_html__'Date''woocommerce' ),
                
'order_status'     => esc_html__'Status''woocommerce' ),
                
'billing_address'  => esc_html__'Billing''woocommerce' ),
                
'shipping_address' => esc_html__'Ship to''woocommerce' ),
                
'order_total'      => esc_html__'Total''woocommerce' ),
                
'wc_actions'       => esc_html__'Actions''woocommerce' ),
            )
        );
    }

    
/**
     * Defines the default sortable columns.
     *
     * @return string[]
     */
    
public function get_sortable_columns() {
        
/**
         * Filters the list of sortable columns.
         *
         * @param array $sortable_columns List of sortable columns.
         *
         * @since 7.3.0
         */
        
return apply_filters(
            
'woocommerce_' $this->order_type '_list_table_sortable_columns',
            array(
                
'order_number' => 'ID',
                
'order_date'   => 'date',
                
'order_total'  => 'order_total',
            )
        );
    }

    
/**
     * Specify the columns we wish to hide by default.
     *
     * @param array     $hidden Columns set to be hidden.
     * @param WP_Screen $screen Screen object.
     *
     * @return array
     */
    
public function default_hidden_columns( array $hiddenWP_Screen $screen ) {
        if ( isset( 
$screen->id ) && wc_get_page_screen_id'shop-order' ) === $screen->id ) {
            
$hidden array_merge(
                
$hidden,
                array(
                    
'billing_address',
                    
'shipping_address',
                    
'wc_actions',
                )
            );
        }

        return 
$hidden;
    }

    
/**
     * Checklist column, used for selecting items for processing by a bulk action.
     *
     * @param WC_Order $item The order object for the current row.
     *
     * @return string
     */
    
public function column_cb$item ) {
        
ob_start();
        
?>
        <input id="cb-select-<?php echo esc_attr$item->get_id() ); ?>" type="checkbox" name="id[]" value="<?php echo esc_attr$item->get_id() ); ?>" />

        <div class="locked-indicator">
            <span class="locked-indicator-icon" aria-hidden="true"></span>
            <span class="screen-reader-text">
                <?php
                
// translators: %s is an order ID.
                
echo esc_htmlsprintf__'Order %s is locked.''woocommerce' ), $item->get_id() ) );
                
?>
            </span>
        </div>
        <?php
        
return ob_get_clean();
    }

    
/**
     * Renders the order number, customer name and provides a preview link.
     *
     * @param WC_Order $order The order object for the current row.
     *
     * @return void
     */
    
public function render_order_number_columnWC_Order $order ): void {
        
$buyer '';

        if ( 
$order->get_billing_first_name() || $order->get_billing_last_name() ) {
            
/* translators: 1: first name 2: last name */
            
$buyer trimsprintf_x'%1$s %2$s''full name''woocommerce' ), $order->get_billing_first_name(), $order->get_billing_last_name() ) );
        } elseif ( 
$order->get_billing_company() ) {
            
$buyer trim$order->get_billing_company() );
        } elseif ( 
$order->get_customer_id() ) {
            
$user  get_user_by'id'$order->get_customer_id() );
            
$buyer ucwords$user->display_name );
        }

        
/**
         * Filter buyer name in list table orders.
         *
         * @since 3.7.0
         *
         * @param string   $buyer Buyer name.
         * @param WC_Order $order Order data.
         */
        
$buyer apply_filters'woocommerce_admin_order_buyer_name'$buyer$order );

        if ( 
$order->get_status() === 'trash' ) {
            echo 
'<strong>#' esc_attr$order->get_order_number() ) . ' ' esc_html$buyer ) . '</strong>';
        } else {
            echo 
'<a href="#" class="order-preview" data-order-id="' absint$order->get_id() ) . '" title="' esc_attr__'Preview''woocommerce' ) ) . '">' esc_html__'Preview''woocommerce' ) ) . '</a>';
            echo 
'<a href="' esc_url$this->get_order_edit_link$order ) ) . '" class="order-view"><strong>#' esc_attr$order->get_order_number() ) . ' ' esc_html$buyer ) . '</strong></a>';
        }

        
// Used for showing date & status next to order number/buyer name on small screens.
        
echo '<div class="order_date small-screen-only">';
        
$this->render_order_date_column$order );
        echo 
'</div>';
        echo 
'<div class="order_status small-screen-only">';
        
$this->render_order_status_column$order );
        echo 
'</div>';
    }

    
/**
     * Get the edit link for an order.
     *
     * @param WC_Order $order Order object.
     *
     * @return string Edit link for the order.
     */
    
private function get_order_edit_linkWC_Order $order ): string {
        return 
$this->page_controller->get_edit_url$order->get_id() );
    }

    
/**
     * Renders the order date.
     *
     * @param WC_Order $order The order object for the current row.
     *
     * @return void
     */
    
public function render_order_date_columnWC_Order $order ): void {
        
$order_timestamp $order->get_date_created() ? $order->get_date_created()->getTimestamp() : '';

        if ( ! 
$order_timestamp ) {
            echo 
'&ndash;';
            return;
        }

        
// Check if the order was created within the last 24 hours, and not in the future.
        
if ( $order_timestamp strtotime'-1 day'time() ) && $order_timestamp <= time() ) {
            
$show_date sprintf(
            
/* translators: %s: human-readable time difference */
                
_x'%s ago''%s = human-readable time difference''woocommerce' ),
                
human_time_diff$order->get_date_created()->getTimestamp(), time() )
            );
        } else {
            
$show_date $order->get_date_created()->date_i18napply_filters'woocommerce_admin_order_date_format'__'M j, Y''woocommerce' ) ) ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
        
}
        
printf(
            
'<time datetime="%1$s" title="%2$s">%3$s</time>',
            
esc_attr$order->get_date_created()->date'c' ) ),
            
esc_html$order->get_date_created()->date_i18nget_option'date_format' ) . ' ' get_option'time_format' ) ) ),
            
esc_html$show_date )
        );
    }

    
/**
     * Renders the order status.
     *
     * @param WC_Order $order The order object for the current row.
     *
     * @return void
     */
    
public function render_order_status_columnWC_Order $order ): void {
        
/* translators: %s: order status label */
        
$tooltip wc_sanitize_tooltip$this->get_order_status_label$order ) );

        
// Gracefully handle legacy statuses.
        
if ( in_array$order->get_status(), array( 'trash''draft''auto-draft' ), true ) ) {
            
$status_name = ( get_post_status_object$order->get_status() ) )->label;
        } else {
            
$status_name wc_get_order_status_name$order->get_status() );
        }

        if ( 
$tooltip ) {
            
printf'<mark class="order-status %s tips" data-tip="%s"><span>%s</span></mark>'esc_attrsanitize_html_class'status-' $order->get_status() ) ), wp_kses_post$tooltip ), esc_html$status_name ) );
        } else {
            
printf'<mark class="order-status %s"><span>%s</span></mark>'esc_attrsanitize_html_class'status-' $order->get_status() ) ), esc_html$status_name ) );
        }
    }

    
/**
     * Gets the order status label for an order.
     *
     * @param WC_Order $order The order object.
     *
     * @return string
     */
    
private function get_order_status_labelWC_Order $order ): string {
        
$status_names = array(
            
'pending'        => __'The order has been received, but no payment has been made. Pending payment orders are generally awaiting customer action.''woocommerce' ),
            
'on-hold'        => __'The order is awaiting payment confirmation. Stock is reduced, but you need to confirm payment.''woocommerce' ),
            
'processing'     => __'Payment has been received (paid), and the stock has been reduced. The order is awaiting fulfillment.''woocommerce' ),
            
'completed'      => __'Order fulfilled and complete.''woocommerce' ),
            
'failed'         => __'The customer’s payment failed or was declined, and no payment has been successfully made.''woocommerce' ),
            
'checkout-draft' => __'Draft orders are created when customers start the checkout process while the block version of the checkout is in place.''woocommerce' ),
            
'cancelled'      => __'The order was canceled by an admin or the customer.''woocommerce' ),
            
'refunded'       => __'Orders are automatically put in the Refunded status when an admin or shop manager has fully refunded the order’s value after payment.''woocommerce' ),
        );

        
/**
         * Provides an opportunity to modify and extend the order status labels.
         *
         * @param array    $action Order actions.
         * @param WC_Order $order  Current order object.
         * @since 9.1.0
         */
        
$status_names apply_filters'woocommerce_get_order_status_labels'$status_names$order );

        
$status_name $order->get_status();

        return isset( 
$status_names$status_name ] ) ? $status_names$status_name ] : '';
    }

    
/**
     * Renders order billing information.
     *
     * @param WC_Order $order The order object for the current row.
     *
     * @return void
     */
    
public function render_billing_address_columnWC_Order $order ): void {
        
$address $order->get_formatted_billing_address();

        if ( 
$address ) {
            echo 
esc_htmlpreg_replace'#<br\s*/?>#i'', '$address ) );

            if ( 
$order->get_payment_method() ) {
                
/* translators: %s: payment method */
                
echo '<span class="description">' sprintfesc_html__'via %s''woocommerce' ), esc_html$order->get_payment_method_title() ) ) . '</span>';
            }
        } else {
            echo 
'&ndash;';
        }
    }

    
/**
     * Renders order shipping information.
     *
     * @param WC_Order $order The order object for the current row.
     *
     * @return void
     */
    
public function render_shipping_address_columnWC_Order $order ): void {
        
$address $order->get_formatted_shipping_address();

        if ( 
$address ) {
            echo 
'<a target="_blank" href="' esc_url$order->get_shipping_address_map_url() ) . '">' esc_htmlpreg_replace'#<br\s*/?>#i'', '$address ) ) . '</a>';
            if ( 
$order->get_shipping_method() ) {
                
/* translators: %s: shipping method */
                
echo '<span class="description">' sprintfesc_html__'via %s''woocommerce' ), esc_html$order->get_shipping_method() ) ) . '</span>';
            }
        } else {
            echo 
'&ndash;';
        }
    }

    
/**
     * Renders the order total.
     *
     * @param WC_Order $order The order object for the current row.
     *
     * @return void
     */
    
public function render_order_total_columnWC_Order $order ): void {
        if ( 
$order->get_payment_method_title() ) {
            
/* translators: %s: method */
            
echo '<span class="tips" data-tip="' esc_attrsprintf__'via %s''woocommerce' ), $order->get_payment_method_title() ) ) . '">' wp_kses_post$order->get_formatted_order_total() ) . '</span>';
        } else {
            echo 
wp_kses_post$order->get_formatted_order_total() );
        }
    }

    
/**
     * Renders order actions.
     *
     * @param WC_Order $order The order object for the current row.
     *
     * @return void
     */
    
public function render_wc_actions_columnWC_Order $order ): void {
        echo 
'<p>';

        
/**
         * Fires before the order action buttons (within the actions column for the order list table)
         * are registered.
         *
         * @param WC_Order $order Current order object.
         * @since 6.7.0
         */
        
do_action'woocommerce_admin_order_actions_start'$order );

        
$actions = array();

        if ( 
$order->has_status( array( 'pending''on-hold' ) ) ) {
            
$actions['processing'] = array(
                
'url'    => wp_nonce_urladmin_url'admin-ajax.php?action=woocommerce_mark_order_status&status=processing&order_id=' $order->get_id() ), 'woocommerce-mark-order-status' ),
                
'name'   => __'Processing''woocommerce' ),
                
'action' => 'processing',
            );
        }

        if ( 
$order->has_status( array( 'pending''on-hold''processing' ) ) ) {
            
$actions['complete'] = array(
                
'url'    => wp_nonce_urladmin_url'admin-ajax.php?action=woocommerce_mark_order_status&status=completed&order_id=' $order->get_id() ), 'woocommerce-mark-order-status' ),
                
'name'   => __'Complete''woocommerce' ),
                
'action' => 'complete',
            );
        }

        
/**
         * Provides an opportunity to modify the action buttons within the order list table.
         *
         * @param array    $action Order actions.
         * @param WC_Order $order  Current order object.
         * @since 6.7.0
         */
        
$actions apply_filters'woocommerce_admin_order_actions'$actions$order );

        
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
        
echo wc_render_action_buttons$actions );

        
/**
         * Fires after the order action buttons (within the actions column for the order list table)
         * are rendered.
         *
         * @param WC_Order $order Current order object.
         * @since 6.7.0
         */
        
do_action'woocommerce_admin_order_actions_end'$order );

        echo 
'</p>';
    }

    
/**
     * Outputs hidden fields used to retain state when filtering.
     *
     * @return void
     */
    
private function print_hidden_form_fields(): void {
        echo 
'<input type="hidden" name="page" value="wc-orders' . ( 'shop_order' === $this->order_type '' '--' $this->order_type ) . '" >'// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

        
$state_params = array(
            
'paged',
            
'status',
        );

        foreach ( 
$state_params as $param ) {
            if ( ! isset( 
$_GET$param ] ) ) {
                continue;
            }

            echo 
'<input type="hidden" name="' esc_attr$param ) . '" value="' esc_attrsanitize_text_fieldwp_unslash$_GET$param ] ) ) ) . '" >';
        }
    }

    
/**
     * Gets the current action selected from the bulk actions dropdown.
     *
     * @return string|false The action name. False if no action was selected.
     */
    
public function current_action() {
        if ( ! empty( 
$_REQUEST['delete_all'] ) ) {
            return 
'delete_all';
        }

        return 
parent::current_action();
    }

    
/**
     * Handle bulk actions.
     */
    
public function handle_bulk_actions() {
        
$action $this->current_action();

        if ( ! 
$action ) {
            return;
        }

        
check_admin_referer'bulk-orders' );

        
$redirect_to remove_query_arg( array( 'deleted''ids' ), wp_get_referer() );
        
$redirect_to add_query_arg'paged'$this->get_pagenum(), $redirect_to );

        if ( 
'delete_all' === $action ) {
            
// Get all trashed orders.
            
$ids wc_get_orders(
                array(
                    
'type'   => $this->order_type,
                    
'status' => 'trash',
                    
'limit'  => -1,
                    
'return' => 'ids',
                )
            );

            
$action 'delete';
        } else {
            
$ids = isset( $_REQUEST['id'] ) ? array_reversearray_map'absint', (array) $_REQUEST['id'] ) ) : array();
        }

        
/**
         * Allows 3rd parties to modify order IDs about to be affected by a bulk action.
         *
         * @param array Array of order IDs.
         */
        
$ids apply_filters// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingSinceComment
            
'woocommerce_bulk_action_ids',
            
$ids,
            
$action,
            
'order'
        
);

        if ( ! 
$ids ) {
            
wp_safe_redirect$redirect_to );
            exit;
        }

        
$report_action  '';
        
$changed        0;
        
$action_handled true;

        if ( 
'remove_personal_data' === $action ) {
            
$report_action 'removed_personal_data';
            
$changed       $this->do_bulk_action_remove_personal_data$ids );
        } elseif ( 
'trash' === $action ) {
            
$changed       $this->do_delete$ids );
            
$report_action 'trashed';
        } elseif ( 
'delete' === $action ) {
            
$changed       $this->do_delete$idstrue );
            
$report_action 'deleted';
        } elseif ( 
'untrash' === $action ) {
            
$changed       $this->do_untrash$ids );
            
$report_action 'untrashed';
        } elseif ( 
false !== strpos$action'mark_' ) ) {
            
$order_statuses wc_get_order_statuses();
            
$new_status     substr$action);
            
$report_action  'marked_' $new_status;

            if ( isset( 
$order_statuses'wc-' $new_status ] ) ) {
                
$changed $this->do_bulk_action_mark_orders$ids$new_status );
            } else {
                
$action_handled false;
            }
        } else {
            
$action_handled false;
        }

        
// Custom action.
        
if ( ! $action_handled ) {
            
$screen get_current_screen()->id;

            
/**
             * This action is documented in /wp-admin/edit.php (it is a core WordPress hook).
             *
             * @since 7.2.0
             *
             * @param string $redirect_to The URL to redirect to after processing the bulk actions.
             * @param string $action      The current bulk action.
             * @param int[]  $ids         IDs for the orders to be processed.
             */
            
$custom_sendback apply_filters"handle_bulk_actions-{$screen}"$redirect_to$action$ids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
        
}

        if ( ! empty( 
$custom_sendback ) ) {
            
$redirect_to $custom_sendback;
        } elseif ( 
$changed ) {
            
$redirect_to add_query_arg(
                array(
                    
'bulk_action' => $report_action,
                    
'changed'     => $changed,
                    
'ids'         => implode','$ids ),
                ),
                
$redirect_to
            
);
        }

        
wp_safe_redirect$redirect_to );
        exit;
    }

    
/**
     * Implements the "remove personal data" bulk action.
     *
     * @param array $order_ids The Order IDs.
     * @return int Number of orders modified.
     */
    
private function do_bulk_action_remove_personal_data$order_ids ): int {
        
$changed 0;

        foreach ( 
$order_ids as $id ) {
            
$order wc_get_order$id );

            if ( ! 
$order ) {
                continue;
            }

            
do_action'woocommerce_remove_order_personal_data'$order ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
            
++$changed;
        }

        return 
$changed;
    }

    
/**
     * Implements the "mark <status>" bulk action.
     *
     * @param array  $order_ids  The order IDs to change.
     * @param string $new_status The new order status.
     * @return int Number of orders modified.
     */
    
private function do_bulk_action_mark_orders$order_ids$new_status ): int {
        
$changed 0;

        
// Initialize payment gateways in case order has hooked status transition actions.
        
WC()->payment_gateways();

        foreach ( 
$order_ids as $id ) {
            
$order wc_get_order$id );

            if ( ! 
$order ) {
                continue;
            }

            
$order->update_status$new_status__'Order status changed by bulk edit.''woocommerce' ), true );
            
do_action'woocommerce_order_edit_status'$id$new_status ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
            
++$changed;
        }

        return 
$changed;
    }

    
/**
     * Handles bulk trashing of orders.
     *
     * @param int[] $ids Order IDs to be trashed.
     * @param bool  $force_delete When set, the order will be completed deleted. Otherwise, it will be trashed.
     *
     * @return int Number of orders that were trashed.
     */
    
private function do_delete( array $idsbool $force_delete false ): int {
        
$changed 0;

        foreach ( 
$ids as $id ) {
            
$order wc_get_order$id );
            
$order->delete$force_delete );
            
$updated_order wc_get_order$id );

            if ( ( 
$force_delete && false === $updated_order ) || ( ! $force_delete && $updated_order->get_status() === 'trash' ) ) {
                ++
$changed;
            }
        }

        return 
$changed;
    }

    
/**
     * Handles bulk restoration of trashed orders.
     *
     * @param array $ids Order IDs to be restored to their previous status.
     *
     * @return int Number of orders that were restored from the trash.
     */
    
private function do_untrash( array $ids ): int {
        
$orders_store wc_get_container()->getOrdersTableDataStore::class );
        
$changed      0;

        foreach ( 
$ids as $id ) {
            if ( 
$orders_store->untrash_orderwc_get_order$id ) ) ) {
                ++
$changed;
            }
        }

        return 
$changed;
    }

    
/**
     * Show confirmation message that order status changed for number of orders.
     */
    
public function bulk_action_notices() {
        if ( empty( 
$_REQUEST['bulk_action'] ) ) {
            return;
        }

        
$order_statuses wc_get_order_statuses();
        
$number         absint$_REQUEST['changed'] ?? );
        
$bulk_action    wc_cleanwp_unslash$_REQUEST['bulk_action'] ) );
        
$message        '';

        
// Check if any status changes happened.
        
foreach ( $order_statuses as $slug => $name ) {
            if ( 
'marked_' str_replace'wc-'''$slug ) === $bulk_action ) { // WPCS: input var ok, CSRF ok.
                /* translators: %s: orders count */
                
$message sprintf_n'%s order status changed.''%s order statuses changed.'$number'woocommerce' ), number_format_i18n$number ) );
                break;
            }
        }

        switch ( 
$bulk_action ) {
            case 
'removed_personal_data':
                
/* translators: %s: orders count */
                
$message sprintf_n'Removed personal data from %s order.''Removed personal data from %s orders.'$number'woocommerce' ), number_format_i18n$number ) );
                echo 
'<div class="updated"><p>' esc_html$message ) . '</p></div>';
                break;

            case 
'trashed':
                
/* translators: %s: orders count */
                
$message sprintf_n'%s order moved to the Trash.''%s orders moved to the Trash.'$number'woocommerce' ), number_format_i18n$number ) );
                break;

            case 
'untrashed':
                
/* translators: %s: orders count */
                
$message sprintf_n'%s order restored from the Trash.''%s orders restored from the Trash.'$number'woocommerce' ), number_format_i18n$number ) );
                break;

            case 
'deleted':
                
/* translators: %s: orders count */
                
$message sprintf_n'%s order permanently deleted.''%s orders permanently deleted.'$number'woocommerce' ), number_format_i18n$number ) );
                break;
        }

        if ( ! empty( 
$message ) ) {
            echo 
'<div class="updated"><p>' esc_html$message ) . '</p></div>';
        }
    }

    
/**
     * Enqueue list table scripts.
     *
     * @return void
     */
    
public function enqueue_scripts(): void {
        echo 
$this->get_order_preview_template(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
        
wp_enqueue_script'wc-orders' );
    }

    
/**
     * Returns the HTML for the order preview template.
     *
     * @return string HTML template.
     */
    
public function get_order_preview_template(): string {
        
$order_edit_url_placeholder =
            
wc_get_container()->getCustomOrdersTableController::class )->custom_orders_table_usage_is_enabled()
            ? 
esc_urladmin_url'admin.php?page=wc-orders&action=edit' ) ) . '&id={{ data.data.id }}'
            
esc_urladmin_url'post.php?action=edit' ) ) . '&post={{ data.data.id }}';

        
ob_start();
        
?>
        <script type="text/template" id="tmpl-wc-modal-view-order">
            <div class="wc-backbone-modal wc-order-preview">
                <div class="wc-backbone-modal-content">
                    <section class="wc-backbone-modal-main" role="main">
                        <header class="wc-backbone-modal-header">
                            <mark class="order-status status-{{ data.status }}"><span>{{ data.status_name }}</span></mark>
                            <?php /* translators: %s: order ID */ ?>
                            <h1><?php echo esc_htmlsprintf__'Order #%s''woocommerce' ), '{{ data.order_number }}' ) ); ?></h1>
                            <button class="modal-close modal-close-link dashicons dashicons-no-alt">
                                <span class="screen-reader-text"><?php esc_html_e'Close modal panel''woocommerce' ); ?></span>
                            </button>
                        </header>
                        <article>
                            <?php do_action'woocommerce_admin_order_preview_start' ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment ?>

                            <div class="wc-order-preview-addresses">
                                <div class="wc-order-preview-address">
                                    <h2><?php esc_html_e'Billing details''woocommerce' ); ?></h2>
                                    {{{ data.formatted_billing_address }}}

                                    <# if ( data.data.billing.email ) { #>
                                        <strong><?php esc_html_e'Email''woocommerce' ); ?></strong>
                                        <a href="mailto:{{ data.data.billing.email }}">{{ data.data.billing.email }}</a>
                                    <# } #>

                                    <# if ( data.data.billing.phone ) { #>
                                        <strong><?php esc_html_e'Phone''woocommerce' ); ?></strong>
                                        <a href="tel:{{ data.data.billing.phone }}">{{ data.data.billing.phone }}</a>
                                    <# } #>

                                    <# if ( data.payment_via ) { #>
                                        <strong><?php esc_html_e'Payment via''woocommerce' ); ?></strong>
                                        {{{ data.payment_via }}}
                                    <# } #>
                                </div>
                                <# if ( data.needs_shipping ) { #>
                                    <div class="wc-order-preview-address">
                                        <h2><?php esc_html_e'Shipping details''woocommerce' ); ?></h2>
                                        <# if ( data.ship_to_billing ) { #>
                                            {{{ data.formatted_billing_address }}}
                                        <# } else { #>
                                            <a href="{{ data.shipping_address_map_url }}" target="_blank">{{{ data.formatted_shipping_address }}}</a>
                                        <# } #>

                                        <# if ( data.data.shipping.phone ) { #>
                                            <strong><?php esc_html_e'Phone''woocommerce' ); ?></strong>
                                            <a href="tel:{{ data.data.shipping.phone }}">{{ data.data.shipping.phone }}</a>
                                        <# } #>

                                        <# if ( data.shipping_via ) { #>
                                            <strong><?php esc_html_e'Shipping method''woocommerce' ); ?></strong>
                                            {{ data.shipping_via }}
                                        <# } #>
                                    </div>
                                <# } #>

                                <# if ( data.data.customer_note ) { #>
                                    <div class="wc-order-preview-note">
                                        <strong><?php esc_html_e'Note''woocommerce' ); ?></strong>
                                        {{ data.data.customer_note }}
                                    </div>
                                <# } #>
                            </div>

                            {{{ data.item_html }}}

                            <?php do_action'woocommerce_admin_order_preview_end' ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment ?>
                        </article>
                        <footer>
                            <div class="inner">
                                {{{ data.actions_html }}}

                                <a class="button button-primary button-large" aria-label="<?php esc_attr_e'Edit this order''woocommerce' ); ?>" href="<?php echo $order_edit_url_placeholder// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>"><?php esc_html_e'Edit''woocommerce' ); ?></a>
                            </div>
                        </footer>
                    </section>
                </div>
            </div>
            <div class="wc-backbone-modal-backdrop modal-close"></div>
        </script>
        <?php

        $html 
ob_get_clean();

        return 
$html;
    }

    
/**
     * Renders the search box with various options to limit order search results.
     *
     * @param string $text The search button text.
     * @param string $input_id The search input ID.
     *
     * @return void
     */
    
public function search_box$text$input_id ) {
        if ( empty( 
$_REQUEST['s'] ) && ! $this->has_items() ) {
            return;
        }

        
$input_id $input_id '-search-input';

        if ( ! empty( 
$_REQUEST['orderby'] ) ) {
            echo 
'<input type="hidden" name="orderby" value="' esc_attrsanitize_text_fieldwp_unslash$_REQUEST['orderby'] ) ) ) . '" />';
        }
        if ( ! empty( 
$_REQUEST['order'] ) ) {
            echo 
'<input type="hidden" name="order" value="' esc_attrsanitize_text_fieldwp_unslash$_REQUEST['order'] ) ) ) . '" />';
        }
        
?>
        <p class="search-box">
            <label class="screen-reader-text" for="<?php echo esc_attr$input_id ); ?>"><?php echo esc_html$text ); ?>:</label>
            <input type="search" id="<?php echo esc_attr$input_id ); ?>" name="s" value="<?php _admin_search_query(); ?>" />
            <?php $this->search_filter(); ?>
            <?php submit_button$text''''false, array( 'id' => 'search-submit' ) ); ?>
        </p>
        <?php
    
}

    
/**
     * Renders the search filter dropdown.
     *
     * @return void
     */
    
private function search_filter() {
        
$options = array(
            
'order_id'       => __'Order ID''woocommerce' ),
            
'customer_email' => __'Customer Email''woocommerce' ),
            
'customers'      => __'Customers''woocommerce' ),
            
'products'       => __'Products''woocommerce' ),
            
'all'            => __'All''woocommerce' ),
        );

        
/**
         * Filters the search filters available in the admin order search. Can be used to add new or remove existing filters.
         * When adding new filters, `woocommerce_hpos_generate_where_for_search_filter` should also be used to generate the WHERE clause for the new filter
         *
         * @since 8.9.0.
         *
         * @param $options array List of available filters.
         */
        
$options       apply_filters'woocommerce_hpos_admin_search_filters'$options );
        
$saved_setting get_user_setting'wc-search-filter-hpos-admin''all' );
        
$selected      sanitize_text_fieldwp_unslash$_REQUEST['search-filter'] ?? $saved_setting ) );
        if ( 
$saved_setting !== $selected ) {
            
set_user_setting'wc-search-filter-hpos-admin'$selected );
        }
        
?>
        <select name="search-filter" id="order-search-filter">
            <?php foreach ( $options as $value => $label ) { ?>
                <option value="<?php echo esc_attrwp_unslashsanitize_text_field$value ) ) ); ?><?php selected$valuesanitize_text_fieldwp_unslash$selected ) ) ); ?>><?php echo esc_html$label ); ?></option>
            <?php ?>
        </select>
        <?php
    
}
}