-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom-hook.php
More file actions
1926 lines (1248 loc) · 54.8 KB
/
custom-hook.php
File metadata and controls
1926 lines (1248 loc) · 54.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
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
remove_action('woocommerce_before_shop_loop', 'woocommerce_result_count', 20);
remove_action('woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30);
add_action('order_customize', 'woocommerce_catalog_ordering', 40);
remove_action('woocommerce_before_main_content', 'woocommerce_breadcrumb', 20);
remove_action('woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10);
add_action('after_header_site', function () {
echo '<div class="woocommerce-notices-wrapper">';
wc_print_notices();
echo '</div>';
}, 15);
add_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_product_title', 4);
add_action('woocommerce_shop_loop_item_title', 'add_div_content', 10);
function add_div_content()
{
global $product;?>
<div class="c-product-box__content">
<a href="<?php echo $product->get_permalink() ?>" class="title"><?php echo $product->get_title(); ?></a>
<?php if ($product->get_price()): ?>
<?php if ($product->is_on_sale()): ?>
<span style="color: red"
class="price"> قیمت ویژه <?php echo number_format($product->get_sale_price()) ?> تومان </span>
<del class="price"> قیمت نقدی <?php echo number_format($product->get_regular_price()) ?>
تومان
</del>
<?php else: ?>
<span class="price"> قیمت نقدی <?php echo number_format($product->get_regular_price()) ?>
تومان
</span>
<?php endif; ?>
<?php else: ?>
<span class="price">نا موجود</span>
<?php endif; ?>
</div>
<?php
}
remove_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10);
//remove_action('woocommerce_after_shop_loop_item_title','woocommerce_template_loop_rating',10);
remove_action('woocommerce_before_shop_loop', 'woocommerce_output_all_notices', 10);
remove_action('woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
add_action('custom_single_title', function () {
the_title('<h1 class="c-product__title"><span class="fa-title">', '</span></h1><span class="c-product__guaranteed">بیش از ۱۰ نفر از خریداران این محصول را پیشنهاد دادهاند</span>');
});
add_action('woocommerce_product_meta_start', function () {
echo ' <div class="c-product__directory">';
});
add_action('woocommerce_product_meta_end', function () {
echo '</div>';
});
/** get all brand one product */
add_action('show_brands', function ($product_id) {
$brands = get_the_terms($product_id, 'brand');
if ($brands) {
foreach ($brands as $brand) {
?>
<li><span>برند : </span> <a href="<?php echo get_term_link($brand->term_id) ?>"
class="btn-link-spoiler"><?php echo $brand->name ?></a></li>
<?php
}
}
});
add_action('custom_attribute', 'woocommerce_template_single_meta', 5);
/** get vendor info for single product */
add_action('woocommerce_single_product_summary', 'get_vendor', 1);
function get_vendor()
{
global $product;
// Get the author ID (the vendor ID)
$vendor_id = get_post_field('post_author', $product->get_id());
// Get the WP_User object (the vendor) from author ID
$vendor = new WP_User($vendor_id);
$store_info = dokan_get_store_info($vendor_id); // Get the store data
$store_name = $store_info['store_name']; // Get the store name
$store_url = dokan_get_store_url($vendor_id); // Get the store URL
$vendor_name = $vendor->display_name; // Get the vendor name
$address = $vendor->billing_address_1; // Get the vendor address
$postcode = $vendor->billing_postcode; // Get the vendor postcode
$city = $vendor->billing_city; // Get the vendor city
$state = $vendor->billing_state; // Get the vendor state
$country = $vendor->billing_country; // Get the vendor country
echo '<div class="seller"><span> فروشنده : </span> <a href="' . $store_url . '" class="btn-link-spoiler">' . $vendor_name . '</a></div>';
}
/** get delivery */
add_action('woocommerce_single_product_summary', function () {
echo '
<div class="c-product__delivery">
<div class="delivery-warehouse"><i class="fa fa-truck"></i><span
class="c-product__delivery-warehouse--no-lead-time">آماده ارسال</span></div>
</div>';
}, 3);
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_title', 40);
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_meta', 5);
add_action('woocommerce_before_add_to_cart_form', function () {
echo ' <div class="c-product__add">';
});
add_action('woocommerce_after_add_to_cart_form', function () {
echo ' </div>';
});
remove_all_actions('woocommerce_product_additional_information');
add_action('woocommerce_product_additional_information', function ($product) {
$attributes = $product->get_attributes();
if (!$attributes) {
echo "ویژگی وجود ندارد";
}
foreach ($attributes as $attribute) {
?>
<li>
<div class="c-params__list-key"><span class="block"><?php echo $attribute['name'] ?></span></div>
<div class="c-params__list-value">
<?php $product_attributes = array();
$product_attributes = explode('|', $attribute['value']);
foreach ($product_attributes as $pa) {
echo '<span class="block">' . $pa . '</span>';
} ?>
</div>
</li>
<?php
}
});
add_action('woocommerce_after_cart_item_name', function ($cart_item) {
$product = wc_get_product($cart_item['product_id']);
echo '<p class="c-checkout__guarantee">';
echo $product->get_short_description();
echo '</p>';
}, 1);
/** action vhange plan for each product */
add_action('wp_ajax_add_plan',function ()
{
$ids=$_POST['product_id'];
$arr_product_plan_ids=array();
foreach ($ids as $id)
{
$arr_product_plan_ids[$id]=$_POST['id_plan'];
}
});
/** action filter plans */
add_action('wp_ajax_filter_plans', function () {
/** price installment */
$mega_array = array();
/** store plan */
foreach ($_POST['product_id'] as $id):
$html="";
$plans_store = get_post_meta($id, 'plans', true);
global $wpdb;
if ( $plans_store) {
$array_html = array();
$html .= "<p class='plans-store__title'>پلن فروشگاهی</p>";
$html .='<div class="plans-store__container">';
foreach ($plans_store as $id_plan) :
$html .= "";
$pln = $wpdb->get_row("select * from {$wpdb->prefix}plans where id={$id_plan}");
if ($pln->is_active) {
$html .= "<div>";
$all_data_selected_plan = WC()->session->get('selected_plan');
$plan_id_selected = 0;
// if (isset($all_data_selected_plan[$id])) $plan_id_selected = $all_data_selected_plan[$id];
$plan_id_selected = $all_data_selected_plan[$id];
$price_cash = get_post_meta($id, '_price', true);
$pish = $price_cash * ($pln->pishe_darsad / 100);
$mande = $price_cash - $pish;
$final_ghest_price = $mande + ($mande * (($pln->num_month * $pln->darsad_profit) / 100));
$html .= '<input type="radio" data-plan_id="' . $id_plan . '" class="radio_price" data-product_id="' . $id . '" name="plan_selected_cart-' . $id . '" id="plan_selected_cart-' . $id . '" value="' . $final_ghest_price . '"';
if ($plan_id_selected == $id_plan) $html .= "checked";
$html .= '>';
$html .= "<p>";
$html .= "قیمت(پیش پرداخت + قیمت قسطی): ";
$html .= number_format($final_ghest_price+$pish);
$html .= " تومان " ;
$html .= "</p>";
$html .= "<p>";
$html .= "قیمت قسطی: ";
$html .= number_format($final_ghest_price);
$html .= " تومان " ;
$html .= "</p>";
$html .= '<p class="pish">';
$html .= "پیش پرداخت:";
/** calc price pish */
$html .= ' ( ' . number_format($pish) . ' تومان )';
$html .= '</p>';
$html .= '<p class="month">';
$html .= "تعداد اقساط:";
$html .= $pln->num_month . " ماه";
$html .= '</p>';
$html .= '<p class="price_month">';
$html .= "مبلغ هر قسط";
$kol_ghest = $final_ghest_price / $pln->num_month;
$html .= '( ' . number_format(($kol_ghest)) . " تومان ) ";
$html .= '</p>';
$html .= '</div>';
}
endforeach;
$html .= "</div>";
}
/** default panel */
$array_html = array();
global $wpdb;
$plan_default = $wpdb->get_results("select * from {$wpdb->prefix}plans where id_vendor =0");
$html .= "";
$html .= "<p class='plans-store__title'>پلن عمومی</p>";
$html .='<div class="plans-store__container">';
// group installment
$plans_general= get_post_meta($id, 'plans_general',true);
foreach ($plan_default as $plan) :
if (in_array($plan->id,$plans_general)):
if ($plan->is_active) :
$html .="<div>";
$price_cash = get_post_meta($id, '_price', true);
$pish = $price_cash * ($plan->pishe_darsad / 100);
$mande = $price_cash - $pish;
$final_ghest_price = $mande + ($mande * (($plan->num_month * $plan->darsad_profit) / 100));
$all_data_selected_plan = WC()->session->get('selected_plan');
$plan_id_selected = 0;
if (isset($all_data_selected_plan[$id])) $plan_id_selected = $all_data_selected_plan[$id];
$html .= '<input type="radio" data-plan_id="' . $plan->id . '" class="radio_price" data-product_id="' . $id . '" name="plan_selected_cart-' . $id . '" id="plan_selected_cart-' . $id . '" value="' . $final_ghest_price . '"';
if ($plan_id_selected == $plan->id) $html .= "checked";
$html .= '>';
$html .= "<p>";
$html .= "قیمت(پیش پرداخت + قیمت قسطی): ";
$html .= number_format($final_ghest_price+$pish);
$html .= " تومان ";
$html .= "</p>";
$html .= "<p>";
$html .= "قیمت قسطی: ";
$html .= number_format($final_ghest_price);
$html .= " تومان " ;
$html .= "</p>";
$html .= '<p class="pish">';
$html .= "پیش پرداخت:";
$html .= ' ( ' . number_format($pish) . ' تومان )';
$html .= '</p>';
$html .= '<p class="month">';
$html .= "تعداد قسط:";
$html .= $plan->num_month . " ماه";
$html .= '</p>';
$html .= '<p class="price_month">';
$html .= "قیمت هر قسط";
$html .= '( ' . number_format($final_ghest_price / $plan->num_month)
. " تومان ) ";
$html .= '</p>';
$html.="</div>";
endif;
endif;
endforeach;
$html.="</div>";
$id_user = get_current_user_id();
$wallet = get_user_meta($id_user, '_current_woo_wallet_balance', true);
$final_price = WC()->session->get('final_price_mul_qty', array());
if ($final_price)
$sum_final_price = array_sum($final_price);
else
$sum_final_price = 0;
$html .= '<script type="text/javascript">
jQuery(document).ready(function ($) {
$(".section_price_installment_r").css("display", "none")
$("input[class=radio_price]:radio").each(function() {
if($(this).is(":checked")) {
$.ajax({
url: "/wp-admin/admin-ajax.php",
type: "post",
data: {
action: "change_price_installment",
product_id: $(this).data("product_id"),
plan_id: $(this).data("plan_id"),
},
success: function (response) {
$(".section_price_installment-"+response.id_product).empty()
.append(response.html);
$(".section_price_installment-"+response.id_product).css("display", "flex")
},
error: function (error) {
console.log("error");
console.log(error);
}
})
}
});
function addCommas(nStr)
{
nStr += \'\';
x = nStr.split(\'.\');
x1 = x[0];
x2 = x.length > 1 ? \'.\' + x[1] : \'\';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, \'$1\' + \',\' + \'$2\');
}
return x1 + x2;
}
$(".radio_price").on("change", function () {
console.log("changed plan");
console.log($(this).data("product_id"));
console.log($(this).data("plan_id"));
var current_wallet=' . $wallet . ';
var sum_final=' . $sum_final_price . ';
$.ajax({
url: "/wp-admin/admin-ajax.php",
type: "post",
data: {
action: "change_price_installment",
product_id: $(this).data("product_id"),
plan_id: $(this).data("plan_id"),
wallet:sum_final
},
success: function (response) {
console.log(response);
$(".section_price_installment-"+response.id_product).empty()
.append(response.html);
//hide old mande
$(".wallet1-price").empty();
$(".wallet-price").empty();
//update total pish
$("#total_pish").empty()
.append(addCommas( parseInt(response.total_price)))
.append(" </span> <span> تومان </span> </p>");
// change wallet
$(".wallet").empty()
.append("<span>جمع مبلغ قسطی انتخابی</span> <span> ");
$(".wallet-price")
.append(addCommas(response.change_wallet))
.append(" </span> <span> تومان </span> </p>");
// $(".wallet1").empty()
// .append("<span>اعتبار باقی مانده</span> <span> ");
$(".wallet1-price")
.append("<span>")
.append(addCommas(current_wallet - response.change_wallet))
.append(" </span> <span> تومان </span> ");
if (current_wallet - response.change_wallet<=0)
{
$(".wallet1").css("color", "red");
}else
{
$(".wallet1").css("color", "black");
}
},
error: function (error) {
console.log(error);
}
});
});
jQuery(document).ajaxStop(function () {
jQuery("#cash").attr("disabled",false);
});
jQuery(document).ajaxStart(function () {
jQuery("#cash").attr("disabled",true);
});
});
</script>';
array_push($array_html, $html);
$mega_array[$id] = $array_html;
endforeach;
wp_send_json($mega_array,200);
/*****************************************/
});
//action update pish total
add_action('wp_ajax_update_total_pish',function ()
{
});
$array_product_id_and_plan_id = [];
/** add session selected_panel */
add_action('wp_ajax_change_price_installment', function () {
/** change select*/
$array_product_id_and_plan_id1 =WC()->session->get('selected_plan',array());
$array_product_id_and_plan_id1[$_POST['product_id']] = $_POST['plan_id'];
WC()->session->set('selected_plan',$array_product_id_and_plan_id1);
/** end */
global $wpdb;
$plans_store = get_post_meta($_POST['product_id'], 'plans', true);
$plan = $wpdb->get_row("select * from {$wpdb->prefix}plans where id={$_POST['plan_id']}");
$targeted_id = $_POST['product_id'];
/** get qty */
foreach (WC()->cart->get_cart() as $cart_item):
if (in_array($targeted_id, array($cart_item['product_id'], $cart_item['variation_id']))):
$quantity = $cart_item['quantity'];
/**price installment array */
$array_product_by_price_installment = WC()->session->get('total_price_installment', array());
if (!is_array($array_product_by_price_installment)) {
$array_product_by_price_installment = array();
}
$ppp = get_post_meta($targeted_id, "_price", true);
$pish = (($ppp * ($plan->pishe_darsad / 100)));
$price_ghest = ($ppp - $pish);
$price_ghest1_kol = $price_ghest + ($price_ghest * ($plan->darsad_profit * $plan->num_month / 100));
$price_ghest1_kol *= $quantity;
$array_product_by_price_installment[$cart_item['product_id']] = $price_ghest1_kol;
WC()->session->set('total_price_installment', $array_product_by_price_installment);
/** end */
$array_product_by_price = WC()->session->get('total_price', array());
if (!is_array($array_product_by_price)) {
$array_product_by_price = array();
}
$ppp = get_post_meta($targeted_id, "_price", true);
$array_product_by_price[$cart_item['product_id']] = $quantity * ($ppp * ($plan->pishe_darsad / 100));
//total price => all price pish pardakht
WC()->session->set('total_price', $array_product_by_price);
add_action('woocommerce_cart_updated', function () {
}, 10, 0);
break;
endif;
endforeach;
/** @var $html subtotal side */
// get price base
$price_base = get_post_meta($targeted_id, '_price', true);
$html = "";
$html .= "<p>";
$html .= "مبلغ کل: ";
$pish = (($price_base * ($plan->pishe_darsad / 100)));
$price_ghest = ($price_base - $pish);
$pish_kol = $quantity * $pish;
$price_ghest1_kol = $price_ghest + ($price_ghest * ($plan->darsad_profit * $plan->num_month / 100));
$price_ghest1_kol *= $quantity;
$html .= number_format($pish_kol + $price_ghest1_kol) . "</br>";
$html .= "</p>";
$html .= "<p>";
$html .= "پیش پرداخت: ";
$html .= ' ( ' . number_format($quantity * $pish) . ' تومان )' . "</br>";
$price_ghest1 = $price_ghest + ($price_ghest * ($plan->darsad_profit * $plan->num_month / 100));
$html .= "</p>";
$html .= "<p>";
$html .= "جمع اقساط: ";
$html .= ' ( ' . number_format(($quantity * $price_ghest1)) . ' تومان )' . "</br>";
$html .= "</p>";
$html .= "<p>";
$html .= "مبلغ هر قسط: ";
$html .= ' ( ' . number_format($quantity * $price_ghest1 / $plan->num_month) . ' تومان )' . "</br>";
$html .= "</p>";
$arr_response = array();
$arr_response['html'] = $html;
$arr_response['id_product'] = $_POST['product_id'];
/** update total pish */
//save to session id product by plan id selected
$plan = $wpdb->get_row("select * from {$wpdb->prefix}plans where id={$_POST['plan_id']}");
$targeted_id = $_POST['product_id'];
foreach (WC()->cart->get_cart() as $cart_item):
if (in_array($targeted_id, array($cart_item['product_id'], $cart_item['variation_id']))):
$quantity = $cart_item['quantity'];
$array_product_by_price = WC()->session->get('total_price', array());
if (!is_array($array_product_by_price)) {
$array_product_by_price = array();
}
$ppp = get_post_meta($targeted_id, "_price", true);
$array_product_by_price[$cart_item['product_id']] = $quantity * ($ppp * ($plan->pishe_darsad / 100));
//total price => all price pish pardakht
WC()->session->set('total_price', $array_product_by_price);
break;
endif;
endforeach;
$arr_response['total_price'] = array_sum( WC()->session->get('total_price', 0));
/** change wallet */
$plan = $wpdb->get_row("select * from {$wpdb->prefix}plans where id={$_POST['plan_id']}");
$targeted_id = $_POST['product_id'];
/** get qty */
foreach (WC()->cart->get_cart() as $cart_item):
if (in_array($targeted_id, array($cart_item['product_id'], $cart_item['variation_id']))):
$quantity = $cart_item['quantity'];
/**price installment array */
$array_product_by_price_installment = WC()->session->get('total_price_installment', array());
if (!is_array($array_product_by_price_installment)) {
$array_product_by_price_installment = array();
}
$ppp = get_post_meta($targeted_id, "_price", true);
$pish = (($ppp * ($plan->pishe_darsad / 100)));
$price_ghest = ($ppp - $pish);
$pish_kol = $quantity * $pish;
$price_ghest1_kol = $price_ghest + ($price_ghest * ($plan->darsad_profit * $plan->num_month / 100));
$price_ghest1_kol *= $quantity;
$array_product_by_price_installment[$cart_item['product_id']] = $price_ghest1_kol;
WC()->session->set('total_price_installment', $array_product_by_price_installment);
/** end */
$array_product_by_price = WC()->session->get('total_price', array());
if (!is_array($array_product_by_price)) {
$array_product_by_price = array();
}
$ppp = get_post_meta($targeted_id, "_price", true);
$array_product_by_price[$cart_item['product_id']] = $quantity * ($ppp * ($plan->pishe_darsad / 100));
//total price => all price pish pardakht
WC()->session->set('total_price', $array_product_by_price);
break;
endif;
endforeach;
$sum_total_price = array_sum(WC()->session->get('total_price_installment', 0));
/** end */
$arr_response['change_wallet']=$sum_total_price;
wp_send_json($arr_response, 200);
});
add_action('wp_ajax_set_type_cart', function () {
if (isset($_POST['type_cart'])) {
if ($_POST['type_cart'] == "cash") {
WC()->session->set('type_cart', 'cash_cart');
return "cghanged";
}
if ($_POST['type_cart'] == "installment") {
WC()->session->set('type_cart', 'installment_cart');
return "cghanged";
}
}
return "notttt";
});
add_filter('woocommerce_calculated_total', function ($total, $cart) {
// WC()->session->__unset('auth');
// WC()->session->__unset( 'total_price' );
// WC()->session->__unset( 'final_price_mul_qty' );
$type_cart = WC()->session->get('type_cart', "cash_cart");
if ($type_cart == "installment_cart") {
$c = 0;
$array_product = WC()->session->get('total_price_installment', 0);
if ($array_product) {
if (is_array($array_product)) {
foreach ($array_product as $id_product => $price_product):
$c += $price_product;
endforeach;
}
}
$cart->subtotal = $c;
return $cart->subtotal;
}
return $cart->subtotal;
}, 50, 2);
/** remove item from cart */
function ss_cart_updated($cart_item_key, $cart)
{
$product_id = $cart->cart_contents[$cart_item_key]['product_id'];
$arr_total_price = WC()->session->get('total_price', '0');
if($arr_total_price !=0)
{
unset($arr_total_price[$product_id]);
}
WC()->session->set('total_price', $arr_total_price);
$arr_total_price_installment = WC()->session->get('total_price_installment', '0');
if ($arr_total_price_installment !=0)
{
unset($arr_total_price_installment[$product_id]);
}
WC()->session->set('total_price_installment', $arr_total_price_installment);
$array_final_price = WC()->session->get('final_price_mul_qty', 0);
unset($array_final_price[$product_id]);
WC()->session->set('final_price_mul_qty', $array_final_price);
}
add_action('woocommerce_remove_cart_item', 'ss_cart_updated', 10, 2);
/** after checkout */
add_action('woocommerce_after_checkout_billing_form', 'QuadLayers_callback_function');
function QuadLayers_callback_function()
{
include "app/views/user/checkout_table.php";
}
/**
* Remove all possible fields
**/
function wc_remove_checkout_fields($fields)
{
// Billing fields
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_email']);
unset($fields['billing']['billing_phone']);
unset($fields['billing']['billing_state']);
unset($fields['billing']['billing_first_name']);
unset($fields['billing']['billing_last_name']);
unset($fields['billing']['billing_address_1']);
unset($fields['billing']['billing_address_2']);
unset($fields['billing']['billing_city']);
unset($fields['billing']['billing_postcode']);
// Shipping fields
unset($fields['shipping']['shipping_company']);
unset($fields['shipping']['shipping_phone']);
unset($fields['shipping']['shipping_state']);
unset($fields['shipping']['shipping_first_name']);
unset($fields['shipping']['shipping_last_name']);
unset($fields['shipping']['shipping_address_1']);
unset($fields['shipping']['shipping_address_2']);
unset($fields['shipping']['shipping_city']);
unset($fields['shipping']['shipping_postcode']);
// Order fields
unset($fields['order']['order_comments']);
return $fields;
}
//add_filter( 'woocommerce_checkout_fields', 'wc_remove_checkout_fields' );
add_filter('woocommerce_billing_fields', 'wc_unrequire_wc_phone_field');
function wc_unrequire_wc_phone_field($fields)
{
// $fields['billing_company']['required'] = true;
$fields['billing_phone']['required'] = false;
return $fields;
}
/** remove all class checkout field */
add_filter('woocommerce_form_field_country', 'clean_checkout_fields_class_attribute_values', 20, 4);
add_filter('woocommerce_form_field_state', 'clean_checkout_fields_class_attribute_values', 20, 4);
add_filter('woocommerce_form_field_textarea', 'clean_checkout_fields_class_attribute_values', 20, 4);
add_filter('woocommerce_form_field_checkbox', 'clean_checkout_fields_class_attribute_values', 20, 4);
add_filter('woocommerce_form_field_password', 'clean_checkout_fields_class_attribute_values', 20, 4);
add_filter('woocommerce_form_field_text', 'clean_checkout_fields_class_attribute_values', 20, 4);
add_filter('woocommerce_form_field_email', 'clean_checkout_fields_class_attribute_values', 20, 4);
add_filter('woocommerce_form_field_tel', 'clean_checkout_fields_class_attribute_values', 20, 4);
add_filter('woocommerce_form_field_number', 'clean_checkout_fields_class_attribute_values', 20, 4);
add_filter('woocommerce_form_field_select', 'clean_checkout_fields_class_attribute_values', 20, 4);
add_filter('woocommerce_form_field_radio', 'clean_checkout_fields_class_attribute_values', 20, 4);
function clean_checkout_fields_class_attribute_values($field, $key, $args, $value)
{
if (is_checkout()) {
// remove "form-row"
$field = str_replace(array('<p class="form-row ', '<p class="form-row'), array('<p class="', '<p class="'), $field);
}
return $field;
}
add_filter('woocommerce_checkout_fields', 'custom_checkout_fields_class_attribute_value', 20, 1);
function custom_checkout_fields_class_attribute_value($fields)
{
$fields['billing']['billing_company']['label'] = 'نام سازمان';
foreach ($fields as $fields_group_key => $group_fields_values) {
foreach ($group_fields_values as $field_key => $field) {