/var/www/html_us/wp-content/plugins/checkout-for-woocommerce/sources/php/functions.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
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
<?php

use Objectiv\Plugins\Checkout\Adapters\ItemsAdapter;
use 
Objectiv\Plugins\Checkout\FormAugmenter;
use 
Objectiv\Plugins\Checkout\Model\Item;
use 
Objectiv\Plugins\Checkout\Model\Template;
use 
Objectiv\Plugins\Checkout\Main;
use 
Objectiv\Plugins\Checkout\Managers\SettingsManager;
use 
Objectiv\Plugins\Checkout\Managers\UpdatesManager;
use 
Objectiv\Plugins\Checkout\Managers\PlanManager;
use 
Objectiv\Plugins\Checkout\Managers\AssetManager;
use 
Objectiv\Plugins\Checkout\Loaders\Content;
use 
Objectiv\Plugins\Checkout\Loaders\Redirect;

/**
 * @deprecated
 * @return Main|null
 */
function cfw_get_main() {
    
_deprecated_function'cfw_get_main''CheckoutWC 5.0.0' );
    return 
Main::instance();
}

/**
 * Outputs a checkout/address form field.
 *
 * @param string $key
 * @param mixed $args
 * @param mixed $value (default: null)
 *
 * @return mixed|void
 */
function cfw_form_fieldstring $key$args$value null ) {
    
$defaults = array(
        
'type'              => 'text',
        
'label'             => '',
        
'description'       => '',
        
'placeholder'       => '',
        
'maxlength'         => false,
        
'required'          => false,
        
'autocomplete'      => false,
        
'id'                => $key,
        
'class'             => array(),
        
'label_class'       => array(),
        
'input_class'       => array(),
        
'return'            => false,
        
'options'           => array(),
        
'custom_attributes' => array(),
        
'validate'          => array(),
        
'default'           => '',
        
'autofocus'         => '',
        
'priority'          => '',
        
'wrap'              => '',
        
'columns'           => 12,
    );

    
$key_sans_type    cfw_strip_key_type$key );
    
$ship_or_bill_key explode'_'$key )[0];

    
$args wp_parse_args$args$defaults );
    
$args apply_filters'woocommerce_form_field_args'$args$key$value );

    if ( 
in_array$ship_or_bill_key, array( 'shipping''billing' ), true ) && empty( $args['custom_attributes']['data-parsley-group'] ) ) {
        
$args['custom_attributes']['data-parsley-group'] = $ship_or_bill_key;
    }

    
$required '';

    
// If we don't have a placeholder, use label
    
if ( empty( $args['placeholder'] ) ) {
        
$args['placeholder'] = $args['label'];
    }

    
// If we don't have a wrap, add one and set start and end to a presumed true
    
if ( empty( $args['wrap'] ) ) {
        
$args FormAugmenter::instance()->calculate_wrap$argstrue );
    }

    if ( 
$args['required'] ) {
        
$args['class'][] = 'validate-required';
    } else {
        
$required '&nbsp;<span class="optional">(' cfw_esc_html__'optional''woocommerce' ) . ')</span>';

        
// We don't need to do this for address_2 because
        // it is handled by address-i18n.js
        
if (
            
'address_2' !== $key_sans_type &&
            
stripos$args['placeholder'], cfw_esc_html__'optional''woocommerce' ) ) === false &&
            
apply_filters'cfw_form_field_append_optional_to_placeholder'true$key )
        ) {
            
$args['placeholder'] = $args['placeholder'] . ' (' cfw_esc_html__'optional''woocommerce' ) . ')';
        }
    }

    if ( 
is_string$args['label_class'] ) ) {
        
$args['label_class'] = array( $args['label_class'] );
    }

    if ( 
is_null$value ) ) {
        
$value $args['default'];
    } else {
        
$args['custom_attributes']['data-persist'] = 'false';
    }

    
// Custom attribute handling
    
$custom_attributes = array();

    
/**
     * Normally WooCommerce nukes empty attributes
     * We can't do that because of our field syncing stuff,
     * so we are going to specifically fix readonly attributes here
     */
    
if ( isset( $args['custom_attributes']['readonly'] ) && strlen$args['custom_attributes']['readonly'] ) === ) {
        unset( 
$args['custom_attributes']['readonly'] );
    }

    if ( 
$args['maxlength'] ) {
        
$args['custom_attributes']['maxlength'] = absint$args['maxlength'] );
    }

    if ( ! empty( 
$args['autocomplete'] ) ) {
        if ( 
=== stripos$key'billing_' ) ) {
            
$args['autocomplete'] = "billing {$args['autocomplete']}";
        } elseif ( 
=== stripos$key'shipping_' ) ) {
            
$args['autocomplete'] = "shipping {$args['autocomplete']}";
        }

        
$args['custom_attributes']['autocomplete'] = $args['autocomplete'];
    }

    if ( 
true === $args['autofocus'] ) {
        
$args['custom_attributes']['autofocus'] = 'autofocus';
    }

    if ( 
$args['description'] ) {
        
$args['custom_attributes']['aria-describedby'] = $args['id'] . '-description';
    }

    if ( ! empty( 
$args['custom_attributes'] ) && is_array$args['custom_attributes'] ) ) {
        foreach ( 
$args['custom_attributes'] as $attribute => $attribute_value ) {
            
$custom_attributes[] = esc_attr$attribute ) . '="' esc_attr$attribute_value ) . '"';
        }
    }

    if ( ! empty( 
$args['validate'] ) ) {
        foreach ( 
$args['validate'] as $validate ) {
            
$args['class'][] = 'validate-' $validate;
        }
    }

    
$field                 '';
    
$label_id              $args['id'];
    
$field_container_start '';

    if ( isset( 
$args['wrap'] ) && ! empty( $args['wrap'] ) ) {
        
$field_container_start $args['wrap']->start $args['wrap']->end;
    }

    
$parsley_out '';

    if ( 
$args['required'] ) {
        
$parsley_out 'data-parsley-required="true"';
    } else {
        
$parsley_out 'data-parsley-required="false"';
    }

    if ( 
'hidden' === $args['type'] ) {
        
$args['start'] = false;
        
$args['end']   = false;
    }

    switch ( 
$args['type'] ) {
        case 
'country':
            
$countries 'shipping_country' === $key WC()->countries->get_shipping_countries() : WC()->countries->get_allowed_countries();

            
$field '<select field_key="' $key_sans_type '" name="' esc_attr$key ) . '" id="' esc_attr$args['id'] ) . '" class="country_to_state ' esc_attrimplode' '$args['input_class'] ) ) . '" ' implode' '$custom_attributes ) . $parsley_out '>' '<option value="">' esc_html__'Select a country''checkout-wc' ) . '&hellip;</option>';

            
/**
             * Filter highlighted countries
             *
             * @since 2.0.0
             *
             * @param array $highlighted_countries Highlighted countries in country dropdown
             */
            
$highlighted_countries array_flipapply_filters'cfw_highlighted_countries', array() ) );
            
$count                 1;

            if ( ! empty( 
$highlighted_countries ) ) {
                
$countries array_merge$highlighted_countries$countries );
            }

            foreach ( 
$countries as $ckey => $cvalue ) {
                
$field .= '<option value="' esc_attr$ckey ) . '" ' selected$value$ckeyfalse ) . '>' $cvalue '</option>';

                if ( ! empty( 
$highlighted_countries ) && count$highlighted_countries ) === $count ) {
                    
$field .= '<option disabled="disabled" value="---">---</option>';
                }

                
$count++;
            }

            
$field .= '</select>';

            
$field .= '<noscript><input type="submit" name="woocommerce_checkout_update_totals" value="' cfw_esc_attr__'Update country''woocommerce' ) . '" /></noscript>';

            break;
        case 
'state':
            
/* Get Country */
            
$country_key 'billing_state' === $key 'billing_country' 'shipping_country';
            
$current_cc  WC()->checkout()->get_value$country_key );
            
$states      WC()->countries->get_states$current_cc );

            if ( 
is_array$states ) && empty( $states ) ) {

                
$field_container_start '<div class="col-lg-4 address-field %3$s" id="%1$s"><div class="cfw-input-wrap">%2$s</div></div>';

                
$field .= '<input type="hidden" field_key="' $key_sans_type '" class="hidden" name="' esc_attr$key ) . '" id="' esc_attr$args['id'] ) . '" value="" ' implode' '$custom_attributes ) . ' placeholder="' esc_attr$args['placeholder'] ) . '" />';

            } elseif ( ! 
is_null$current_cc ) && is_array$states ) ) {

                
$field .= '<select field_key="' $key_sans_type '" name="' esc_attr$key ) . '" id="' esc_attr$args['id'] ) . '" class="' esc_attrimplode' '$args['input_class'] ) ) . '" ' implode' '$custom_attributes ) . $parsley_out ' data-placeholder="' esc_attr$args['placeholder'] ) . '">
                    <option value="">' 
cfw_esc_html__'Select an option&hellip;''woocommerce' ) . '</option>';

                foreach ( 
$states as $ckey => $cvalue ) {
                    
$field .= '<option value="' esc_attr$ckey ) . '" ' selected$value$ckeyfalse ) . '>' $cvalue '</option>';
                }

                
$field .= '</select>';

            } else {

                
$field .= '<input ' $parsley_out ' field_key="' $key_sans_type '" type="text" class="input-text ' esc_attrimplode' '$args['input_class'] ) ) . '" value="' esc_attr$value ) . '"  placeholder="' esc_attr$args['placeholder'] ) . '" name="' esc_attr$key ) . '" id="' esc_attr$args['id'] ) . '" ' implode' '$custom_attributes ) . ' />';

            }

            break;
        case 
'textarea':
            
$field .= '<textarea name="' esc_attr$key ) . '" class="input-text ' esc_attrimplode' '$args['input_class'] ) ) . '" id="' esc_attr$args['id'] ) . '" placeholder="' esc_attr$args['placeholder'] ) . '" ' . ( empty( $args['custom_attributes']['rows'] ) ? ' rows="2"' '' ) . ( empty( $args['custom_attributes']['cols'] ) ? ' cols="5"' '' ) . implode' '$custom_attributes ) . $parsley_out '>' esc_textarea$value ) . '</textarea>';

            break;
        case 
'checkbox':
            
$field '<label class="checkbox ' implode' '$args['label_class'] ) . '" ' implode' '$custom_attributes ) . '>
                    <input type="' 
