-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
executable file
·1231 lines (937 loc) · 37.8 KB
/
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
<?php
add_action('wp_enqueue_scripts', 'ch_theme_enqueue_styles');
function ch_theme_enqueue_styles() {
$parent_style = 'creditcard-parent-style';
wp_enqueue_style($parent_style, get_template_directory_uri() . '/style.css');
wp_enqueue_style('cardhero',
get_stylesheet_directory_uri() . '/style.css',
array($parent_style)
);
}
/*
Fixes WP5.0 & WPBakery Page Builder loses Role Settings upon
You can set the post type for which the editor should be
available by adding the following code to functions.php:
Author: Jacktator
Plugin: WPBakery Page Builder 5.6
Reference: https://stackoverflow.com/questions/49316654/wp-bakery-page-builder-loses-settings-in-role-manager?rq=1
*/
add_action('vc_before_init', 'Use_wpBakery');
function Use_wpBakery() {
$vc_list = array('page', 'credit_cards', 'reward_programs', 'companies', 'cpt_services');
vc_set_default_editor_post_types($vc_list);
vc_editor_set_post_types($vc_list);
}
/*
Enable 'show_in_rest' option in ACF & ACF Pro
Author: Jacktator
Plugin: ACF Pro 5.7.9
Reference: https://github.com/airesvsg/acf-to-rest-api
*/
// Enable the option show in rest
add_filter('acf/rest_api/field_settings/show_in_rest', '__return_true');
// Enable the option edit in rest
add_filter('acf/rest_api/field_settings/edit_in_rest', '__return_true');
/*
Add shortcode support for ACF Table Field
Author: Jacktator
Plugin: Advanced Custom Field Table Field 1.2.6
Reference: https://wordpress.org/plugins/advanced-custom-fields-table-field/
*/
// function shortcode_acf_tablefield($atts) {
// $a = shortcode_atts(array(
// 'field-name' => false,
// 'post-id' => false,
// ), $atts);
// $table = get_field($a['field-name'], $a['post-id']);
// $return = '';
// if ($table) {
// $return .= '<table style="width: 100%;">';
// if ($table['header']) {
// $return .= '<thead>';
// $return .= '<tr>';
// foreach ($table['header'] as $th) {
// $return .= '<th>';
// $return .= $th['c'];
// $return .= '</th>';
// }
// $return .= '</tr>';
// $return .= '</thead>';
// }
// $return .= '<tbody>';
// foreach ($table['body'] as $tr) {
// $return .= '<tr>';
// foreach ($tr as $td) {
// $return .= '<td>';
// $return .= $td['c'];
// $return .= '</td>';
// }
// $return .= '</tr>';
// }
// $return .= '</tbody>';
// $return .= '</table>';
// }
// return $return;
// }
// add_shortcode('table', 'shortcode_acf_tablefield');
/*
Create shortcode for displaying Earn Table using CPT and ACF.
Author: Jacktator
Plugin: Custom Post Type UI 1.6.1
Plugin: Advanced Custom Fields PRO 5.7.9
Reference: https://wordpress.stackexchange.com/a/291525/134082
Usage: [ch_credit_card_rewards_programs_earn_table rewards_program="24"] // Generate the Reward Table, Based on Earning 2 Credit Card Points per Dollar, and rewards_program ID is 24
*/
function ch_generate_credit_card_rewards_programs_earn_table($atts) {
// TODO
}
add_shortcode('ch_credit_card_rewards_programs_earn_table', 'ch_generate_credit_card_rewards_programs_earn_table');
/*
Create Tabs
Author: Jacktator
Plugin: Visual Composer Extensions All In One 3.4.9.3
ShortCode: [cq_vc_tab_item]
Usage: [ch_credit_card_rewards_programs_earn_tabs] // Renders Rewards Programs in Tabs, Based on Earning 2 Credit Card Points per Dollar
*/
function ch_generate_credit_card_rewards_programs_earn_tabs($atts) {
// extract attributs
extract(shortcode_atts(array(
'rewards_program',
'post_id' => false, // Default
'format_value' => true, // Default
), $atts));
// extract attributs
// Construct Tabs
$rewards_programs_tabs = "";
// Construct Tabs
$rewards_programs_tabs .= '[cq_vc_tabs rotatetabs="0"]';
$rewards_programs = get_field('rewards_programs'); // Repeater
if (have_rows('rewards_programs')) {
while (have_rows('rewards_programs')) {
the_row();
// Feth Rewards Program Data
$rewards_program = get_sub_field('rewards_program');
$rewards_program_unit = get_field('unit', $rewards_program->ID);
// Construct Single Tab Item
$rewards_programs_tabs .= '[cq_vc_tab_item tabtitle="' . $rewards_program->post_title . '"]';
// Find the Max Earn Rate
if (have_rows('earn_rates')) {
$rewards_programs_table = '';
// Construct Table Head
$table_head = '<table style="width: 100%;">
<thead>
<tr>
<th>Categories</th>
<th>Earn Rate</th>
</tr>
</thead>';
$rewards_programs_table .= $table_head;
// Construct Table Body
$rewards_programs_table .= '<tbody>';
while (have_rows('earn_rates')) {
the_row();
$earn_rate = get_sub_field('earn_rate');
$categories = get_sub_field('categories');
$notes = get_sub_field('notes');
$rewards_programs_table .= '<tr>';
$rewards_programs_table .= '<td>' . implode(", ", $categories) . '</td>';
$rewards_programs_table .= '<td> Earn <strong>' . $earn_rate . ' ' . $rewards_program_unit . '</strong> Per Dollar. </td>';
$rewards_programs_table .= '</tr>';
}
// Close Table Body
$rewards_programs_table .= '</tbody>';
// Close Table
$rewards_programs_table .= '</table>';
// $rewards_programs_table = '[ch_generate_credit_card_rewards_programs_earn_table rewards_program="' . $rewards_program->ID .'"]';
// Return Table
$rewards_programs_tabs .= $rewards_programs_table;
}
// Close Single Tab Item
$rewards_programs_tabs .= '[/cq_vc_tab_item]';
}
}
// Close Tabs
$rewards_programs_tabs .= '[/cq_vc_tabs]';
return do_shortcode($rewards_programs_tabs);
}
add_shortcode('ch_credit_card_rewards_programs_earn_tabs', 'ch_generate_credit_card_rewards_programs_earn_tabs');
/*
Create shortcode for displaying Maximum Earn Rate Table using CPT and ACF.
Author: Jacktator
Plugin: Custom Post Type UI 1.6.1
Plugin: Advanced Custom Fields PRO 5.7.9
Reference: https://wordpress.stackexchange.com/a/291525/134082
Usage: [ch_credit_card_rewards_programs_redemption_table earn_rate="2" rewards_program="24"] // Generate the Reward Table, Based on Earning 2 Credit Card Points per Dollar, and rewards_program ID is 24
*/
function ch_generate_credit_card_rewards_programs_redemption_table($atts) {
// extract attributs
extract(shortcode_atts(array(
'earn_rate' => 1, // Default earn_rate to 1
'rewards_program' => 0, // ID of Rewards_Program Object
'post_id' => false, // Default
'format_value' => true, // Default
), $atts));
// extract attributs
if (have_rows('redemption_parnters', $rewards_program)) {
$table = '';
// Construct Table Head
$table_head = '<table style="width: 100%;">
<thead>
<tr>
<th>Reward Program</th>
<th>Maximum Earn Rate</th>
</tr>
</thead>';
$table .= $table_head;
// Construct Table Body
$table .= '<tbody>';
while (have_rows('redemption_parnters', $rewards_program)) {
the_row();
$partner_program = get_sub_field('partner_program');
$partner_program_fields = get_field_objects($partner_program->ID);
$partner_program_company = get_field('company', $partner_program->ID); // Deprecated, use get_field('provider'); instead.
if (!$partner_program_company) {
$partner_program_company = get_field('provider', $partner_program->ID)->post_title;
}
$partner_program_program = get_field('program', $partner_program->ID); // Deprecated, use $partner_program->post_title; instead.
if (!$partner_program_program) {
$partner_program_program = $partner_program->post_title;
}
$partner_program_unit = get_field('unit', $partner_program->ID);
$flexible_points_currency = get_field('flexible_points_currency', $partner_program->ID);
$partner_program_points_value = get_field('points_value', $partner_program->ID);
$redemption_rate = get_sub_field('redemption_rate');
$notes = get_sub_field('notes');
$table .= '<tr>';
$table .= '<td>' . $partner_program_company . ' - ' . $partner_program_program . '</td>';
if ($value === 0) {
$table .= '<td>Not Available</td>';
} else {
$table .= '<td> $1 earns <strong>' . sigFig($redemption_rate * $earn_rate, 4) . ' ' . $partner_program_unit . '.</strong> <br/><small>' . $notes . '</small></td>';
}
$table .= '</tr>';
}
// Close Table Body
$table .= '</tbody>';
// Close Table
$table .= '</table>';
return do_shortcode($table);
} else {
return 'Reward Program has no Redemption Partner.';
}
}
add_shortcode('ch_credit_card_rewards_programs_redemption_table', 'ch_generate_credit_card_rewards_programs_redemption_table');
/*
Create Tabs
Author: Jacktator
Plugin: Visual Composer Extensions All In One 3.4.9.3
ShortCode: [cq_vc_tab_item]
Usage: [ch_credit_card_rewards_programs_redemption_tabs] // Renders Rewards Programs in Tabs, Based on Earning 2 Credit Card Points per Dollar
*/
function ch_generate_credit_card_rewards_programs_redemption_tabs($atts) {
// extract attributs
extract(shortcode_atts(array(
'earn_rate' => 1, // Default earn_rate to 1, Deprecated
'post_id' => false, // Default
'format_value' => true, // Default
), $atts));
// Store Flexible Points for Second Tier Table
$flexible_partner_programs = array();
$excluding_partner_programs = array();
$rewards_programs = get_field('rewards_programs'); // Repeater
if (have_rows('rewards_programs')) {
// Construct Tabs
$rewards_programs_tabs = "";
// Construct Tabs
$rewards_programs_tabs .= '[cq_vc_tabs rotatetabs="0"]';
while (have_rows('rewards_programs')) {
the_row();
// Feth Rewards Program Data
$rewards_program = get_sub_field('rewards_program');
$max_earn_rate = 0;
// Find the Max Earn Rate
if (have_rows('earn_rates')) {
while (have_rows(earn_rates)) {
the_row();
$earn_rate = get_sub_field('earn_rate');
if ($earn_rate > $max_earn_rate) {
$max_earn_rate = $earn_rate;
}
}
}
// Construct Single Tab Item
$rewards_programs_tabs .= '[cq_vc_tab_item tabtitle="' . $rewards_program->post_title . '"]';
$rewards_programs_table = '[ch_credit_card_rewards_programs_redemption_table earn_rate="' . $max_earn_rate . '" rewards_program="' . $rewards_program->ID . '"]';
// Return Table
$rewards_programs_tabs .= $rewards_programs_table;
// Close Single Tab Item
$rewards_programs_tabs .= '[/cq_vc_tab_item]';
}
// Close Tabs
$rewards_programs_tabs .= '[/cq_vc_tabs]';
return do_shortcode($rewards_programs_tabs);
} else {
return "Error: Rewards Programs is empty.";
}
}
add_shortcode('ch_credit_card_rewards_programs_redemption_tabs', 'ch_generate_credit_card_rewards_programs_redemption_tabs');
/*
Create shortcode for displaying Further Earn Rate Table using CPT and ACF.
Author: Jacktator
Plugin: Custom Post Type UI 1.6.1
Plugin: Advanced Custom Fields PRO 5.7.9
Reference: https://wordpress.stackexchange.com/a/291525/134082
Usage: [ch_credit_card_rewards_programs_more_redemption_table earn_rate="2" rewards_program="24"] // Generate the Reward Table with More redemption, Based on Earning 2 Credit Card Points per Dollar, and rewards_program ID is 24
*/
function ch_generate_credit_card_rewards_programs_more_redemption_table($atts) {
// extract attributs
extract(shortcode_atts(array(
'earn_rate' => 1, // Default earn_rate to 1
'rewards_program' => 0, // ID of Rewards_Program Object
'post_id' => false, // Default
'format_value' => true, // Default
), $atts));
// extract attributs
// Store Flexible Points for Second Tier Table
$flexible_partner_programs = array();
$excluding_partner_programs = array();
if (have_rows('redemption_parnters', $rewards_program)) {
$table = '';
// Construct Table Head
$table_head = '<table style="width: 100%;">';
$table .= $table_head;
// Add all available redemption partners as primary partners
while (have_rows('redemption_parnters', $rewards_program)) {
the_row();
$partner_program = get_sub_field('partner_program');
$partner_program_fields = get_field_objects($partner_program->ID);
$partner_program_company = get_field('company', $partner_program->ID); // Deprecated, use get_field('provider'); instead.
if (!$partner_program_company) {
$partner_program_company = get_field('provider', $partner_program->ID)->post_title;
}
$partner_program_program = get_field('program', $partner_program->ID); // Deprecated, use $partner_program->post_title; instead.
if (!$partner_program_program) {
$partner_program_program = $partner_program->post_title;
}
$partner_program_unit = get_field('unit', $partner_program->ID);
$flexible_points_currency = get_field('flexible_points_currency', $partner_program->ID);
$partner_program_points_value = get_field('points_value', $partner_program->ID);
$redemption_rate = get_sub_field('redemption_rate');
$notes = get_sub_field('notes');
// Add program to $excluding_partner_programs to avoid duplication when handle second tier redemotion
array_push($excluding_partner_programs, $partner_program_program);
// Add Flexible Points Program to Array
if (!in_array($partner_program, $excluding_partner_programs) && $flexible_points_currency) {
array_push($flexible_partner_programs, $partner_program);
}
}
// Construct Secondary Table Body
foreach ($flexible_partner_programs as $flexible_partner_program) {
$flexible_partner_program_company = get_field('company', $flexible_partner_program->ID); // Deprecated, use get_field('provider'); instead.
if (!$flexible_partner_program_company) {
$flexible_partner_program_company = get_field('provider', $flexible_partner_program->ID)->post_title;
}
$flexible_partner_program_program = get_field('program', $flexible_partner_program->ID); // Deprecated, use $partner_program->post_title; instead.
if (!$flexible_partner_program_program) {
$flexible_partner_program_program = $flexible_partner_program->post_title;
}
// Construct Secondary Table Head
$table .= '
<thead>
<tr>
<th> Reward Program via ' . $flexible_partner_program_company . ' - ' . $flexible_partner_program_program . ' </th>
<th>Maximum Earn Rate</th>
</tr>
</thead>';
// Construct Secondary Table Body
$table .= '<tbody>';
while (have_rows('redemption_parnters', $flexible_partner_program->ID)) {
// Render Redemption
the_row();
$second_tier_partner_program = get_sub_field('partner_program');
$second_tier_partner_program_fields = get_field_objects($second_tier_partner_program->ID);
$second_tier_partner_program_company = get_field('company', $second_tier_partner_program->ID); // Deprecated, use get_field('provider'); instead.
if (!$second_tier_partner_program_company) {
$second_tier_partner_program_company = get_field('provider', $second_tier_partner_program->ID)->post_title;
}
$second_tier_partner_program_program = get_field('program', $second_tier_partner_program->ID); // Deprecated, use $partner_program->post_title; instead.
if (!$second_tier_partner_program_program) {
$second_tier_partner_program_program = $second_tier_partner_program->post_title;
}
$second_tier_partner_program_unit = get_field('unit', $second_tier_partner_program->ID);
$second_tier_flexible_points_currency = get_field('flexible_points_currency', $second_tier_partner_program->ID);
$second_tier_partner_program_points_value = get_field('points_value', $second_tier_partner_program->ID);
// Only Add new partner in second tier redemption
// if (!in_array($second_tier_partner_program_program, $excluding_partner_programs)) {
$second_tier_redemption_rate = get_sub_field('redemption_rate');
$second_tier_notes = get_sub_field('notes');
$table .= '<tr>';
$table .= '<td>' . $second_tier_partner_program_company . ' - ' . $second_tier_partner_program_program . '</td>';
if ($value === 0) {
$table .= '<td>Not Available</td>';
} else {
$table .= '<td> $1 earns <strong>' . sigFig($redemption_rate * $second_tier_redemption_rate * $earn_rate, 4) . ' ' . $second_tier_partner_program_unit . '.</strong> <br/><small>' . $flexible_partner_program_program . ' 1: ' . $redemption_rate . ' (' . $notes . ').<br/>' . $second_tier_partner_program_unit . ' 1: ' . $second_tier_redemption_rate . ' (' . $second_tier_notes . ').</small></td>';
}
$table .= '</tr>';
// DO NOT add program to $excluding_partner_programs to avoid duplication when handle second tier redemotion
// array_push($excluding_partner_programs, $flexible_partner_program);
// Add Flexible Points Program to Array
if (!in_array($flexible_partner_program, $excluding_partner_programs) && $flexible_points_currency) {
array_push($flexible_partner_programs, $partner_program);
}
// }
}
$table .= '</tbody>';
}
// Close Table
$table .= '</table>';
return do_shortcode($table);
} else {
return 'Reward Program has no Redemption Partner.';
}
}
add_shortcode('ch_credit_card_rewards_programs_more_redemption_table', 'ch_generate_credit_card_rewards_programs_more_redemption_table');
/*
Create Tabs
Author: Jacktator
Plugin: Visual Composer Extensions All In One 3.4.9.3
ShortCode: [cq_vc_tab_item]
Usage: [ch_credit_card_rewards_programs_more_redemption_tabs] // Renders Rewards Programs in Tabs, Based on Earning 2 Credit Card Points per Dollar
*/
function ch_generate_credit_card_rewards_programs_more_redemption_tabs($atts) {
// extract attributs
extract(shortcode_atts(array(
'earn_rate' => 1, // Default earn_rate to 1, Deprecated
'post_id' => false, // Default
'format_value' => true, // Default
), $atts));
// Store Flexible Points for Second Tier Table
$flexible_partner_programs = array();
$excluding_partner_programs = array();
$rewards_programs = get_field('rewards_programs'); // Repeater
if (have_rows('rewards_programs')) {
// Construct Tabs
$rewards_programs_tabs = "";
// Construct Tabs
$rewards_programs_tabs .= '[cq_vc_tabs rotatetabs="0"]';
while (have_rows('rewards_programs')) {
the_row();
// Feth Rewards Program Data
$rewards_program = get_sub_field('rewards_program');
$max_earn_rate = 0;
// Find the Max Earn Rate
if (have_rows('earn_rates')) {
while (have_rows(earn_rates)) {
the_row();
$earn_rate = get_sub_field('earn_rate');
if ($earn_rate > $max_earn_rate) {
$max_earn_rate = $earn_rate;
}
}
}
// Construct Single Tab Item
$rewards_programs_tabs .= '[cq_vc_tab_item tabtitle="' . $rewards_program->post_title . '"]';
$rewards_programs_table = '[ch_credit_card_rewards_programs_more_redemption_table earn_rate="' . $max_earn_rate . '" rewards_program="' . $rewards_program->ID . '"]';
// Return Table
$rewards_programs_tabs .= $rewards_programs_table;
// Close Single Tab Item
$rewards_programs_tabs .= '[/cq_vc_tab_item]';
}
// Close Tabs
$rewards_programs_tabs .= '[/cq_vc_tabs]';
return do_shortcode($rewards_programs_tabs);
} else {
return "Error: Rewards Programs is empty.";
}
}
add_shortcode('ch_credit_card_rewards_programs_more_redemption_tabs', 'ch_generate_credit_card_rewards_programs_more_redemption_tabs');
/*
Create shortcode for displaying Redemption Table using CPT and ACF.
Author: Jacktator
Plugin: Custom Post Type UI 1.6.1
Plugin: Advanced Custom Fields PRO 5.7.9
Reference: https://wordpress.stackexchange.com/a/291525/134082
Usage: [ch_redemption_table] // Meaning Earning 2 Credit Card Points per Dollar
*/
function ch_generate_redemption_table($atts) {
// extract attributs
extract(shortcode_atts(array(
'post_id' => false, // Default
'format_value' => true, // Default
), $atts));
$base_unit = get_field('unit');
// Store Flexible Points for Second Tier Table
$flexible_partner_programs = array();
$excluding_partner_programs = array();
if (have_rows('redemption_parnters')) {
$table = '';
// Construct Table Head
$table_head = '<table style="width: 100%;">
<thead>
<tr>
<th>Company</th>
<th>Reward Program</th>
<th>Redemption Rate</th>
<th>Notes</th>
</tr>
</thead>';
$table .= $table_head;
// Construct Primary Table Body
$table .= '<tbody>';
while (have_rows('redemption_parnters')) {
// Render Redemption
the_row();
$partner_program = get_sub_field('partner_program');
$minimum = get_sub_field('minimum');
$increment = get_sub_field('increment');
$partner_program_fields = get_field_objects($partner_program->ID);
$partner_program_company = get_field('company', $partner_program->ID); // Deprecated, use get_field('provider'); instead.
if (!$partner_program_company) {
$partner_program_company = get_field('provider', $partner_program->ID)->post_title;
}
$partner_program_program = get_field('program', $partner_program->ID); // Deprecated, use $partner_program->post_title; instead.
if (!$partner_program_program) {
$partner_program_program = $partner_program->post_title;
}
$partner_program_unit = get_field('unit', $partner_program->ID);
$flexible_points_currency = get_field('flexible_points_currency', $partner_program->ID);
$partner_program_points_value = get_field('points_value', $partner_program->ID);
$redemption_rate = get_sub_field('redemption_rate');
$notes = get_sub_field('notes');
$table .= '<tr>';
$table .= '<td>' . $partner_program_company . '</td>';
$table .= '<td>' . $partner_program_program . '</td>';
if ($value === 0) {
$table .= '<td colspan="2">Not Available</td>';
} else {
$table .= '<td> 1 ' . $base_unit . ' = <strong>' . $redemption_rate . ' ' . $partner_program_unit . '.</strong> <br/><small>Minimum ' . $minimum . ', increment ' . $increment . '. ' . '</small></td>';
$table .= '<td>' . $notes . '. ' . '</td>';
}
$table .= '</tr>';
// Add program to $excluding_partner_programs to avoid duplication when handle second tier redemotion
array_push($excluding_partner_programs, $partner_program_program);
// Add Flexible Points Program to Array
if (!in_array($partner_program, $excluding_partner_programs) && $flexible_points_currency) {
array_push($flexible_partner_programs, $partner_program);
}
}
$table .= '</tbody>';
// Construct Secondary Table Body
foreach ($flexible_partner_programs as $flexible_partner_program) {
$flexible_partner_program_company = get_field('company', $flexible_partner_program->ID); // Deprecated, use get_field('provider'); instead.
if (!$flexible_partner_program_company) {
$flexible_partner_program_company = get_field('provider', $flexible_partner_program->ID)->post_title;
}
$flexible_partner_program_program = get_field('program', $flexible_partner_program->ID); // Deprecated, use $partner_program->post_title; instead.
if (!$flexible_partner_program_program) {
$flexible_partner_program_program = $flexible_partner_program->post_title;
}
// Construct Secondary Table Head
$table .= '
<thead>
<tr>
<th colspan="2"> Reward Program via ' . $flexible_partner_program_company . ' - ' . $flexible_partner_program_program . ' </th>
<th> Effective Redemption Rate</th>
<th> Notes</th>
</tr>
</thead>';
// Construct Secondary Table Body
$table .= '<tbody>';
while (have_rows('redemption_parnters', $flexible_partner_program->ID)) {
// Render Redemption
the_row();
$second_tier_partner_program = get_sub_field('partner_program');
$second_tier_minimum = get_sub_field('minimum');
$second_tier_increment = get_sub_field('increment');
$second_tier_partner_program_fields = get_field_objects($second_tier_partner_program->ID);
$second_tier_partner_program_company = get_field('company', $second_tier_partner_program->ID); // Deprecated, use get_field('provider'); instead.
if (!$second_tier_partner_program_company) {
$second_tier_partner_program_company = get_field('provider', $second_tier_partner_program->ID)->post_title;
}
$second_tier_partner_program_program = get_field('program', $second_tier_partner_program->ID); // Deprecated, use $partner_program->post_title; instead.
if (!$second_tier_partner_program_program) {
$second_tier_partner_program_program = $second_tier_partner_program->post_title;
}
$second_tier_partner_program_unit = get_field('unit', $second_tier_partner_program->ID);
$second_tier_flexible_points_currency = get_field('flexible_points_currency', $second_tier_partner_program->ID);
$second_tier_partner_program_points_value = get_field('points_value', $second_tier_partner_program->ID);
// Only Add new partner in second tier redemption
// if (!in_array($second_tier_partner_program_program, $excluding_partner_programs)) {
$second_tier_redemption_rate = get_sub_field('redemption_rate');
$second_tier_notes = get_sub_field('notes');
$table .= '<tr>';
$table .= '<td>' . $second_tier_partner_program_company . '</td>';
$table .= '<td>' . $second_tier_partner_program_program . '</td>';
if ($value === 0) {
$table .= '<td>Not Available</td>';
} else {
$table .= '<td> 1 ' . $base_unit . ' = <strong>' . sigFig($redemption_rate * $second_tier_redemption_rate, 4) . ' ' . $second_tier_partner_program_unit . '.</strong> <br/><small>' . $flexible_partner_program_program . ' 1: ' . $redemption_rate . ' (Minimum ' . $minimum . ', increment ' . $increment . ').<br/>' . $second_tier_partner_program_unit . ' 1: ' . $second_tier_redemption_rate . ' (Minimum ' . $second_tier_minimum . ', increment ' . $second_tier_increment . ').</small></td>';
$table .= '<td>' . $notes . '<br/>' . $second_tier_notes . '</td>';
}
$table .= '</tr>';
// DO NOT add program to $excluding_partner_programs to avoid duplication when handle second tier redemotion
// array_push($excluding_partner_programs, $flexible_partner_program);
// Add Flexible Points Program to Array
if (!in_array($flexible_partner_program, $excluding_partner_programs) && $flexible_points_currency) {
array_push($flexible_partner_programs, $partner_program);
}
// }
}
$table .= '</tbody>';
}
// Close Table
$table .= '</table>';
// Return Table
return do_shortcode($table);
} else {
return 'redemption_parnters is empty.';
}
}
add_shortcode('ch_redemption_table', 'ch_generate_redemption_table');
/*
Trim Number to 4 Significant Digits.
Author: Jacktator
Reference: https://stackoverflow.com/a/48283297/3381997
*/
function sigFig($value, $digits) {
if ($value == 0) {
$decimalPlaces = $digits - 1;
} elseif ($value < 0) {
$decimalPlaces = $digits - floor(log10($value * -1)) - 1;
} else {
$decimalPlaces = $digits - floor(log10($value)) - 1;
}
$answer = round($value, $decimalPlaces);
return $answer;
}
/*
Create shortcode for displaying Credit Card Image using ShadowCard CPT and ACF.
Author: Jacktator
Plugin: Custom Post Type UI 1.6.1
Plugin: Advanced Custom Fields PRO 5.7.9
Plugin: Visual Composer Extensions All In One 3.4.9.3
Reference: https://wordpress.stackexchange.com/a/291525/134082
Usage: [ch_card_image]
*/
function ch_generate_card_image($atts) {
// extract attributs
extract(shortcode_atts(array(
'post_id' => false, // Default
'format_value' => true, // Default
), $atts));
$featured_image_id = get_post_thumbnail_id($post_id);
$credit_card_title = get_the_title($post_id);
$card_image_shortcode = '[cq_vc_shadowcard image="' . $featured_image_id . '" title="' . $credit_card_title . '" tolerance="12"]';
return do_shortcode($card_image_shortcode);
}
add_shortcode('ch_card_image', 'ch_generate_card_image');
/*
Create shortcode for displaying Credit Card Features using ShadowCard CPT and ACF.
Author: Jacktator
Plugin: Custom Post Type UI 1.6.1
Plugin: Advanced Custom Fields PRO 5.7.9
Plugin: ThemeREX Addons 11.6.30
Reference: https://wordpress.stackexchange.com/a/291525/134082
Usage: [ch_card_features]
*/
function ch_generate_card_features($atts) {
// extract attributs
extract(shortcode_atts(array(
'post_id' => false, // Default
'format_value' => true, // Default
), $atts));
$features_row_shortcode = '';
// $features_row_shortcode .= '[vc_row css=".vc_custom_1546576317270{background-color: #eaeaea !important;}"][vc_column]';
// $features_row_shortcode .= '[vc_empty_space alter_height="medium" hide_on_mobile=""]';
$features_row_shortcode .= '[vc_row_inner]';
$features = get_field('features'); // Repeater
if (have_rows('features')) {
// $features_objects = get_field_object('features');
// $features_count = count($features_objects);
while (have_rows('features')) {
the_row();
// Feth Feature Data
$feature_title = get_sub_field('title');
$feature_subtitle = get_sub_field('subtitle');
$feature_description = get_sub_field('description');
// Construct Feature Column
$features_row_shortcode .= '[vc_column_inner width="1/4"][trx_sc_title title_style="default" title_align="center" title="' . $feature_title . '" subtitle="' . $feature_subtitle . '"][/vc_column_inner]';
}
}
$features_row_shortcode .= '[/vc_row_inner]';
// $features_row_shortcode .= '[vc_empty_space alter_height="medium" hide_on_mobile=""]';
// $features_row_shortcode .= '[/vc_column][/vc_row][vc_row]';
return do_shortcode($features_row_shortcode);
}
add_shortcode('ch_card_features', 'ch_generate_card_features');
/*
Create shortcode for displaying Credit Card Cons with CPT and ACF.
Author: Jacktator
Plugin: Custom Post Type UI 1.6.1
Plugin: Advanced Custom Fields PRO 5.7.9
Plugin: ThemeREX Addons 11.6.30
Reference: https://wordpress.stackexchange.com/a/291525/134082
Usage: [ch_card_cons]
*/
function ch_generate_card_cons($atts) {
// extract attributs
extract(shortcode_atts(array(
'post_id' => false, // Default
'format_value' => true, // Default
), $atts));
$cons_list_shortcode = '';
$cons_list_shortcode .= '<ul class="trx_addons_list_error">';
$cons = get_field('cons'); // Repeater
if (have_rows('cons')) {
// $cons_objects = get_field_object('features');
// $cons_count = count($cons_objects);
while (have_rows('cons')) {
the_row();
// Feth Pro Data
$pro_html = get_sub_field('con');
// Construct Pro List Item
$cons_list_shortcode .= '<li>' . $pro_html . '</li>';
}
}
$cons_list_shortcode .= '</ul>';
return $cons_list_shortcode;
}
add_shortcode('ch_card_cons', 'ch_generate_card_cons');
/*
Create shortcode for displaying Credit Card Pros with CPT and ACF.
Author: Jacktator
Plugin: Custom Post Type UI 1.6.1
Plugin: Advanced Custom Fields PRO 5.7.9
Plugin: ThemeREX Addons 11.6.30
Reference: https://wordpress.stackexchange.com/a/291525/134082
Usage: [ch_card_pros]
*/
function ch_generate_card_pros($atts) {
// extract attributs
extract(shortcode_atts(array(
'post_id' => false, // Default
'format_value' => true, // Default
), $atts));
$pros_list_shortcode = '';
$pros_list_shortcode .= '<ul class="trx_addons_list_success">';
$pros = get_field('pros'); // Repeater
if (have_rows('pros')) {
// $pros_objects = get_field_object('features');
// $pros_count = count($pros_objects);
while (have_rows('pros')) {
the_row();
// Feth Pro Data
$pro_html = get_sub_field('pro');
// Construct Pro List Item
$pros_list_shortcode .= '<li>' . $pro_html . '</li>';
}
}
$pros_list_shortcode .= '</ul>';
return $pros_list_shortcode;
}
add_shortcode('ch_card_pros', 'ch_generate_card_pros');
/*
Create shortcode for displaying Maximum Earn Rate Table using CPT and ACF.
Author: Jacktator
Plugin: Custom Post Type UI 1.6.1
Plugin: Advanced Custom Fields PRO 5.7.9
Reference: https://wordpress.stackexchange.com/a/291525/134082
Usage: [ch_interest_fee_table] // Generate the Interest & Fee Table
*/
function ch_generate_interest_fee_table($atts) {
// extract attributs
extract(shortcode_atts(array(
'post_id' => false, // Default
'format_value' => true, // Default
), $atts));
// extract attributs