esc_attr$args['type'] ) . '" class="input-checkbox ' esc_attrimplode' '$args['input_class'] ) ) . '" name="' esc_attr$key ) . '" id="' esc_attr$args['id'] ) . '" value="1" ' checked$value1false ) . implode' '$custom_attributes ) . ' />'
                     
$args['label'] . $required '</label>';

            break;
        case 
'password':
        case 
'text':
        case 
'hidden':
        case 
'email':
        case 
'tel':
        case 
'number':
            
$field .= '<input type="' esc_attr$args['type'] ) . '" field_key="' $key_sans_type '" class="input-text ' esc_attrimplode' '$args['input_class'] ) ) . '" name="' esc_attr$key ) . '" id="' esc_attr$args['id'] ) . '" placeholder="' esc_attr$args['placeholder'] ) . '"  value="' esc_attr$value ) . '" ' implode' '$custom_attributes ) . $parsley_out ' />';

            break;
        case 
'select':
            
$options '';
            
$field   '';

            if ( ! empty( 
$args['options'] ) ) {
                foreach ( 
$args['options'] as $option_key => $option_text ) {
                    if ( 
'' === $option_key ) {
                        
// If we have a blank option, select2 needs a placeholder
                        
if ( empty( $args['placeholder'] ) ) {
                            
$args['placeholder'] = $option_text $option_text cfw__'Choose an option''woocommerce' );
                        }
                        
$custom_attributes[] = 'data-allow_clear="true"';
                    }
                    
$options .= '<option value="' esc_attr$option_key ) . '" ' selected$value$option_keyfalse ) . '>' esc_attr$option_text ) . '</option>';
                }

                
$field .= '<select field_key="' $key_sans_type '" name="' esc_attr$key ) . '" id="' esc_attr$args['id'] ) . '" class="select ' esc_attrimplode' '$args['input_class'] ) ) . '" ' implode' '$custom_attributes ) . ' data-placeholder="' esc_attr$args['placeholder'] ) . '" ' $parsley_out '>' $options '</select>';
            }

            break;
        case 
'radio':
            
$label_id currentarray_keys$args['options'] ) );

            if ( ! empty( 
$args['options'] ) ) {
                
$count 0;
                foreach ( 
$args['options'] as $option_key => $option_text ) {
                    if ( 
=== $count ) {
                        
$field .= '<input type="radio" class="input-radio ' esc_attrimplode' '$args['input_class'] ) ) . '" value="' esc_attr$option_key ) . '" name="' esc_attr$key ) . '" id="' esc_attr$args['id'] ) . '_' esc_attr$option_key ) . '"' checked$value$option_keyfalse ) . $parsley_out ' />';
                    } else {
                        
$field .= '<input type="radio" class="input-radio ' esc_attrimplode' '$args['input_class'] ) ) . '" value="' esc_attr$option_key ) . '" name="' esc_attr$key ) . '" id="' esc_attr$args['id'] ) . '_' esc_attr$option_key ) . '"' checked$value$option_keyfalse ) . ' />';
                    }
                    
$field .= '<label for="' esc_attr$args['id'] ) . '_' esc_attr$option_key ) . '" class="radio ' implode' '$args['label_class'] ) . '">' $option_text '</label>';

                    
$count++;
                }
            }

            break;
        default:
            
/**
             * Filter form field element
             *
             * @since 2.0.0
             *
             * @param string $field Form field element
             */
            
$field .= apply_filters'cfw_form_field_element_' $args['type'], '<input type="' esc_attr$args['type'] ) . '" field_key="' $key_sans_type '" class="input-text ' esc_attrimplode' '$args['input_class'] ) ) . '" name="' esc_attr$key ) . '" id="' esc_attr$args['id'] ) . '" placeholder="' esc_attr$args['placeholder'] ) . '"  value="' esc_attr$value ) . '" ' implode' '$custom_attributes ) . $parsley_out ' />'$key$value$args );
            break;
    }

    
$row_wrap '';

    if ( ! empty( 
$field ) ) {

        
$field_html '';

        if ( 
$args['label'] && 'checkbox' !== $args['type'] && 'hidden' !== $args['type'] ) {
            
$field_html .= '<label for="' esc_attr$label_id ) . '" class="' esc_attrimplode' '$args['label_class'] ) ) . '">' $args['label'] . $required '</label>';
        }

        
$field_html .= $field;

        
$container_class esc_attrimplode' '$args['class'] ) );
        
$container_id    esc_attr$args['id'] ) . '_field';

        if ( isset( 
$args['start'] ) && $args['start'] ) {
            
$row_wrap '<div class="row cfw-input-wrap-row">';
        }

        
/**
         * Filter input row wrap
         *
         * @since 2.0.0
         *
         * @param string $row_wrap Input row wrap
         */
        
$row_wrap apply_filters'cfw_input_row_wrap'$row_wrap$key$args$value );

        if ( ! empty( 
$field_container_start ) ) {
            
$field $row_wrap . @sprintf$field_container_start$container_id$field_html$container_class ); // phpcs:ignore
        
}

        if ( isset( 
$args['end'] ) && $args['end'] ) {
            
$field .= '</div>';
        }
    }

    
$field apply_filters'woocommerce_form_field_' $args['type'], $field$key$args$value$row_wrap );

    if ( 
$args['return'] ) {
        return 
$field;
    } else {
        echo 
$field;
    }
}

function 
cfw_strip_key_type$key ) {
    
$key_exp explode'_'$key );
    return 
implode'_'array_slice$key_exp1count$key_exp ) - 1true ) );
}

/**
 * @param WC_Checkout $checkout
 */
function cfw_get_shipping_checkout_fieldsWC_Checkout $checkout ) {
    
/**
     * Filters shipping address checkout fields
     *
     * @since 2.0.0
     *
     * @param array $shipping_checkout_fields Shipping address checkout fields
     */
    
$shipping_checkout_fields apply_filters'cfw_get_shipping_checkout_fields'$checkout->get_checkout_fields'shipping' ) );

    foreach ( 
$shipping_checkout_fields as $key => $field ) {
        
cfw_form_field$key$field$checkout->get_value$key ) );
    }
}

/**
 * @param WC_Checkout $checkout
 */
function cfw_get_billing_checkout_fieldsWC_Checkout $checkout ) {
    
/**
     * Filters billing address checkout fields
     *
     * @since 2.0.0
     *
     * @param array $billing_checkout_fields Billing address checkout fields
     */
    
$billing_checkout_fields apply_filters'cfw_get_billing_checkout_fields'$checkout->get_checkout_fields'billing' ) );

    foreach ( 
$billing_checkout_fields as $key => $field ) {
        
// Don't output billing email or native billing phone
        // This logic is ugly, but basically we're saying:
        //   - If the field is billing phone and our wrap isn't present, skip the field
        //   - If the field is billing email, skip it
        //   - Otherwise, output it
        
if ( 'billing_phone' === $key && ! isset( $field['wrap'] ) ) {
            continue;
        }

        if ( 
'billing_email' === $key ) {
            continue;
        }

        
$field['custom_attributes']['data-saved-value'] = $checkout->get_value$key ) ?? '';

        
cfw_form_field$key$field$checkout->get_value$key ) );
    }
}

/**
 * @param WC_Checkout $checkout
 *
 * @return string
 */
function cfw_get_review_pane_shipping_addressWC_Checkout $checkout ): string {
    return 
WC()->countries->get_formatted_address(
        
/**
         * Filters review pane shipping address
         *
         * @since 2.0.0
         *
         * @param array $shipping_details_address Review pane shipping address
         */
        
apply_filters(
            
'cfw_get_shipping_details_address',
            array(
                
'company'   => isset( $_POST['s_company'] ) ? $_POST['s_company'] : $checkout->get_value'shipping_company' ),
                
'address_1' => $_POST['s_address_1'] ?? $checkout->get_value'shipping_address_1' ),
                
'address_2' => $_POST['s_address_2'] ?? $checkout->get_value'shipping_address_2' ),
                
'city'      => $_POST['s_city'] ?? $checkout->get_value'shipping_city' ),
                
'state'     => $_POST['s_state'] ?? $checkout->get_value'shipping_state' ),
                
'postcode'  => $_POST['s_postcode'] ?? $checkout->get_value'shipping_postcode' ),
                
'country'   => $_POST['s_country'] ?? $checkout->get_value'shipping_country' ),
            ),
            
$checkout
        
),
        
', '
    
);
}

/**
 * @param WC_Checkout $checkout
 *
 * @return string
 */
function cfw_get_review_pane_billing_addressWC_Checkout $checkout ): string {
    return 
WC()->countries->get_formatted_address(
        
/**
         * Filters review pane billing address
         *
         * @since 2.0.0
         *
         * @param array $billing_details_address Review pane billing address
         */
        
apply_filters(
            
'cfw_get_review_pane_billing_address',
            array(
                
'company'   => isset( $_POST['company'] ) ? $_POST['company'] : $checkout->get_value'billing_company' ),
                
'address_1' => $_POST['address_1'] ?? $checkout->get_value'billing_address_1' ),
                
'address_2' => $_POST['address_2'] ?? $checkout->get_value'billing_address_2' ),
                
'city'      => $_POST['city'] ?? $checkout->get_value'billing_city' ),
                
'state'     => $_POST['state'] ?? $checkout->get_value'billing_state' ),
                
'postcode'  => $_POST['postcode'] ?? $checkout->get_value'billing_postcode' ),
                
'country'   => $_POST['country'] ?? $checkout->get_value'billing_country' ),
            ),
            
$checkout
        
),
        
', '
    
);
}

function 
cfw_get_shipping_methods_html() {
    
ob_start();

    
cfw_shipping_methods_html();

    return 
ob_get_clean();
}

function 
cfw_shipping_methods_html() {
    
$packages WC()->shipping->get_packages();

    foreach ( 
$packages as $i => $package ) {
        
$chosen_method WC()->session->chosen_shipping_methods$i ] ?? '';
        
$product_names = array();

        if ( 
sizeof$packages ) > ) {
            foreach ( 
$package['contents'] as $item_id => $values ) {
                
$product_names$item_id ] = $values['data']->get_name() . ' &times;' $values['quantity'];
            }
            
$product_names apply_filters'woocommerce_shipping_package_details_array'$product_names$package );
        }

        
$available_methods    $package['rates'];
        
$show_package_details sizeof$packages ) > 1;
        
$package_details      implode', '$product_names );
        
$package_name         apply_filters'woocommerce_shipping_package_name'sprintfcfw_nx'Shipping''Shipping %d', ( $i ), 'shipping packages''woocommerce' ), ( $i ) ), $i$package );
        
$index                $i;

        
// Next section ripped straight from cart-shipping and edited for now
        
if ( count$available_methods ) > ) : ?>
            <?php if ( count$packages ) ) : ?>
                <h4 class="cfw-shipping-package-title"><?php echo $package_name?></h4>
            <?php endif; ?>

            <?php cfw_before_shipping(); ?>

            <ul id="shipping_method" class="cfw-shipping-methods-list">
                <?php
                
foreach ( $available_methods as $method ) :
                    
ob_start();
                    
do_action'woocommerce_after_shipping_rate'$method$index );
                    
$after_shipping_method ob_get_clean();
                    
?>
                    <li>
                        <div class="cfw-shipping-method-inner">
                            <?php printf'<input type="radio" name="shipping_method[%1$d]" data-index="%1$d" id="shipping_method_%1$d_%2$s" value="%3$s" class="shipping_method" %4$s />'$indexesc_attrsanitize_title$method->id ) ), esc_attr$method->id ), checked$method->id$chosen_methodfalse ) ); // WPCS: XSS ok. ?>
                            <?php printf'<label for="shipping_method_%1$s_%2$s">%3$s</label>'$indexesc_attrsanitize_title$method->id ) ), wc_cart_totals_shipping_method_label$method ) ); // WPCS: XSS ok. ?>
                        </div>
                        <?php
                        
if ( ! empty( trim$after_shipping_method ) ) && preg_match'/<thead|<tbody|<tfoot|<th|<tr/'$after_shipping_method ) && substrtrim$after_shipping_method ), 0) !== '<table' ) :
                            
?>
                            <table>
                                <?php echo $after_shipping_method?>
                            </table>
                        <?php else : ?>
                            <?php echo $after_shipping_method?>
                        <?php endif; ?>
                    </li>
                <?php endforeach; ?>
            </ul>

            <?php cfw_after_shipping(); ?>
        <?php else : ?>
            <div class="shipping-message">
                <?php echo apply_filters'woocommerce_no_shipping_available_html''<div class="cfw-alert cfw-alert-error"><div class="message">' wpautopcfw__'There are no shipping options available. Please ensure that your address has been entered correctly, or contact us if you need any help.''woocommerce' ) ) . '</div></div>' ); ?>
            </div>
        <?php endif; ?>

        <?php if ( $show_package_details ) : ?>
            <?php echo '<p class="woocommerce-shipping-contents"><small>' esc_html$package_details ) . '</small></p>'?>
        <?php endif; ?>
        <?php
    
}
}

function 
cfw_has_valid_shipping_methods(): bool {
    foreach ( 
WC()->shipping->get_packages() as $package ) {
        if ( 
count$package['rates'] ) === ) {
            return 
false;
        }
    }

    return 
true;
}

function 
cfw_before_shipping() {
    if ( 
has_action'woocommerce_review_order_before_shipping' ) ) :
        
?>
        <table id="cfw-before-shipping">
            <?php do_action'woocommerce_review_order_before_shipping' ); ?>
        </table>
        <?php
    
endif;
}

function 
cfw_after_shipping() {
    if ( 
has_action'woocommerce_review_order_after_shipping' ) ) :
        
?>
        <table id="cfw-after-shipping">
            <?php
            
/**
             * Fires after shipping methods in table
             *
             * @since 2.0.0
             */
            
do_action'cfw_after_shipping_methods' );
            
?>
            <?php do_action'woocommerce_review_order_after_shipping' ); ?>
        </table>
        <?php
    
endif;
}

function 
cfw_get_payment_methods_html$available_gateways false ) {
    
/**
     * Fires before payment methods html is fetched
     *
     * @since 2.0.0
     */
    
do_action'cfw_get_payment_methods_html' );

    
$available_gateways = empty( $available_gateways ) ? WC()->payment_gateways->get_available_payment_gateways() : (array) $available_gateways;
    
WC()->payment_gateways()->set_current_gateway$available_gateways );

    
ob_start();
    
?>
    <ul class="wc_payment_methods payment_methods methods cfw-radio-reveal-group">
    <?php
    
/**
     * Fires at start of payment methods UL
     *
     * @since 2.0.0
     */
    
do_action'cfw_payment_methods_ul_start' );

    if ( ! empty( 
$available_gateways ) ) {
        
$count 0;
        foreach ( 
$available_gateways as $gateway ) {
            
// Prevent fatal errors when no gateway is available
            // OR when gateway isn't actually a gateway
            
if ( is_a$gateway'stdClass' ) ) {
                continue;
            }

            
/**
             * Filters whether to show gateway in list of gateways
             *
             * @since 2.0.0
             *
             * @param bool $show Show gateway output
             */
            
if ( apply_filters"cfw_show_gateway_{$gateway->id}"true ) ) :
                
/**
                 * Filters gateway order button text
                 *
                 * @since 2.0.0
                 *
                 * @param string $gateway_order_button_text The gateway order button text
                 */
                
$gateway_order_button_text apply_filters'cfw_gateway_order_button_text'$gateway->order_button_text$gateway );

                
/**
                 * Filters gateway order button text
                 *
                 * @since 2.0.0
                 *
                 * @param string $icons The gateway icon HTML
                 * @param \WC_Payment_Gateway
                 */
                
$icons apply_filters'cfw_get_gateway_icons'$gateway->get_icon(), $gateway );

                
$title              $gateway->get_title();
                
$is_active_class    $gateway->chosen 'cfw-active' '';
                
$li_class_attribute apply_filters'cfw_payment_method_li_class'"wc_payment_method cfw-radio-reveal-li $is_active_class payment_method_{$gateway->id});
                
?>
                <li class="<?php echo $li_class_attribute?>">
                    <div class="payment_method_title_wrap cfw-radio-reveal-title-wrap">
                        <input id="payment_method_<?php echo $gateway->id?>" type="radio" class="input-radio" name="payment_method" value="<?php echo esc_attr$gateway->id ); ?><?php checked$gateway->chosentrue ); ?> data-order_button_text="<?php echo esc_attr$gateway_order_button_text ); ?>"/>

                        <label class="payment_method_label cfw-radio-reveal-label" for="payment_method_<?php echo $gateway->id?>">
                            <div>
                                <?php if ( $title ) : ?>
                                    <span class="payment_method_title cfw-radio-reveal-title">
                                        <?php echo $title?>
                                    </span>
                                <?php endif; ?>

                                <?php if ( $icons ) : ?>
                                    <span class="payment_method_icons">
                                        <?php echo $icons?>
                                    </span>
                                <?php endif; ?>
                            </div>
                        </label>
                    </div>
                <?php
                
/**
                 * Filters whether to show gateway content
                 *
                 * @since 2.0.0
                 *
                 * @param bool $show Show gateway content
                 */
                
if ( apply_filters"cfw_payment_gateway_{$gateway->id}_content"$gateway->has_fields() || $gateway->get_description() ) ) :
                    
?>
                        <div class="payment_box payment_method_<?php echo $gateway->id?> cfw-radio-reveal-content" <?php echo ! $gateway->chosen 'style="display:none;"' ''?>>
                            <?php
                            ob_start
();

                            
remove_filter'woocommerce_form_field', array( FormAugmenter::instance(), 'cfw_form_field' ), 10 );

                            
$gateway->payment_fields();

                            
add_filter'woocommerce_form_field', array( FormAugmenter::instance(), 'cfw_form_field' ), 10);

                            
$field_html ob_get_clean();

                            
/**
                             * Gateway Compatibility Patches
                             */
                            // Expiration field fix
                            
$field_html str_ireplace'js-sv-wc-payment-gateway-credit-card-form-expiry''js-sv-wc-payment-gateway-credit-card-form-expiry  wc-credit-card-form-card-expiry'$field_html );
                            
$field_html str_ireplace'js-sv-wc-payment-gateway-credit-card-form-account-number''js-sv-wc-payment-gateway-credit-card-form-account-number  wc-credit-card-form-card-number'$field_html );

                            
// Credit Card Field Placeholders
                            
$field_html str_ireplace'•••• â€¢â€¢â€¢â€¢ â€¢â€¢â€¢â€¢ â€¢â€¢â€¢â€¢''Card Number'$field_html );
                            
$field_html str_ireplace'&bull;&bull;&bull;&bull; &bull;&bull;&bull;&bull; &bull;&bull;&bull;&bull; &bull;&bull;&bull;&bull;''Card Number'$field_html );

                            
/**
                             * Filters gateway payment field output HTML
                             *
                             * @since 2.0.0
                             *
                             * @param string $gateway_output Payment gateway output HTML
                             */
                            
echo apply_filters"cfw_payment_gateway_field_html_{$gateway->id}"$field_html );
                            
?>
                        </div>
                    <?php endif; ?>
                </li>

                <?php
                
else :
                    
/**
                     * Fires after payment method LI to allow alternate / additional output
                     *
                     * @since 2.0.0
                     */
                    
do_action_ref_array"cfw_payment_gateway_list_{$gateway->id}_alternate", array( $count ) );
                endif;

                
$count++;
        }
    } else {
        echo 
'<li class="woocommerce-notice woocommerce-notice--info woocommerce-info">' apply_filters'woocommerce_no_available_payment_methods_message'cfw__'Sorry, it seems that there are no available payment methods for your location. Please contact us if you require assistance or wish to make alternate arrangements.''woocommerce' ) ) . '</li>';
    }

    
/**
     * Fires after bottom of payment methods UL
     *
     * @since 2.0.0
     */
    
do_action'cfw_payment_methods_ul_end' );
    
?>
    </ul>
    <?php

    
return ob_get_clean();
}

/**
 * @param WC_Cart|WC_Order $object
 * @return mixed|void
 */
function cfw_get_item_summary_table$object ) {
    
$items_adapter = new ItemsAdapter$object );
    
$items         $items_adapter->get_items();
    
$is_checkout   is_a$object'\\WC_Cart' );
    
ob_start();
    
?>
    <table id="cfw-cart" class="cfw-module">
        <?php
        
if ( $is_checkout ) {
            
/**
             * Fires at start of cart table
             *
             * @since 2.0.0
             */
            
do_action'cfw_cart_html_table_start' );
        }

        
/** @var Item $item */
        
foreach ( $items as $item ) :
            
$item_thumb $item->get_thumbnail();
            
?>
            <tr class="cart-item-row cart-item-<?php echo $item->get_item_key(); ?> <?php echo $item->get_row_class(); ?>">
                <?php if ( $item_thumb ) : ?>
                    <td class="cfw-cart-item-image">
                        <div class="cfw-cart-item-image-wrap">
                            <?php echo $item_thumb?>

                            <span class="cfw-cart-item-quantity-bubble">
                                <?php echo $item->get_quantity(); ?>
                            </span>
                        </div>
                    </td>
                <?php endif; ?>

                <th class="cfw-cart-item-description" <?php echo empty( $item_thumb ) ? 'colspan="2" style="padding-left: 0; ?>"' ''?> >
                    <div class="cfw-cart-item-title">
                        <?php
                        
/**
                         * Filters whether to link cart items to products
                         *
                         * @since 1.0.0
                         *
                         * @param bool $link_cart_items Link cart items to products
                         */
                        
if ( apply_filters'cfw_link_cart_items'SettingsManager::instance()->get_setting'cart_item_link' ) === 'enabled' ) ) :
                            
?>
                            <a target="_blank" href="<?php echo $item->get_url(); ?>">
                                <?php echo $item->get_title(); ?>
                            </a>
                        <?php else : ?>
                            <?php echo $item->get_title(); ?>
                        <?php endif; ?>
                    </div>
                    <?php
                    cfw_maybe_display_item_discount
$item );
                    
cfw_display_item_data$item );

                    if ( 
$is_checkout ) {
                        
/**
                         * Fires after cart item data output
                         *
                         * @since 2.0.0
                         */
                        
do_action'cfw_cart_item_after_data'$item->get_raw_item(), $item->get_item_key() );
                    }

                    echo 
$item->get_quantity_control();

                    if ( 
$is_checkout ) {
                        
/**
                         * Fires after cart item quantity output
                         *
                         * @since 2.0.0
                         */
                        
do_action'cfw_cart_item_after_quantity'$item->get_raw_item(), $item->get_item_key() );
                    }
                    
?>
                </th>

                <td class="cfw-cart-item-quantity visually-hidden">
                    <?php echo $item->get_quantity(); ?>
                </td>

                <td class="cfw-cart-item-subtotal">
                    <?php do_action'cfw_before_cart_item_subtotal'$item ); ?>
                    <?php echo $item->get_subtotal(); ?>
                </td>
            </tr>
            <?php
            
if ( $is_checkout ) {
                
/**
                 * Fires after cart item row <tr/> is outputted
                 *
                 * @since 2.0.0
                 */
                
do_action'cfw_after_cart_item_row'$item->get_raw_item(), $item->get_item_key() );
            }
            endforeach;
        
?>
    </table>
    <?php
    $return 
ob_get_clean();
    if ( 
$is_checkout ) {
        
/**
         * After cart html table output
         *
         * @since 4.3.4
         */
        
do_action_deprecated'cfw_after_cart_html'null'CheckoutWC 5.4.0''cfw_after_items_summary_table' );

        
/**
         * Filters cart output HTML
         *
         * @since 1.0.0
         *
         * @param string $cart_html Cart output HTML
         */
        
$return apply_filters_deprecated'cfw_cart_html', array( $return ), 'CheckoutWC 5.4.0''cfw_items_summary_table_html' );
    }

    if ( ! 
$is_checkout ) {
        
/**
         * Filters order cart HTML output
         *
         * @since 1.0.0
         *
         * @param string $order_cart_html Order cart HTML output
         */
        
$return apply_filters_deprecated'cfw_order_cart_html', array( $return ), 'CheckoutWC 5.4.0''cfw_items_summary_table_html' );
    }

    return 
apply_filters'cfw_items_summary_table_html'$return$is_checkout 'checkout' 'order' );
}

function 
cfw_get_cart_html() {
    
_deprecated_function'cfw_get_cart_html''CheckoutWC 5.4.0''cfw_get_item_summary_table' );

    return 
cfw_get_item_summary_tableWC()->cart );
}

/**
 * @param WC_Order $order
 */
function cfw_order_cart_htmlWC_Order $order ) {
    
_deprecated_function'cfw_order_cart_html''CheckoutWC 5.4.0''cfw_get_item_summary_table' );

    echo 
cfw_get_item_summary_table$order );
}

/**
 * @param WC_Order $order
 *
 * @return mixed|void
 */
function cfw_get_order_cart_htmlWC_Order $order ) {
    
_deprecated_function'cfw_get_order_cart_html''CheckoutWC 5.4.0''cfw_get_item_summary_table' );

    return 
cfw_get_item_summary_table$order );
}

/**
 * @param Item $item
 */
function cfw_get_item_data_outputItem $item ): string {
    if ( 
apply_filters'cfw_cart_item_data_expanded'SettingsManager::instance()->get_setting'cart_item_data_display' ) === 'woocommerce' ) ) {
        return 
cfw_display_item_data_native$item->get_raw_item() );
    }

    
$item_data $item->get_data();

    if ( empty( 
$item_data ) ) {
        return 
'';
    }

    
$display_outputs = array();

    foreach ( 
$item_data as $raw_key => $raw_value ) {
        
$key               wp_kses_post$raw_key );
        
$value             strip_tags$raw_value );
        
$display_outputs[] = "$key$value";
    }

    return 
join' / '$display_outputs );
}

/**
 * @param Item $item
 */
function cfw_display_item_dataItem $item ) {
    
$output cfw_get_item_data_output$item );

    if ( 
$output ) {
        echo 
'<div class="cfw-cart-item-data">' $output '</div>';
    }
}

/**
 * @param Item $item
 */
function cfw_maybe_display_item_discountItem $item ) {
    if ( ! 
is_array$item->get_raw_item() ) ) {
        return;
    }

    
/**
     * Filters whether to show cart item discount on cart item
     *
     * @since 2.0.0
     *
     * @param bool $show_cart_item_discount Show cart item discount on cart item
     */
    
if ( apply_filters'cfw_show_cart_item_discount'false ) ) {
        echo 
'<div class="cfw-items-summary-item-discount">';
        echo 
apply_filters'cfw_cart_item_discount'$item->get_product()->is_on_sale() ? $item->get_product()->get_price_html() : ''$item->get_raw_item(), $item->get_product() );
        echo 
'</div>';
    }
}

/**
 * @param array|WC_Order_Item $object
 */
function cfw_display_item_data_native$object ) {
    if ( 
is_array$object ) ) {
        
$output wc_get_formatted_cart_item_data$object );

        
$output str_replace' :'':'$output );
    } else {
        
$output wc_display_item_meta$object, array( 'echo' => false ) );
    }

    return 
$output;
}


function 
cfw_get_totals_html() {
    
ob_start();

    
/**
     * Filters cart element ID
     *
     * @since 3.0.0
     *
     * @param string $cart_element_id Cart element ID
     */
    
$template_cart_el_id apply_filters'cfw_template_cart_el''cfw-totals-list' );
    
?>
    <div id="<?php echo $template_cart_el_id?>" class="cfw-module">
        <table class="cfw-module">
            <?php
            
/**
             * Fires at start of cart summary totals table
             *
             * @since 2.0.0
             */
            
do_action'cfw_before_cart_summary_totals' );
            
?>

            <tr class="cart-subtotal">
                <th><?php cfw_e'Subtotal''woocommerce' ); ?></th>
                <td><?php wc_cart_totals_subtotal_html(); ?></td>
            </tr>

            <?php foreach ( WC()->cart->get_coupons() as $code => $coupon ) : ?>
                <tr class="cart-discount coupon-<?php echo esc_attrsanitize_title$code ) ); ?>">
                    <th><?php wc_cart_totals_coupon_label$coupon ); ?></th>
                    <td><?php wc_cart_totals_coupon_html$coupon ); ?></td>
                </tr>
            <?php endforeach; ?>

            <?php if ( cfw_show_shipping_total() ) : ?>
                <?php cfw_cart_totals_shipping_html(); ?>
            <?php endif; ?>

            <?php foreach ( WC()->cart->get_fees() as $fee ) : ?>
                <tr class="fee">
                    <th><?php echo esc_html$fee->name ); ?></th>
                    <td><?php wc_cart_totals_fee_html$fee ); ?></td>
                </tr>
            <?php endforeach; ?>

            <?php if ( wc_tax_enabled() && ! WC()->cart->display_prices_including_tax() ) : ?>
                <?php if ( 'itemized' === get_option'woocommerce_tax_total_display' ) ) : ?>
                    <?php foreach ( WC()->cart->get_tax_totals() as $code => $tax ) : ?>
                        <tr class="tax-rate tax-rate-<?php echo sanitize_title$code ); ?>">
                            <th><?php echo esc_html$tax->label ); ?></th>
                            <td><?php echo wp_kses_post$tax->formatted_amount ); ?></td>
                        </tr>
                    <?php endforeach; ?>
                <?php else : ?>
                    <tr class="tax-total">
                        <th><?php echo esc_htmlWC()->countries->tax_or_vat() ); ?></th>
                        <td><?php wc_cart_totals_taxes_total_html(); ?></td>
                    </tr>
                <?php endif; ?>
            <?php endif; ?>

            <?php
            
/**
             * Fires before totals are output in cart summary totals table
             *
             * @since 2.0.0
             */
            
do_action'woocommerce_review_order_before_order_total' );
            
?>

            <tr class="order-total">
                <th><?php cfw_e'Total''woocommerce' ); ?></th>
                <td><?php wc_cart_totals_order_total_html(); ?></td>
            </tr>

            <?php
            
/**
             * Fires after totals are output in cart summary totals table
             *
             * @since 2.0.0
             */
            
do_action'woocommerce_review_order_after_order_total' );
            
?>

            <?php
            
/**
             * Fires at end of cart summary totals table before </table> tag
             *
             * @since 2.0.0
             */
            
do_action'cfw_after_cart_summary_totals' );
            
?>
        </table>
    </div>
    <?php

    
/**
     * Filters cart totals HTML
     *
     * @since 2.0.0
     *
     * @param string $totals_html Cart totals HTML
     */
    
return apply_filters'cfw_totals_html'ob_get_clean() );
}

/**
 * Get shipping methods.
 *
 * @see wc_cart_totals_shipping_html()
 */
function cfw_cart_totals_shipping_html() {
    
?>
    <tr class="woocommerce-shipping-totals">
        <th>
            <?php
            
/**
             * Filters cart totals shipping label
             *
             * @since 2.0.0
             *
             * @param string $cart_totals_shipping_label Cart totals shipping label
             */
            
echo apply_filters'cfw_cart_totals_shipping_label'cfw_esc_html__'Shipping''woocommerce' ) );
            
?>
        </th>
        <td>
            <?php echo cfw_get_shipping_total(); ?>
        </td>
    </tr>
    <?php
}

function 
cfw_all_packages_have_available_shipping_methods( array $packages ): bool {
    foreach ( 
$packages as $package ) {
        if ( empty( 
$package['rates'] ) ) {
            return 
false;
        }
    }

    return 
true;
}

function 
cfw_get_shipping_total(): string {
    
$small_format '<span class="cfw-small">%s</span>';

    
$has_calculated_shipping WC()->customer->has_calculated_shipping();
    
$address_required        get_option'woocommerce_shipping_cost_requires_address' ) === 'yes';
    
$missing_address         $address_required && ! $has_calculated_shipping;

    if ( 
$missing_address ) {
        
/**
         * Filters shipping total address required text
         *
         * @param string $address_required_text Shipping total address required text
         * @since 2.0.0
         */
        
return sprintf$small_formatwp_kses_postapply_filters'cfw_shipping_total_address_required_text'cfw__'Enter your address to view shipping options.''woocommerce' ) ) ) );
    }

    
$packages WC()->shipping()->get_packages();

    if ( ! 
cfw_all_packages_have_available_shipping_methods$packages ) ) {
        
/**
         * Filters shipping total text when no shipping methods are available
         *
         * @param string $new_shipping_total_not_available_text Shipping total text when no shipping methods are available
         * @since 2.0.0
         */
        
return sprintf$small_formatwp_kses_postapply_filters'cfw_shipping_total_not_available_text'__'No shipping methods available''checkout-wc' ) ) ) );
    }

    
$total cfw_calculate_packages_shipping$packagesWC()->sessionWC()->cart );

    if ( 
$total ) {
        return 
wc_price$total );
    }

    return 
apply_filters'cfw_shipping_free_text'cfw__'Free!''woocommerce' ) );
}

function 
cfw_calculate_packages_shipping( array $packages$wc_session$wc_cart ) {
    
$total 0;

    foreach ( 
$packages as $i => $package ) {
        
$chosen_method     = isset( $wc_session->chosen_shipping_methods$i ] ) ? $wc_session->chosen_shipping_methods$i ] : '';
        
$available_methods = empty( $package['rates'] ) ? array() : $package['rates'];

        foreach ( 
$available_methods as $method ) {
            if ( 
$method->id !== $chosen_method ) {
                continue;
            }

            if ( 
>= $method->cost ) {
                continue;
            }

            
$total += $method->cost;

            if ( 
$wc_cart->display_prices_including_tax() ) {
                
$total += $method->get_shipping_tax();
            }
        }
    }

    return 
$total;
}

/**
 * Get shipping methods.
 *
 * @see wc_cart_totals_shipping_html()
 */
function cfw_order_review_pane_shipping_totals() {
    
?>
    <li>
        <div class="inner cfw-no-border">
            <div role="rowheader" class="cfw-review-pane-label">
                <?php
                
/**
                 * Filters cart totals shipping label
                 *
                 * @param string $cart_totals_shipping_label Cart totals shipping label
                 * @since 3.0.0
                 */
                
echo apply_filters'cfw_cart_totals_shipping_label'cfw_esc_html__'Shipping''woocommerce' ) );
                
?>
            </div>
        </div>
        <div role="cell" class="cfw-review-pane-content cfw-review-pane-right cfw-no-border">
            <?php echo cfw_get_shipping_total(); ?>
        </div>
    </li>
    <?php
}

/**
 * @param WC_Order $order
 */
function cfw_order_totals_htmlWC_Order $order ) {
    echo 
cfw_get_order_totals_html$order );
}

/**
 * @param WC_Order $order
 *
 * @return mixed|void
 */
function cfw_get_order_totals_htmlWC_Order $order ) {
    
$totals $order->get_order_item_totals();

    
ob_start();

    
/**
     * Filters order totals element ID
     *
     * @since 2.0.0
     *
     * @param string $order_totals_list_element_id Order totals element ID
     */
    
$order_totals_list_element_id apply_filters'cfw_template_cart_el''cfw-totals-list' );
    
?>
    <div id="<?php echo $order_totals_list_element_id?>" class="cfw-module">
        <table class="cfw-module">
            <?php
            
/**
             * Fires at start of cart summary totals table
             *
             * @since 2.0.0
             */
            
do_action'cfw_before_cart_summary_totals' );
            
?>

            <?php
            
foreach ( $totals as $key => $total ) :
                if ( 
'payment_method' === $key ) {
                    continue;
                }
                
?>
                <tr class="cart-subtotal <?php echo ( 'order_total' === $key ) ? 'order-total' ''?>">
                    <th><?php echo $total['label']; ?></th>
                    <td><?php echo $total['value']; ?></td>
                </tr>
            <?php endforeach; ?>

            <?php do_action'woocommerce_review_order_after_order_total' ); ?>

            <?php
            
/**
             * Fires at end of cart summary totals table before </table> tag
             *
             * @since 2.0.0
             */
            
do_action'cfw_after_cart_summary_totals' );
            
?>
        </table>
    </div>
    <?php

    
/**
     * Filters order totals HTML
     *
     * @since 2.0.0
     *
     * @param string $order_totals_html Cart totals HTML
     */
    
return apply_filters'cfw_order_totals_html'ob_get_clean() );
}

function 
cfw_address_class_wrap$shipping true ) {
    
// If __field-wrapper class isn't there, Amazon Pay nukes our address fields :-(
    
$result 'woocommerce-billing-fields woocommerce-billing-fields__field-wrapper';

    if ( 
true === $shipping ) {
        
$result 'woocommerce-shipping-fields woocommerce-shipping-fields__field-wrapper';
    }

    echo 
$result;
}

function 
cfw_get_place_order$order_button_text false ) {
    
ob_start();

    
$order_button_text = ! $order_button_text apply_filters'woocommerce_order_button_text'__'Complete Order''checkout-wc' ) ) : $order_button_text;

    
/**
     * Filters place order button container classes
     *
     * @since 2.0.0
     *
     * @param array $place_order_button_container_classes Place order button container classes
     */
    
$place_order_button_container_class join' 'apply_filters'cfw_place_order_button_container_classes', array( 'place-order' ) ) );
    
?>
    <div class="<?php echo $place_order_button_container_class?>" data-total="<?php echo WC()->cart->get_total'checkoutwc' ); ?>" id="cfw-place-order">
        <?php echo apply_filters'woocommerce_order_button_html''<button type="submit" class="cfw-primary-btn cfw-next-tab validate" name="woocommerce_checkout_place_order" id="place_order" formnovalidate="formnovalidate" value="' esc_attr$order_button_text ) . '" data-value="' esc_attr$order_button_text ) . '">' esc_html$order_button_text ) . '</button>' ); // @codingStandardsIgnoreLine ?>

        <?php do_action'woocommerce_review_order_after_submit' ); ?>

        <?php wp_nonce_field'woocommerce-process_checkout''woocommerce-process-checkout-nonce' ); ?>
        <input type="hidden" name="cfw_update_cart" value="false" />
    </div>
    <?php
    
if ( ! is_ajax() ) {
        
do_action'woocommerce_review_order_after_payment' );
    }

    return 
ob_get_clean();
}

function 
cfw_place_order$order_button_text false ) {
    echo 
cfw_get_place_order$order_button_text );
}

function 
cfw_get_payment_methods$available_gateways false$object false$show_title true$payment_methods_html false ) {
    if ( 
false === $payment_methods_html ) {
        
$payment_methods_html cfw_get_payment_methods_html$available_gateways );
    }

    
$object = ! $object WC()->cart $object;

    
ob_start();
    
?>
    <div id="cfw-billing-methods" class="cfw-module cfw-accordion">
        <?php
        
/**
         * Fires above the payment method heading
         *
         * @since 5.1.1
         */
        
do_action'cfw_before_payment_method_heading' );

        if ( 
$show_title ) :
            
?>
            <h3>
                <?php
                
/**
                 * Filters payment methods heading
                 *
                 * @since 2.0.0
                 *
                 * @param string $payment_methods_heading Payment methods heading
                 */
                
echo apply_filters'cfw_payment_method_heading'esc_html__'Payment''checkout-wc' ) );
                
?>
            </h3>
        <?php endif; ?>

        <?php
        
/**
         * Fires after payment methods heading and before transaction are encrypted statement
         *
         * @since 2.0.0
         */
        
do_action'cfw_checkout_before_payment_methods' );
        
?>

        <?php if ( $object->needs_payment() ) : ?>
            <div class="cfw-payment-method-information-wrap">
                <h4 class="cfw-small secure-notice">
                    <?php
                    
/**
                     * Filters payment methods transactions are encrypted statement
                     *
                     * @since 2.0.0
                     *
                     * @param string $transactions_encrypted_statement Payment methods transactions are encrypted statement
                     */
                    
echo apply_filters'cfw_transactions_encrypted_statement'esc_html__'All transactions are secure and encrypted.''checkout-wc' ) );
                    
?>
                </h4>

                <div class="cfw-payment-methods-wrap">
                    <div id="payment" class="woocommerce-checkout-payment">
                        <?php echo $payment_methods_html?>
                    </div>
                </div>
            </div>
        <?php else : ?>
            <div class="cfw-no-payment-method-wrap">
                <span class="cfw-small">
                    <?php
                    
/**
                     * Filters no payment required text
                     *
                     * @since 2.0.0
                     *
                     * @param string $no_payment_required_text No payment required text
                     */
                    
echo apply_filters'cfw_no_payment_required_text'esc_html__'Your order is free. No payment is required.''checkout-wc' ) );
                    
?>
                </span>
            </div>
        <?php endif; ?>

        <?php
        
/**
         * Fires at end of payment methods container before </div> tag
         *
         * @since 2.0.0
         */
        
do_action'cfw_checkout_after_payment_methods' );
        
?>
    </div>
    <?php

    
return ob_get_clean();
}

function 
cfw_billing_address_radio_group() {
    
/**
     * Fires before billing address radio group is output
     *
     * @since 2.0.0
     */
    
do_action'cfw_checkout_before_billing_address' );

    
/**
     * Filters whether to force displaying the billing address (no accordion)
     *
     * @since 2.0.0
     *
     * @param bool $force_display_billing_address Force displaying billing address
     */
    
if ( ! apply_filters'cfw_force_display_billing_address'false ) ) :
        
?>
        <div id="cfw-shipping-same-billing" class="cfw-module cfw-accordion">
            <ul class="cfw-radio-reveal-group">
                <li class="cfw-radio-reveal-li cfw-no-reveal">
                    <div class="cfw-radio-reveal-title-wrap">
                        <input type="radio" name="bill_to_different_address" id="billing_same_as_shipping_radio" value="same_as_shipping" class="garlic-auto-save" checked="checked" />

                        <label for="billing_same_as_shipping_radio" class="cfw-radio-reveal-label">
                            <div>
                                <span class="cfw-radio-reveal-title"><?php esc_html_e'Same as shipping address''checkout-wc' ); ?></span>
                            </div>
                        </label>

                        <?php
                        
/**
                         * Fires after same as shipping address label
                         *
                         * @since 2.0.0
                         */
                        
do_action'cfw_after_same_as_shipping_address_label' );
                        
?>
                    </div>
                </li>
                <li class="cfw-radio-reveal-li">
                    <div class="cfw-radio-reveal-title-wrap">
                        <input type="radio" name="bill_to_different_address" id="shipping_dif_from_billing_radio" value="different_from_shipping" class="garlic-auto-save" />

                        <label for="shipping_dif_from_billing_radio" class="cfw-radio-reveal-label">
                            <div>
                                <span class="cfw-radio-reveal-title"><?php esc_html_e'Use a different billing address''checkout-wc' ); ?></span>
                            </div>
                        </label>
                    </div>
                    <div id="cfw-billing-fields-container" class="cfw-radio-reveal-content <?php cfw_address_class_wrapfalse ); ?>" style="display: none">
                        <?php
                        
/**
                         * Fires before billing address inside billing address container
                         *
                         * @since 2.0.0
                         */
                        
do_action'cfw_start_billing_address_container' );

                        
cfw_get_billing_checkout_fieldsWC()->checkout() );

                        
/**
                         * Fires after billing address inside billing address container
                         *
                         * @since 2.0.0
                         */
                        
do_action'cfw_end_billing_address_container' );
                        
?>
                    </div>
                </li>
            </ul>
        </div>
    <?php else : ?>
        <input type="hidden" name="bill_to_different_address" id="billing_same_as_shipping_radio" value="different_from_shipping" />
        <?php cfw_get_billing_checkout_fieldsWC()->checkout() ); ?>
    <?php endif; ?>

    <!-- wrapper required for compatibility with Pont shipping for Woocommerce -->
    <div class="cfw-force-hidden">
        <div id="ship-to-different-address">
            <input id="ship-to-different-address-checkbox" type="checkbox" name="ship_to_different_address" value="<?php echo WC()->cart->needs_shipping_address() ? 0?>" checked="checked" />
        </div>
    </div>

    <?php
    
/**
     * Fires after billing address
     *
     * @since 2.0.0
     */
    
do_action'cfw_checkout_after_billing_address' );
}

/**
 * Get all approved WooCommerce order notes.
 *
 * @param int|string $order_id The order ID.
 * @param string $status_search
 *
 * @return bool|string
 */
function cfw_order_status_date$order_id$status_search ) {
    
remove_filter'comments_clauses', array( 'WC_Comments''exclude_order_comments' ) );

    
$notes get_comments(
        array(
            
'post_id' => $order_id,
            
'orderby' => 'comment_ID',
            
'order'   => 'DESC',
            
'approve' => 'approve',
            
'type'    => 'order_note',
        )
    );

    
add_filter'comments_clauses', array( 'WC_Comments''exclude_order_comments' ) );

    
$pattern sprintfcfw__'Order status changed from %1$s to %2$s.''woocommerce' ), 'X'$status_search );

    
$pieces         explode' '$pattern );
    
$last_two_words implode' 'array_splice$pieces, -) );

    foreach ( 
$notes as $note ) {
        if ( 
false !== stripos$note->comment_content$last_two_words ) ) {
            return 
$note->comment_date_gmt;
        }
    }

    return 
false;
}

/**
 * @param \WC_Order $order
 */
function cfw_maybe_output_tracking_numbers$order ) {
    
$output '';

    if ( 
defined'WC_SHIPMENT_TRACKING_VERSION' ) ) {
        
$tracking_items \WC_Shipment_Tracking_Actions::get_instance()->get_tracking_items$order->get_id(), true );
        
$label_suffix   cfw__'Tracking Number:''woocommerce-shipment-tracking' );

        foreach ( 
$tracking_items as $tracking_item ) {
            
/**
             * Filters tracking link header on thank you page
             *
             * @since 3.14.0
             *
             * @param string $shipment_tracking_header Tracking link header
             * @param string $tracking_provider The shipping provider for tracking link
             */
            
$output .= apply_filters'cfw_thank_you_shipment_tracking_header'"<h4>{$tracking_item['formatted_tracking_provider']} {$label_suffix}</h4>"$tracking_item['formatted_tracking_provider'] );

            
/**
             * Filters tracking link output on thank you page
             *
             * @since 3.14.0
             *
             * @param string $shipment_tracking_link Tracking link output
             * @param string $tracking_link The tracking link
             * @param string $tracking_number The tracking number
             */
            
$output .= apply_filters'cfw_thank_you_shipment_tracking_link'"<p><a class=\"tracking-number\" target=\"_blank\" href=\"{$tracking_item['formatted_tracking_link']}\">{$tracking_item['tracking_number']}</a></p>"$tracking_item['formatted_tracking_link'], $tracking_item['tracking_number'] );
        }
    } elseif ( 
function_exists'wc_advanced_shipment_tracking' ) ) {
        
ob_start();
        
$wc_advanced_shipment_tracking_actions \WC_Advanced_Shipment_Tracking_Actions::get_instance();
        
$wc_advanced_shipment_tracking_actions->show_tracking_info_order$order->get_id() );

        
$output ob_get_clean();
    } elseif ( 
has_filter'cfw_thank_you_tracking_numbers' ) ) {
        
/**
         * Filter to handle custom shipment tracking links output on thank you page
         *
         * @since 3.0.0
         *
         * @param string $custom_tracking_numbers_output The tracking numbers output
         * @param \WC_Order $order The order object
         */
        
$output apply_filters'cfw_thank_you_tracking_numbers'''$order );
    }

    if ( ! empty( 
$output ) ) {
        echo 
'<div class="inner cfw-padded">';

        
/**
         * Filter tracking numbers output on thank you page
         *
         * @since 3.0.0
         *
         * @param string $tracking_numbers_output The tracking numbers output HTML
         * @param \WC_Order $order The order object
         */
        
echo apply_filters'cfw_maybe_output_tracking_numbers'$output$order );

        echo 
'</div>';
    }
}

function 
cfw_return_to_cart_link() {
    if ( ! 
apply_filters'cfw_show_return_to_cart_link'true ) ) {
        return;
    }

    
/**
     * Filter return to cart link URL
     *
     * @since 2.0.0
     *
     * @param string $return_to_cart_link_url Return to cart link URL
     */
    
$return_to_cart_link_url apply_filters'cfw_return_to_cart_link_url'wc_get_cart_url() );

    
/**
     * Filter return to cart link text
     *
     * @since 2.0.0
     *
     * @param string $return_to_cart_link_text Return to cart link text
     */
    
$return_to_cart_link_text apply_filters'cfw_return_to_cart_link_text'esc_html__'Return to cart''checkout-wc' ) );

    
/**
     * Filter return to cart link
     *
     * @since 2.0.0
     *
     * @param string $cart_link Return to cart link
     */
    
echo apply_filters'cfw_return_to_cart_link'sprintf'<a href="%s" class="cfw-prev-tab">« %s</a>'$return_to_cart_link_url$return_to_cart_link_text ) );
}

/**
 * @param string $label The pre-translated button label
 * @param array $classes Any extra classes to add
 */
function cfw_continue_to_shipping_buttonstring $label '', array $classes = array() ) {
    
$new_classes array_merge(
        array(
            
'cfw-primary-btn' => 'cfw-primary-btn',
            
'cfw-next-tab',
            
'cfw-continue-to-shipping-btn',
        ),
        
$classes
    
);

    if ( 
in_array'cfw-secondary-btn'$classestrue ) ) {
        unset( 
$new_classes['cfw-primary-btn'] );
    }

    
/**
     * Filter continue to shipping method button label
     *
     * @since 3.0.0
     *
     * @param string $continue_to_shipping_method_label Continue to shipping method button label
     */
    
$continue_to_shipping_method_label = ! empty( $label ) ? $label apply_filters'cfw_continue_to_shipping_method_label'esc_html__'Continue to shipping''checkout-wc' ) );

    
/**
     * Filter continue to shipping method button
     *
     * @since 3.0.0
     *
     * @param string $shipping_method_button Continue to shipping method button
     */
    
echo apply_filters'cfw_continue_to_shipping_button'sprintf'<a href="javascript:" data-tab="#cfw-shipping-method" class="%s">%s</a>'join' '$new_classes ), $continue_to_shipping_method_label ) );
}

/**
 * @param string $label The pre-translated button label
 * @param array $classes Any extra classes to add to the button
 */
function cfw_continue_to_payment_buttonstring $label '', array $classes = array() ) {
    
$new_classes array_merge(
        
$classes,
        array(
            
'cfw-primary-btn' => 'cfw-primary-btn',
            
'cfw-next-tab',
            
'cfw-continue-to-payment-btn',
        )
    );

    if ( 
in_array'cfw-secondary-btn'$classestrue ) ) {
        unset( 
$new_classes['cfw-primary-btn'] );
    }

    
/**
     * Filter continue to payment method button label
     *
     * @since 3.0.0
     *
     * @param string $continue_to_payment_method_label Continue to payment method button label
     */
    
$continue_to_payment_method_label = ! empty( $label ) ? $label apply_filters'cfw_continue_to_payment_method_label'esc_html__'Continue to payment''checkout-wc' ) );

    
/**
     * Filter continue to payment method button
     *
     * @since 3.0.0
     *
     * @param string $payment_method_button Continue to payment method button
     */
    
echo apply_filters'cfw_continue_to_payment_button'sprintf'<a href="javascript:" data-tab="#cfw-payment-method" class="%s">%s</a>'join' '$new_classes ), $continue_to_payment_method_label ) );
}

function 
cfw_continue_to_order_review_button() {
    
/**
     * Filter continue to order review button label
     *
     * @since 3.0.0
     *
     * @param string $continue_to_order_review_label Continue to order review button label
     */
    
$continue_to_order_review_label apply_filters'cfw_continue_to_order_review_label'esc_html__'Review order''checkout-wc' ) );

    
/**
     * Filter continue to order review button
     *
     * @since 3.0.0
     *
     * @param string $order_review_button Continue to order review button
     */
    
echo apply_filters'cfw_continue_to_order_review_button'sprintf'<a href="javascript:" data-tab="#cfw-order-review" class="cfw-primary-btn cfw-next-tab cfw-continue-to-order-review-btn">%s</a>'$continue_to_order_review_label ) );
}

function 
cfw_return_to_customer_information_link() {
    
/**
     * Filter return to customer information tab label
     *
     * @since 3.0.0
     *
     * @param string $return_to_customer_info_label Return to customer information tab label
     */
    
$return_to_customer_info_label apply_filters'cfw_return_to_customer_info_label'esc_html__'Return to information''checkout-wc' ) );

    
/**
     * Filter return to customer information tab link
     *
     * @since 3.0.0
     *
     * @param string $return_to_customer_info_link Return to customer information tab link
     */
    
echo apply_filters'cfw_return_to_customer_information_link'sprintf'<a href="javascript:" data-tab="#cfw-customer-info" class="cfw-prev-tab cfw-return-to-information-btn">« %s</a>'$return_to_customer_info_label ) );
}

function 
cfw_return_to_shipping_method_link() {
    
/**
     * Filter return to shipping method tab label
     *
     * @since 3.0.0
     *
     * @param string $return_to_shipping_method_label Return to shipping method tab label
     */
    
$return_to_shipping_method_label apply_filters'cfw_return_to_shipping_method_label'esc_html__'Return to shipping''checkout-wc' ) );

    
/**
     * Filter return to shipping method tab link
     *
     * @since 3.0.0
     *
     * @param string $return_to_shipping_method_link Return to shipping method tab link
     */
    
echo apply_filters'cfw_return_to_shipping_method_link'sprintf'<a href="javascript:" data-tab="#cfw-shipping-method" class="cfw-prev-tab cfw-return-to-shipping-btn">« %s</a>'$return_to_shipping_method_label ) );
}

function 
cfw_return_to_payment_method_link() {
    
/**
     * Filter return to payment method tab label
     *
     * @since 3.0.0
     *
     * @param string $return_to_payment_method_label Return to payment method tab label
     */
    
$return_to_payment_method_label apply_filters'cfw_return_to_payment_method_label'esc_html__'Return to payment''checkout-wc' ) );

    
/**
     * Filter return to payment method tab link
     *
     * @since 3.0.0
     *
     * @param string $return_to_payment_method_link Return to payment method tab link
     */
    
echo apply_filters'cfw_return_to_payment_method_link'sprintf'<a href="javascript:" data-tab="#cfw-payment-method" class="cfw-prev-tab cfw-return-to-payment-btn">« %s</a>'$return_to_payment_method_label ) );
}

/**
 * @return bool
 */
function cfw_show_customer_information_tab(): bool {
    
/**
     * Filters whether to show customer information tab
     *
     * @since 3.0.0
     *
     * @param bool $show_customer_information_tab Show customer information tab
     */
    
return apply_filters'cfw_show_customer_information_tab'true );
}

function 
cfw_breadcrumb_navigation() {
    
$show_customer_info_tab apply_filters'cfw_show_customer_information_tab'true );

    
$default_breadcrumbs = array(
        
'cart'            => array(
            
/**
             * Filters breadcrumb cart link URL
             *
             * @since 3.0.0
             *
             * @param string $breadcrumb_cart_link_url Breadcrumb cart link URL
             */
            
'href'     => apply_filters'cfw_breadcrumb_cart_url'wc_get_cart_url() ),

            
/**
             * Filters breadcrumb cart link label
             *
             * @since 3.0.0
             *
             * @param string $breadcrumb_cart_link_label Breadcrumb cart link label
             */
            
'label'    => apply_filters'cfw_breadcrumb_cart_label'cfw_esc_html__'Cart''woocommerce' ) ),
            
'priority' => 10,
        ),
        
'information-tab' => array(
            
'href'     => '#cfw-customer-info',

            
/**
             * Filters customer information breadcrumb label
             *
             * @since 3.0.0
             *
             * @param string $customer_information_breadcrumb_label Customer information breadcrumb label
             */
            
'label'    => apply_filters'cfw_breadcrumb_customer_info_label'esc_html__'Information''checkout-wc' ) ),
            
'priority' => 20,
        ),
        
'shipping-tab'    => array(
            
'href'     => '#cfw-shipping-method',

            
/**
             * Filters shipping method breadcrumb label
             *
             * @since 3.0.0
             *
             * @param string $shipping_method_breadcrumb_label Shipping method breadcrumb label
             */
            
'label'    => apply_filters'cfw_breadcrumb_shipping_label'esc_html__'Shipping''checkout-wc' ) ),
            
'priority' => 30,
        ),
        
'payment-tab'     => array(
            
'href'     => '#cfw-payment-method',

            
/**
             * Filters payment method breadcrumb label
             *
             * @since 3.0.0
             *
             * @param string $payment_method_breadcrumb_label Payment method breadcrumb label
             */
            
'label'    => apply_filters'cfw_breadcrumb_payment_label'esc_html__'Payment''checkout-wc' ) ),
            
'priority' => 40,
        ),
    );

    if ( ! 
$show_customer_info_tab ) {
        unset( 
$default_breadcrumbs['customer_info'] );
    }

    
/**
     * Filters breadcrumbs
     *
     * @since 3.0.0
     *
     * @param string $breadcrumbs Breadcrumbs
     */
    
$breadcrumbs apply_filters'cfw_breadcrumbs'$default_breadcrumbs );

    
// Order by priority
    
uasort$breadcrumbs'cfw_breadcrumb_uasort_comparison' );

    
/**
     * Fires before breadcrumb navigation is output
     *
     * @since 2.0.0
     */
    
do_action'cfw_before_breadcrumb_navigation' );
    
?>
    <ul id="cfw-breadcrumb" class="etabs">
        <?php foreach ( $breadcrumbs as $id => $breadcrumb ) : ?>
        <li class="<?php echo ( 'cart' !== $id ) ? 'tab' ''?> <?php echo $id?>">
            <a href="<?php echo esc_attr$breadcrumb['href'] ); ?>" class="cfw-small"><?php echo esc_html$breadcrumb['label'] ); ?></a>
        </li>
        <?php endforeach; ?>
    </ul>
    <?php

    
/**
     * Fires after breadcrumb navigation is output
     *
     * @since 2.0.0
     */
    
do_action'cfw_after_breadcrumb_navigation' );
}

/**
 * User to sort breadcrumbs based on priority with uasort.
 *
 * @since 3.5.1
 * @param array $a First breadcrumb to compare.
 * @param array $b Second breadcrumb to compare.
 * @return int
 */
function cfw_breadcrumb_uasort_comparison$a$b ) {
    
/*
     * We are not guaranteed to get a priority
     * setting. So don't compare if they don't
     * exist.
     */
    
if ( ! isset( $a['priority'], $b['priority'] ) ) {
        return 
0;
    }

    return 
wc_uasort_comparison$a['priority'], $b['priority'] );
}

/**
 * @param $name
 *
 * @return mixed|null
 */
function cfw_constant$name ) {
    if ( ! 
defined$name ) ) {
        return 
null;
    }

    return 
constant$name );
}

function 
cfw_main_container_classes$context 'checkout' ) {
    
$classes = array();

    
$classes[] = 'container';
    
$classes[] = 'context-' $context;
    
$classes[] = 'checkoutwc';

    if ( 
is_admin_bar_showing() ) {
        
$classes[] = 'admin-bar';
    }

    if ( 
SettingsManager::instance()->get_setting'label_style' ) === 'normal' ) {
        
$classes[] = 'cfw-label-style-normal';
    }

    
/**
     * Filters main container classes
     *
     * @since 3.0.0
     *
     * @param string $classes Main container classes
     */
    
return apply_filters"cfw_{$context}_main_container_classes"join' '$classes ) );
}

/**
 * @param callable $function
 * @return false|string
 */
function cfw_return_function_output( callable $function ) {
    
ob_start();

    
$function();

    return 
ob_get_clean();
}

function 
cfw_count_filters$filter ): int {
    global 
$wp_filter;
    
$count 0;

    if ( isset( 
$wp_filter$filter ] ) ) {
        foreach ( 
$wp_filter$filter ]->callbacks as $callbacks ) {
            
$count += (int) count$callbacks );
        }
    }

    return 
$count;
}

/**
 * @return bool
 */
function cfw_is_checkout(): bool {
    
/**
     * Filter cfw_is_checkout()
     *
     * @since 3.0.0
     *
     * @param bool $is_checkout Whether or not we are on the checkout page
     */
    
return apply_filters(
        
'cfw_is_checkout',
        ( 
function_exists'is_checkout' ) && is_checkout() ) &&
        ! 
is_order_received_page() &&
        ! 
is_checkout_pay_page()
    );
}

/**
 * @return bool
 */
function cfw_is_checkout_pay_page(): bool {
    
/**
     * Filter is_checkout_pay_page()
     *
     * @since 3.0.0
     *
     * @param bool $is_checkout_pay_page Whether or not we are on the checkout pay page
     */
    
return apply_filters(
        
'cfw_is_checkout_pay_page',
        
function_exists'is_checkout_pay_page' ) &&
        
is_checkout_pay_page() &&
        
cfw_get_active_template()->supports'order-pay' ) &&
        
PlanManager::can_access_feature'enable_order_pay'PlanManager::PLUS )
    );
}

/**
 * @return bool
 */
function cfw_is_order_received_page(): bool {
    
/**
     * Filter is_order_received_page()
     *
     * @since 3.0.0
     *
     * @param bool $is_order_received_page Whether or not we are on the order received page
     */
    
return apply_filters(
        
'cfw_is_order_received_page',
        
function_exists'is_order_received_page' ) &&
        
is_order_received_page() &&
        
cfw_get_active_template()->supports'order-received' ) &&
        
PlanManager::can_access_feature'enable_thank_you_page'PlanManager::PLUS )
    );
}

/**
 * @return bool
 */
function is_cfw_page(): bool {
    return 
cfw_is_checkout() || cfw_is_checkout_pay_page() || cfw_is_order_received_page();
}

/**
 * Determines whether CheckoutWC templates can load on the frontend
 *
 * @return bool
 */
function cfw_is_enabled(): bool {
    
$valid_license       UpdatesManager::instance()->license_is_valid();
    
$templates_enabled   SettingsManager::instance()->get_setting'enable' ) === 'yes';
    
$is_admin            current_user_can'manage_options' );
    
$user_can_access     = ( $valid_license && $templates_enabled ) || $is_admin;
    
$forcefully_disabled defined'CFW_DISABLE_TEMPLATES' ) || isset( $_COOKIE['CFW_DISABLE_TEMPLATES'] ) || isset( $_GET['bypass-cfw'] );

    return 
$user_can_access && ! $forcefully_disabled;
}

/**
 * Get phone field setting
 *
 * @return boolean
 */
function cfw_is_phone_fields_enabled(): bool {
    return 
'hidden' !== get_option'woocommerce_checkout_phone_field''required' );
}

/**
 * Match new guest order to existing account if it exists
 *
 * @param $order_id
 */
function cfw_maybe_match_new_order_to_user_account$order_id ) {
    
$order wc_get_order$order_id );
    
$user  $order->get_user();

    if ( ! 
$user ) {
        
$user_data get_user_by'email'$order->get_billing_email() );

        if ( ! empty( 
$user_data->ID ) ) {
            try {
                
$order->set_customer_id$user_data->ID );
                
$order->save();
            } catch ( 
\WC_Data_Exception $e ) {
                
error_log"CheckoutWC: Error matching {$order_id} to customer {$user_data->ID});
            }
        }
    }
}

/**
 * Match old guest orders to new account if they exist
 *
 * @param $user_id
 */
function cfw_maybe_link_orders_at_registration$user_id ) {
    
wc_update_new_customer_past_orders$user_id );
}

function 
cfw_get_plugin_template_path(): string {
    return 
CFW_PATH_BASE '/templates';
}

function 
cfw_get_user_template_path(): string {
    return 
get_stylesheet_directory() . '/checkout-wc';
}

function 
cfw_get_active_template(): Template {
    
$active_template_slug SettingsManager::instance()->get_setting'active_template' );
    return new 
Template( empty( $active_template_slug ) ? 'default' $active_template_slug );
}

/**
 * @return Template[]
 */
function cfw_get_available_templates(): array {
    return 
Template::get_all_available();
}

function 
cfw_frontend() {
    
// Enqueue Assets
    
( new AssetManager() )->init();

    if ( ! 
is_cfw_page() ) {
        return;
    }

    
// Output Templates
    
if ( SettingsManager::instance()->get_setting'template_loader' ) === 'content' ) {
        
Content::checkout();
        
Content::order_pay();
        
Content::order_received();

        return;
    }

    
add_action(
        
'template_redirect',
        function() {
            
Redirect::template_redirect();
        },
        
apply_filters'cfw_template_redirect_priority'11 )
    );
}

/**
 * @return bool|\WC_Order|\WC_Order_Refund
 */
function cfw_get_order_received_order() {
    global 
$wp;

    
$order_id $wp->query_vars['order-received'];
    
$order    false;

    
$order_id  apply_filters'woocommerce_thankyou_order_id'absint$order_id ) );
    
$order_key apply_filters'woocommerce_thankyou_order_key', empty( $_GET['key'] ) ? '' wc_cleanwp_unslash$_GET['key'] ) ) ); // WPCS: input var ok, CSRF ok.

    
if ( $order_id ) {
        
$order wc_get_order$order_id );
        if ( ! 
$order || ! hash_equals$order->get_order_key(), $order_key ) ) {
            
$order false;
        }
    }

    return 
$order;
}

/**
 * @return FormAugmenter|null
 */
function cfw_get_form(): FormAugmenter {
    return 
FormAugmenter::instance();
}

/**
 * @return bool
 */
function cfw_is_thank_you_page_active(): bool {
    return 
PlanManager::can_access_feature'enable_thank_you_page'PlanManager::PLUS );
}

/**
 * @return bool
 */
function cfw_is_thank_you_view_order_page_active(): bool {
    return 
cfw_is_thank_you_page_active() && PlanManager::can_access_feature'override_view_order_template'PlanManager::PLUS );
}

/**
 * @return false|string
 */
function cfw_get_logo_url() {
    
$logo_attachment_id SettingsManager::instance()->get_setting'logo_attachment_id' );

    return 
wp_get_attachment_url$logo_attachment_id );
}

function 
cfw_logo() {
    
/**
     * Filters header logo / title link URL
     *
     * @since 3.0.0
     *
     * @param string $url The link URL
     */
    
$url apply_filters'cfw_header_home_url'get_home_url() );

    
/**
     * Filters header logo / title link URL
     *
     * @since 5.3.0
     *
     * @param string $url The link URL
     */
    
$blog_name apply_filters'cfw_header_blog_name'get_bloginfo'name' ) );

    
$logo_url cfw_get_logo_url();
    
?>
    <div class="cfw-logo">
        <a title="<?php echo html_entity_decode$blog_nameENT_QUOTES ); ?>" href="<?php echo $url?>" class="<?php echo ! empty( $logo_url ) ? 'logo' ''?>">
            <?php if ( empty( $logo_url ) ) : ?>
                <?php echo html_entity_decode$blog_nameENT_QUOTES ); ?>
            <?php endif; ?>
        </a>
    </div>
    <?php
}

/**
 * Add WP theme styles to list of blocked style handles.
 *
 * @param $styles
 *
 * @return array
 */
function cfw_remove_theme_styles$styles ): array {
    global 
$wp_styles;

    
$theme_directory_uri get_theme_root_uri();
    
$theme_directory_uri str_replace( array( 'http:''https:' ), ''$theme_directory_uri ); // handle both http/https/and relative protocol URLs

    
foreach ( $wp_styles->registered as $wp_style ) {
        if ( ! empty( 
$wp_style->src ) && stripos$wp_style->src$theme_directory_uri ) !== false && stripos$wp_style->src'/checkout-wc/' ) === false ) {
            
$styles[] = $wp_style->handle;
        }
    }

    return 
$styles;
}

/**
 * Add WP theme styles to list of blocked style handles.
 *
 * @param $scripts
 *
 * @return array
 */
function cfw_remove_theme_scripts$scripts ): array {
    global 
$wp_scripts;

    
$theme_directory_uri get_theme_root_uri();
    
$theme_directory_uri str_replace( array( 'http:''https:' ), ''$theme_directory_uri ); // handle both http/https/and relative protocol URLs

    
foreach ( $wp_scripts->registered as $wp_script ) {
        if ( ! empty( 
$wp_script->src ) && stripos$wp_script->src$theme_directory_uri ) !== false && stripos$wp_script->src'/checkout-wc/' ) === false ) {
            
$scripts[] = $wp_script->handle;
        }
    }

    return 
$scripts;
}

/**
 * For gateways that add buttons above checkout form
 *
 * @param string $class
 * @param string $id
 * @param string $style
 */
function cfw_add_separator$class ''$id ''$style '' ) {
    if ( ! 
defined'CFW_PAYMENT_BUTTON_SEPARATOR' ) ) {
        
define'CFW_PAYMENT_BUTTON_SEPARATOR'true );
    } else {
        return;
    }
    
?>
    <div id="payment-info-separator-wrap" class="<?php echo $class?>">
        <p <?php echo ( $id ) ? "id='{$id}'" ''?> <?php echo ( $style ) ? "style='{$style}'" ''?> class="pay-button-separator">
            <span>
                <?php
                
/**
                 * Filters payment request button separator text
                 *
                 * @since 2.0.0
                 *
                 * @param string $separator_label The separator label (default: Or)
                 */
                
echo esc_htmlapply_filters'cfw_express_pay_separator_text'__'Or''checkout-wc' ) ) );
                
?>
            </span>
        </p>
    </div>
    <?php
}

/**
 * @param string $hook
 * @param string $function_name
 * @param int $priority
 * @return false|mixed
 */
function cfw_get_hook_instance_objectstring $hookstring $function_nameint $priority 10 ) {
    global 
$wp_filter;

    
$existing_hooks $wp_filter$hook ];

    if ( 
$existing_hooks$priority ] ) {
        foreach ( 
$existing_hooks$priority ] as $key => $callback ) {
            if ( 
false !== stripos$key$function_name ) ) {
                return 
$callback['function'][0];
            }
        }
    }

    return 
false;
}

/**
 * @return bool
 */
function cfw_is_login_at_checkout_allowed(): bool {
    return 
'yes' === get_option'woocommerce_enable_checkout_login_reminder' );
}

/**
 * @return bool
 */
function cfw_is_enhanced_login_enabled(): bool {
    
$enable_enhanced_login apply_filters_deprecated'cfw_suppress_default_login_form', array( SettingsManager::instance()->get_setting'login_style' ) !== 'woocommerce' ), 'CheckoutWC 5.3.7''cfw_enable_enhanced_login' );

    return 
apply_filters'cfw_enable_enhanced_login'$enable_enhanced_login ) && cfw_is_login_at_checkout_allowed();
}

/**
 * @param array $cart_data
 * @return bool
 */
function cfw_update_cart( array $cart_data ): bool {
    try {
        foreach ( 
$cart_data as $cart_item_key => $value ) {
            
$cart_item WC()->cart->get_cart_item$cart_item_key );

            if ( 
null === $cart_item ) {
                
WC()->cart->remove_cart_item$cart_item_key );
                continue;
            }

            
/** @var \WC_Product $cart_item_product */
            
$cart_item_product $cart_item['data'];

            if ( ! 
$cart_item_product || ! $cart_item_product->exists() ) {
                continue;
            }

            
$max_quantity apply_filters'woocommerce_quantity_input_max'$cart_item_product->get_max_purchase_quantity() > $cart_item_product->get_max_purchase_quantity() : PHP_INT_MAX$cart_item_product );

            if ( 
$value['qty'] > $max_quantity ) {
                
$value['qty'] = $max_quantity;
            }

            
/**
             * Remove items from the cart contents
             * Ensures things like subscriptions update their output properly
             * Note: Using strval() here instead of intval to handle partial quantities like 0.5
             *
             * We don't use WC()->cart->set_quantity()'s understanding of setting a 0 quantity because it causes a bug we can't remember.
             */
            
if ( '0' === strval$value['qty'] ) ) {
                
WC()->cart->remove_cart_item$cart_item_key );
            } elseif ( 
floatvalWC()->cart->cart_contents$cart_item_key ]['quantity'] ) !== floatval$value['qty'] ) ) {
                
WC()->cart->set_quantity$cart_item_key$value['qty'], false );
            }
        }
    } catch ( 
Exception $e ) {
        return 
false;
    }

    
// Calculate shipping before totals. This will ensure any shipping methods that affect things like taxes are chosen prior to final totals being calculated. Ref: #22708.
    // Without these lines, changes aren't saved
    
WC()->cart->calculate_shipping();
    
WC()->cart->calculate_totals();

    return 
true;
}

function 
cfw_side_cart_iconbool $return false ) {
    
$output \Objectiv\Plugins\Checkout\Features\SideCart::get_cart_icon();

    if ( 
$return ) {
        return 
$output;
    }

    echo 
$output;
}