forked from pavelevap/ceske-sluzby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ceske-sluzby.php
2209 lines (2092 loc) · 102 KB
/
ceske-sluzby.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
/**
* Plugin Name: České služby pro WordPress
* Plugin URI: https://www.separatista.net
* Description: Implementace různých českých služeb do WordPressu.
* Version: 0.6-alpha
* Author: Pavel Hejn
* Author URI: https://www.separatista.net
* GitHub Plugin URI: pavelevap/ceske-sluzby
* License: GPL2
*/
define( 'CS_VERSION', '0.6-alpha' );
$language = get_locale();
if ( $language == "sk_SK" ) {
define( "HEUREKA_URL", "heureka.sk" );
define( "GLAMI_URL", "glami.sk" );
define( "HEUREKA_KONVERZE", "https://im9.cz/sk/js/ext/2-roi-async.js" );
define( "GOOGLE_MENA", "EUR" );
}
else {
define( "HEUREKA_URL", "heureka.cz" );
define( "GLAMI_URL", "glami.cz" );
define( "HEUREKA_KONVERZE", "https://im9.cz/js/ext/1-roi-async.js" );
define( "GOOGLE_MENA", "CZK" );
}
function ceske_sluzby_heureka_overeno_zakazniky( $order_id, $posted ) {
$api = get_option( 'wc_ceske_sluzby_heureka_overeno-api' );
$souhlas = get_option( 'wc_ceske_sluzby_heureka_overeno-souhlas' );
$souhlas_check = array();
$souhlas_text = "";
if ( ! empty( $souhlas ) ) {
if ( $souhlas == 'souhlas_optout' && isset( $_POST['heureka_overeno_zakazniky_souhlas_optout'] ) && (int)$_POST['heureka_overeno_zakazniky_souhlas_optout'] == 1 ) {
$souhlas_check = array( $souhlas => current_time( 'mysql' ) );
$souhlas_text = 'Objednávka byla úspěšně odeslána do služby Ověřeno zákazníky (Heureka) a zákazník neodmítl navržený souhlas se zpracováním dat.';
}
if ( $souhlas == 'nesouhlas_optout' && ! isset( $_POST['heureka_overeno_zakazniky_nesouhlas_optout'] ) ) {
$souhlas_check = array( $souhlas => current_time( 'mysql' ) );
$souhlas_text = 'Objednávka byla úspěšně odeslána do služby Ověřeno zákazníky (Heureka) a zákazník nepotvrdil nesouhlas se zpracováním dat.';
}
} else {
$souhlas_check = array( 'neaktivni' => current_time( 'mysql' ) );
$souhlas_text = 'Objednávka byla úspěšně odeslána do služby Ověřeno zákazníky (Heureka).';
}
if ( ! empty( $api ) && ! empty( $souhlas_check ) ) {
$order = wc_get_order( $order_id );
// https://github.com/heureka/heureka-overeno-php-api
require_once( dirname( __FILE__ ) . '/src/heureka/HeurekaOvereno.php' );
$language = get_locale();
try {
if ( $language == "sk_SK" ) {
$overeno = new HeurekaOvereno( $api, HeurekaOvereno::LANGUAGE_SK );
}
else {
$overeno = new HeurekaOvereno( $api );
}
$overeno->setEmail( $posted['billing_email'] );
$items = $order->get_items();
if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
foreach ( $items as $item_data ) {
$overeno->addProduct( $item_data['name'] );
}
} else {
foreach ( $items as $item_id => $item_data ) {
$aktivace_xml = get_option( 'wc_ceske_sluzby_heureka_xml_feed-aktivace' );
$product = $item_data->get_product();
if ( $aktivace_xml == "yes" ) {
$overeno->addProductItemId( $product->get_id() );
} else {
$overeno->addProduct( $product->get_name() );
}
}
}
$overeno->addOrderId( $order_id );
$overeno->send();
update_post_meta( $order_id, 'ceske_sluzby_heureka_overeno_zakazniky_souhlas', $souhlas_check );
$order->add_order_note( $souhlas_text );
}
catch ( OverflowException $o ) {
$order->add_order_note( 'API klíč pro službu Ověřeno zákazníky nebyl správně nastaven: ' . $o->getMessage() );
}
catch ( HeurekaOverenoException $e ) {
$order->add_order_note( 'Odeslání dat pro službu Ověřeno zákazníky se nezdařilo: ' . $e->getMessage() );
}
}
}
function ceske_sluzby_heureka_mereni_konverzi( $order_id ) {
$api = get_option( 'wc_ceske_sluzby_heureka_konverze-api' );
if ( ! empty( $api ) ) {
$order = wc_get_order( $order_id );
$items = $order->get_items(); ?>
<script type="text/javascript">
var _hrq = _hrq || [];
_hrq.push(['setKey', '<?php echo $api; ?>']);
_hrq.push(['setOrderId', '<?php echo $order_id; ?>']);
<?php if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
foreach ( $items as $item ) {
$cena = wc_format_decimal( $order->get_item_subtotal( $item ) );
echo "_hrq.push(['addProduct', '" . $item['name'] . "', '" . $cena . "', '" . $item['qty'] . "']);";
}
} else {
foreach ( $items as $item_id => $item_data ) {
$product = $item_data->get_product();
$cena = wc_format_decimal( $item_data->get_total() / $item_data->get_quantity() );
echo "_hrq.push(['addProduct', '" . $product->get_name() . "', '" . $cena . "', '" . $item_data->get_quantity() . "']);";
}
} ?>
_hrq.push(['trackOrder']);
(function() {
var ho = document.createElement('script'); ho.type = 'text/javascript'; ho.async = true;
ho.src = '<?php echo HEUREKA_KONVERZE; ?>';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ho, s);
})();
</script>
<?php
}
}
function ceske_sluzby_heureka_certifikat_spokojenosti() {
$api = get_option( 'wc_ceske_sluzby_heureka_konverze-api' );
$certifikat = get_option( 'wc_ceske_sluzby_heureka_certifikat_spokojenosti-aktivace' );
if ( ! empty( $api ) && $certifikat == "yes" ) {
$umisteni = get_option( 'wc_ceske_sluzby_heureka_certifikat_spokojenosti_umisteni' );
$odsazeni = get_option( 'wc_ceske_sluzby_heureka_certifikat_spokojenosti_odsazeni' );
if ( ! empty( $umisteni ) ) {
if ( $umisteni == "vlevo" ) {
$umisteni = 21;
} else {
$umisteni = 22;
}
} else {
$umisteni = 21;
}
if ( empty( $odsazeni ) ) {
$odsazeni = 60;
}
?>
<script type="text/javascript">
//<![CDATA[
var _hwq = _hwq || [];
_hwq.push(['setKey', '<?php echo $api; ?>']);_hwq.push(['setTopPos', '<?php echo $odsazeni; ?>']);_hwq.push(['showWidget', '<?php echo $umisteni; ?>']);(function() {
var ho = document.createElement('script'); ho.type = 'text/javascript'; ho.async = true;
ho.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.<?php echo HEUREKA_URL; ?>/direct/i/gjs.php?n=wdgt&sak=<?php echo $api; ?>';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ho, s);
})();
//]]>
</script>
<?php
}
}
function ceske_sluzby_sklik_mereni_konverzi( $order_id ) {
$konverze = get_option( 'wc_ceske_sluzby_sklik_konverze-objednavky' );
if ( ! empty( $konverze ) ) {
$order = wc_get_order( $order_id );
$hodnota_objednavky = round( $order->get_subtotal() ); ?>
<!-- Měřicí kód Sklik.cz -->
<iframe width="119" height="22" frameborder="0" scrolling="no" src="//c.imedia.cz/checkConversion?c=<?php echo $konverze; ?>&color=ffffff&v=<?php echo $hodnota_objednavky; ?>"></iframe>
<?php
}
}
function ceske_sluzby_sklik_retargeting() {
$konverze = get_option( 'wc_ceske_sluzby_sklik_retargeting' );
if ( ! empty( $konverze ) ) { ?>
<script type="text/javascript">
/* <![CDATA[ */
var seznam_retargeting_id = <?php echo $konverze; ?>;
/* ]]> */
</script>
<script type="text/javascript" src="//c.imedia.cz/js/retargeting.js"></script>
<?php
}
}
function ceske_sluzby_srovname_mereni_konverzi( $order_id ) {
$klic = get_option( 'wc_ceske_sluzby_srovname_konverze-objednavky' );
if ( ! empty( $klic ) ) {
$order = wc_get_order( $order_id );
$items = $order->get_items(); ?>
<script type="text/javascript">
var _srt = _srt || [];
_srt.push(['_setShop', '<?php echo $klic; ?>']);
_srt.push(['_setTransId', '<?php echo $order_id; ?>']);
<?php if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
foreach ( $items as $item ) {
$cena = wc_format_decimal( $order->get_item_subtotal( $item ) );
echo "_srt.push(['_addProduct', '" . $item['name'] . "', '" . $cena . "', '" . $item['qty'] . "']);";
}
} else {
foreach ( $items as $item_id => $item_data ) {
$product = $item_data->get_product();
$cena = wc_format_decimal( $item_data->get_total() / $item_data->get_quantity() );
echo "_srt.push(['_addProduct', '" . $product->get_name() . "', '" . $cena . "', '" . $item_data->get_quantity() . "']);";
}
} ?>
_srt.push(['_trackTrans']);
(function() {
var s = document.createElement("script");
s.type = "text/javascript";
s.async = true;
s.src = ("https:" == document.location.protocol ? "https" : "http") + "://www.srovname.cz/js/track-trans.js";
var x = document.getElementsByTagName("script")[0];
x.parentNode.insertBefore(s, x);
})();
</script>
<?php
}
}
function ceske_sluzby_zbozi_mereni_konverzi( $order_id ) {
$id_obchodu = get_option( 'wc_ceske_sluzby_zbozi_konverze_id-obchodu' );
if ( ! empty( $id_obchodu ) ) {
$order = wc_get_order( $order_id );
$hodnota_objednavky = number_format( (float)( $order->get_total() ), 2, '.', '' ); ?>
<script>
(function(w,d,s,u,n,k,c,t){w.ZboziConversionObject=n;w[n]=w[n]||function(){
(w[n].q=w[n].q||[]).push(arguments)};w[n].key=k;c=d.createElement(s);
t=d.getElementsByTagName(s)[0];c.async=1;c.src=u;t.parentNode.insertBefore(c,t)
})(window,document,"script","https://www.zbozi.cz/conversion/js/conv.js","zbozi","<?php echo $id_obchodu; ?>");
zbozi("setOrder",{
"orderId": "<?php echo $order_id; ?>",
"totalPrice": "<?php echo $hodnota_objednavky; ?>"
});
zbozi("send");
</script>
<?php
}
}
function ceske_sluzby_sledovani_zasilek_email( $email_classes ) {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-ceske-sluzby-sledovani-zasilek-email.php';
$email_classes['WC_Email_Ceske_Sluzby_Sledovani_Zasilek'] = new WC_Email_Ceske_Sluzby_Sledovani_Zasilek();
return $email_classes;
}
function ceske_sluzby_sledovani_zasilek_email_akce( $email_actions ) {
$email_actions[] = 'woocommerce_ceske_sluzby_sledovani_zasilek_email_akce';
return $email_actions;
}
function ceske_sluzby_kontrola_aktivniho_pluginu() {
if ( defined( 'WOOCOMMERCE_VERSION' ) && version_compare( WOOCOMMERCE_VERSION, '2.2', '>=' ) ) {
require_once plugin_dir_path( __FILE__ ) . 'includes/ceske-sluzby-functions.php';
if ( is_admin() ) {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-ceske-sluzby-admin.php';
require_once plugin_dir_path( __FILE__ ) . 'includes/class-ceske-sluzby-sledovani-zasilek.php';
WC_Settings_Tab_Ceske_Sluzby_Admin::init();
require_once plugin_dir_path( __FILE__ ) . 'includes/class-ceske-sluzby-product-tab.php';
require_once plugin_dir_path( __FILE__ ) . 'includes/class-ceske-sluzby-varianty.php';
new WC_Product_Tab_Ceske_Sluzby_Admin();
$xml_feed = get_option( 'wc_ceske_sluzby_heureka_xml_feed-aktivace' );
if ( $xml_feed == "yes" ) {
add_action( 'product_cat_add_form_fields', 'ceske_sluzby_xml_kategorie_pridat_pole', 99 );
add_action( 'product_cat_edit_form_fields', 'ceske_sluzby_xml_kategorie_upravit_pole', 99 );
add_action( 'created_term', 'ceske_sluzby_xml_kategorie_ulozit', 20, 3 );
add_action( 'edit_term', 'ceske_sluzby_xml_kategorie_ulozit', 20, 3 );
add_filter( 'manage_edit-product_cat_columns', 'ceske_sluzby_xml_kategorie_pridat_sloupec' );
add_filter( 'manage_product_cat_custom_column', 'ceske_sluzby_xml_kategorie_sloupec', 10, 3 );
}
}
add_action( 'woocommerce_shipping_init', 'ceske_sluzby_doprava_ulozenka_init' );
add_filter( 'woocommerce_shipping_methods', 'ceske_sluzby_doprava_ulozenka' );
add_action( 'woocommerce_shipping_init', 'ceske_sluzby_doprava_dpd_parcelshop_init' );
add_filter( 'woocommerce_shipping_methods', 'ceske_sluzby_doprava_dpd_parcelshop' );
add_action( 'woocommerce_checkout_order_processed', 'ceske_sluzby_heureka_overeno_zakazniky', 10, 2 );
add_action( 'woocommerce_review_order_before_submit', 'ceske_sluzby_heureka_overeno_zakazniky_souhlas' );
add_action( 'woocommerce_thankyou', 'ceske_sluzby_heureka_mereni_konverzi' );
add_action( 'woocommerce_thankyou', 'ceske_sluzby_zbozi_mereni_konverzi' );
add_action( 'woocommerce_thankyou', 'ceske_sluzby_sklik_mereni_konverzi' );
add_action( 'woocommerce_thankyou', 'ceske_sluzby_srovname_mereni_konverzi' );
add_action( 'wp_footer', 'ceske_sluzby_sklik_retargeting' );
add_filter( 'wc_order_is_editable', 'ceske_sluzby_moznost_menit_dobirku', 10, 2 );
add_filter( 'woocommerce_package_rates', 'ceske_sluzby_omezit_dopravu_pokud_dostupna_zdarma', 10, 2 );
add_action( 'woocommerce_review_order_after_shipping', 'ceske_sluzby_ulozenka_zobrazit_pobocky' );
add_action( 'woocommerce_new_order_item', 'ceske_sluzby_ulozenka_ulozeni_pobocky', 10, 2 );
add_action( 'woocommerce_checkout_process', 'ceske_sluzby_ulozenka_overit_pobocku' );
add_action( 'woocommerce_admin_order_data_after_billing_address', 'ceske_sluzby_ulozenka_objednavka_zobrazit_pobocku' );
add_action( 'woocommerce_email_after_order_table', 'ceske_sluzby_ulozenka_objednavka_zobrazit_pobocku' );
add_action( 'woocommerce_order_details_after_order_table', 'ceske_sluzby_ulozenka_objednavka_zobrazit_pobocku' );
add_action( 'woocommerce_review_order_after_shipping', 'ceske_sluzby_dpd_parcelshop_zobrazit_pobocky' );
add_action( 'woocommerce_new_order_item', 'ceske_sluzby_dpd_parcelshop_ulozeni_pobocky', 10, 2 );
add_action( 'woocommerce_checkout_process', 'ceske_sluzby_dpd_parcelshop_overit_pobocku' );
add_action( 'woocommerce_admin_order_data_after_billing_address', 'ceske_sluzby_dpd_parcelshop_objednavka_zobrazit_pobocku' );
add_action( 'woocommerce_email_after_order_table', 'ceske_sluzby_dpd_parcelshop_objednavka_zobrazit_pobocku' );
add_action( 'woocommerce_order_details_after_order_table', 'ceske_sluzby_dpd_parcelshop_objednavka_zobrazit_pobocku' );
$aktivace_zasilkovna = get_option( 'wc_ceske_sluzby_doprava_zasilkovna' );
if ( $aktivace_zasilkovna == "yes" ) {
add_action( 'woocommerce_shipping_init', 'ceske_sluzby_doprava_zasilkovna_init' );
add_filter( 'woocommerce_shipping_methods', 'ceske_sluzby_doprava_zasilkovna' );
$zasilkovna_settings = get_option( 'woocommerce_ceske_sluzby_zasilkovna_settings' );
if ( isset( $zasilkovna_settings['zasilkovna_api-klic'] ) && ! empty( $zasilkovna_settings['zasilkovna_api-klic'] ) ) {
add_action( 'wp_footer', 'ceske_sluzby_zasilkovna_scripts_checkout', 100 );
add_action( 'woocommerce_review_order_after_shipping', 'ceske_sluzby_zasilkovna_zobrazit_pobocky' );
add_action( 'woocommerce_new_order_item', 'ceske_sluzby_zasilkovna_ulozeni_pobocky', 10, 2 );
add_action( 'woocommerce_checkout_process', 'ceske_sluzby_zasilkovna_overit_pobocku' );
add_action( 'woocommerce_admin_order_data_after_billing_address', 'ceske_sluzby_zasilkovna_objednavka_zobrazit_pobocku' );
add_action( 'woocommerce_email_after_order_table', 'ceske_sluzby_zasilkovna_objednavka_zobrazit_pobocku' );
add_action( 'woocommerce_order_details_after_order_table', 'ceske_sluzby_zasilkovna_objednavka_zobrazit_pobocku' );
}
}
add_filter( 'woocommerce_pay4pay_cod_amount', 'ceske_sluzby_ulozenka_dobirka_pay4pay' );
add_filter( 'woocommerce_pay4pay_cod_amount', 'ceske_sluzby_dpd_parcelshop_dobirka_pay4pay' );
$aktivace_recenzi = get_option( 'wc_ceske_sluzby_heureka_recenze_obchodu-aktivace' );
if ( $aktivace_recenzi == "yes" ) {
add_shortcode( 'heureka-recenze-obchodu', 'ceske_sluzby_heureka_recenze_obchodu' );
}
$sledovani_zasilek = get_option( 'wc_ceske_sluzby_dalsi_nastaveni_sledovani-zasilek' );
if ( $sledovani_zasilek == "yes" ) {
add_filter( 'woocommerce_email_classes', 'ceske_sluzby_sledovani_zasilek_email' );
if ( version_compare( WC_VERSION, '3.2', '>=' ) ) {
add_filter( 'woocommerce_email_actions', 'ceske_sluzby_sledovani_zasilek_email_akce' );
}
}
$aktivace_eet = get_option( 'wc_ceske_sluzby_dalsi_nastaveni_eet-aktivace' );
if ( $aktivace_eet == "yes" ) {
add_filter( 'upload_mimes', 'ceske_sluzby_povolit_nahravani_certifikatu' );
require_once plugin_dir_path( __FILE__ ) . 'includes/class-ceske-sluzby-eet.php';
add_action( 'wpo_wcpdf_after_order_details', 'ceske_sluzby_zobrazit_eet_faktura_externi', 10, 2 );
add_action( 'woocommerce_order_status_completed', 'ceske_sluzby_automaticky_ziskat_uctenku' );
add_action( 'woocommerce_payment_complete', 'ceske_sluzby_automaticky_ziskat_uctenku' );
add_action( 'woocommerce_email_order_meta', 'ceske_sluzby_zobrazit_eet_email', 10, 4 );
if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
add_filter( 'woocommerce_order_tax_totals', 'ceske_sluzby_doplnit_danovou_sazbu' );
} else {
add_filter( 'woocommerce_order_get_tax_totals', 'ceske_sluzby_doplnit_danovou_sazbu' );
}
}
$aktivace_dodaci_doby = get_option( 'wc_ceske_sluzby_dalsi_nastaveni_dodaci_doba-aktivace' );
if ( $aktivace_dodaci_doby == "yes" ) {
$dodaci_doba = get_option( 'wc_ceske_sluzby_dodaci_doba_zobrazovani' );
if ( ! empty( $dodaci_doba ) ) {
foreach ( $dodaci_doba as $zobrazeni ) {
if ( $zobrazeni == 'get_availability_text' ) {
// Původně použitý filtr woocommerce_get_availability_text je funkční až od WooCommerce 2.6.2
// https://github.com/woocommerce/woocommerce/commit/33346938855b334861678bccecef4a58e5fc0cfa
add_filter( 'woocommerce_get_availability', 'ceske_sluzby_zobrazit_dodaci_dobu_filtr', 10, 2 );
add_action( 'woocommerce_before_add_to_cart_form', 'ceske_sluzby_zobrazit_dodatecnou_dodaci_dobu_akce' );
add_filter( 'woocommerce_available_variation', 'ceske_sluzby_zobrazit_dodatecnou_dodaci_dobu_filtr', 10, 3 );
}
if ( $zobrazeni == 'before_add_to_cart_form' ) {
add_action( 'woocommerce_before_add_to_cart_form', 'ceske_sluzby_zobrazit_dodaci_dobu_akce' );
if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
add_filter( 'woocommerce_stock_html', 'ceske_sluzby_nahradit_zobrazeny_text_deprecated', 10, 3 );
} else {
add_filter( 'woocommerce_get_stock_html', 'ceske_sluzby_nahradit_zobrazeny_text', 10, 2 );
}
add_action( 'woocommerce_before_add_to_cart_form', 'ceske_sluzby_zobrazit_dodatecnou_dodaci_dobu_akce' );
add_filter( 'woocommerce_available_variation', 'ceske_sluzby_zobrazit_dodatecnou_dodaci_dobu_filtr', 10, 3 );
}
if ( $zobrazeni == 'after_shop_loop_item' ) {
add_action( 'woocommerce_after_shop_loop_item', 'ceske_sluzby_zobrazit_dodaci_dobu_akce', 8 );
add_action( 'woocommerce_after_shop_loop_item', 'ceske_sluzby_zobrazit_dodatecnou_dodaci_dobu_akce', 9 );
}
}
}
add_filter( 'woocommerce_admin_stock_html', 'ceske_sluzby_zobrazeni_dodaci_doby_administrace', 10, 2 );
add_action( 'woocommerce_variation_header', 'ceske_sluzby_zobrazeni_dodaci_doby_varianty' );
add_action( 'admin_head', 'ceske_sluzby_zobrazeni_dodaci_doby_administrace_css' );
}
add_action( 'admin_enqueue_scripts', 'ceske_sluzby_load_admin_scripts' );
add_action( 'wp_footer', 'ceske_sluzby_heureka_certifikat_spokojenosti' ); // Pouze pro eshop nebo na celém webu?
add_action( 'woocommerce_cart_calculate_fees', 'ceske_sluzby_zaokrouhlovani_poplatek' );
add_action( 'woocommerce_after_calculate_totals', 'ceske_sluzby_spustit_zaokrouhlovani' );
add_action( 'wp_footer', 'ceske_sluzby_aktualizovat_checkout_javascript' );
add_filter( 'woocommerce_available_payment_gateways', 'ceske_sluzby_dostupne_platebni_metody' );
$nepresne_zaokrouhleni = get_option( 'wc_ceske_sluzby_dalsi_nastaveni_nepresne-zaokrouhleni' );
if ( $nepresne_zaokrouhleni == "yes" ) {
add_filter( 'woocommerce_calc_tax', 'ceske_sluzby_zmena_kalkulace_dani' );
add_filter( 'woocommerce_tax_round', 'ceske_sluzby_zmena_zaokrouhlovani_dani' );
}
$zmena_platby_predem = get_option( 'wc_ceske_sluzby_dalsi_nastaveni_zmena-platby-predem' );
if ( $zmena_platby_predem == "yes" ) {
add_filter( 'woocommerce_bacs_process_payment_order_status','ceske_sluzby_zmena_stavu_objednavky_platba_predem', 10, 2 );
add_filter( 'woocommerce_email_actions', 'ceske_sluzby_moznost_odesilat_emaily_zmena_stavu_platba_predem' );
add_action( 'woocommerce_email', 'ceske_sluzby_zmena_emailovych_notifikaci_platba_predem' );
add_action( 'init', 'ceske_sluzby_odebrat_bankovni_ucet_po_dokonceni_objednavky', 100 );
add_action( 'admin_head', 'ceske_sluzby_stylovani_tlacitek_objednavky_administrace_css' );
}
}
}
add_action( 'plugins_loaded', 'ceske_sluzby_kontrola_aktivniho_pluginu' );
function ceske_sluzby_doprava_ulozenka_init() {
if ( ! class_exists( 'WC_Shipping_Ceske_Sluzby_Ulozenka' ) ) {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-ceske-sluzby-ulozenka.php';
}
}
function ceske_sluzby_doprava_ulozenka( $methods ) {
$methods[] = 'WC_Shipping_Ceske_Sluzby_Ulozenka';
return $methods;
}
function ceske_sluzby_ulozenka_zobrazit_pobocky() {
if ( is_ajax() ) {
// Do budoucna možná použít spíše woocommerce_checkout_update_order_review
$ulozenka_branches = '';
if ( isset( $_POST['post_data'] ) ) {
parse_str( $_POST['post_data'], $post_data );
if ( isset( $post_data['ulozenka_branches'] ) ) {
$ulozenka_branches = $post_data['ulozenka_branches'];
}
}
$available_shipping = WC()->shipping->load_shipping_methods();
$chosen_shipping_method = WC()->session->get( 'chosen_shipping_methods' );
$settings = array();
if ( $chosen_shipping_method[0] == "ceske_sluzby_ulozenka" ) {
$settings = $available_shipping[ $chosen_shipping_method[0] ]->settings;
if ( $settings['enabled'] == "yes" && ! empty( $settings['ulozenka_id-obchodu'] ) ) {
$json_class = new Ceske_Sluzby_Json_Loader();
// http://docs.ulozenkav3.apiary.io/#pepravnsluby
$zeme = WC()->customer->get_shipping_country();
if ( $zeme == "CZ" ) { $zeme_code = "CZE"; }
if ( $zeme == "SK" ) { $zeme_code = "SVK"; }
$parametry = array( 'provider' => 1, 'country' => $zeme_code ); ?>
<tr class="ulozenka">
<td>
<img src="https://www.ulozenka.cz/logo/ulozenka.png" width="140" border="0">
</td>
<td>
<font size="2">Uloženka - výběr pobočky:</font><br>
<div id="ulozenka-branch-select-options">
<select name="ulozenka_branches">
<option>Vyberte pobočku</option>
<?php $json = $json_class->load( $parametry );
if ( isset( $json->data->destination ) && ! empty( $json->data->destination ) ) {
$pobocky = $json_class->sortName( $json->data->destination );
foreach ( $pobocky as $pobocka ) {
echo '<option value="' . $pobocka . '"' . selected( $pobocka, $ulozenka_branches ) . '>' . $pobocka . '</option>';
}
} ?>
</select>
</div>
</td>
</tr>
<?php }
}
}
}
function ceske_sluzby_ulozenka_ulozeni_pobocky( $item_id, $item ) {
if ( isset( $_POST["ulozenka_branches"] ) ) {
if ( $_POST["ulozenka_branches"] && $_POST["shipping_method"][0] == "ceske_sluzby_ulozenka" ) {
if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
$item_type = $item['order_item_type'];
} else {
$item_type = $item->get_type();
}
if ( $item_type == 'shipping' ) {
wc_add_order_item_meta( $item_id, 'ceske_sluzby_ulozenka_pobocka_nazev', esc_attr( $_POST['ulozenka_branches'] ), true );
}
}
}
}
function ceske_sluzby_ulozenka_overit_pobocku() {
if ( isset( $_POST["ulozenka_branches"] ) ) {
if ( $_POST["ulozenka_branches"] == "Vyberte pobočku" && $_POST["shipping_method"][0] == "ceske_sluzby_ulozenka" ) {
wc_add_notice( 'Pokud chcete doručit zboží prostřednictvím Uloženky, zvolte prosím pobočku.', 'error' );
}
}
}
function ceske_sluzby_ulozenka_objednavka_zobrazit_pobocku( $order ) {
if ( $order->has_shipping_method( 'ceske_sluzby_ulozenka' ) ) {
foreach ( $order->get_shipping_methods() as $shipping_item_id => $shipping_item ) {
if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
$pobocka = $order->get_item_meta( $shipping_item_id, 'ceske_sluzby_ulozenka_pobocka_nazev', true );
} else {
$pobocka = wc_get_order_item_meta( $shipping_item_id, 'ceske_sluzby_ulozenka_pobocka_nazev', true );
}
if ( ! empty( $pobocka ) ) {
echo "<p><strong>Uloženka:</strong> " . $pobocka . "</p>";
}
}
}
}
function ceske_sluzby_ulozenka_dobirka_pay4pay( $amount ) {
$available_shipping = WC()->shipping->load_shipping_methods();
$chosen_shipping_method = WC()->session->get( 'chosen_shipping_methods' );
if ( $chosen_shipping_method[0] == "ceske_sluzby_ulozenka" ) {
$settings = $available_shipping[ $chosen_shipping_method[0] ]->settings;
$zeme = WC()->customer->get_shipping_country();
if ( $zeme == "CZ" ) {
if ( ! empty( $settings['ulozenka_dobirka'] ) ) {
$amount = $settings['ulozenka_dobirka'];
}
}
if ( $zeme == "SK" ) {
if ( ! empty( $settings['ulozenka_dobirka-slovensko'] ) ) {
$amount = $settings['ulozenka_dobirka-slovensko'];
}
}
if ( class_exists( 'WOOCS' ) ) {
$amount = apply_filters( 'woocs_exchange_value', $amount );
}
}
return $amount;
}
function ceske_sluzby_doprava_dpd_parcelshop_init() {
if ( ! class_exists( 'WC_Shipping_Ceske_Sluzby_DPD_ParcelShop' ) ) {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-ceske-sluzby-dpd-parcelshop.php';
require_once plugin_dir_path( __FILE__ ) . 'includes/class-ceske-sluzby-json-loader.php';
}
}
function ceske_sluzby_doprava_dpd_parcelshop( $methods ) {
$methods[] = 'WC_Shipping_Ceske_Sluzby_DPD_ParcelShop';
return $methods;
}
function ceske_sluzby_dpd_parcelshop_zobrazit_pobocky() {
if ( is_ajax() ) {
$dpd_parcelshop_branches = '';
if ( isset( $_POST['post_data'] ) ) {
parse_str( $_POST['post_data'], $post_data );
if ( isset( $post_data['dpd_parcelshop_branches'] ) ) {
$dpd_parcelshop_branches = $post_data['dpd_parcelshop_branches'];
}
}
$available_shipping = WC()->shipping->load_shipping_methods();
$chosen_shipping_method = WC()->session->get( 'chosen_shipping_methods' );
$settings = array();
if ( $chosen_shipping_method[0] == "ceske_sluzby_dpd_parcelshop" ) {
$settings = $available_shipping[ $chosen_shipping_method[0] ]->settings;
if ( $settings['enabled'] == "yes" ) {
$json_class = new Ceske_Sluzby_Json_Loader();
$zeme = WC()->customer->get_shipping_country();
if ( $zeme == "CZ" ) { $zeme_code = "CZE"; }
if ( $zeme == "SK" ) { $zeme_code = "SVK"; }
$parametry = array( 'provider' => 5, 'country' => $zeme_code ); ?>
<tr class="dpd-parcelshop">
<td>
<img src="http://www.dpdparcelshop.cz/images/DPD-logo.png" width="140" border="0">
</td>
<td>
<font size="2">DPD ParcelShop - výběr pobočky:</font><br>
<div id="dpd-parcelshop-branch-select-options">
<select name="dpd_parcelshop_branches">
<option>Vyberte pobočku</option>
<?php $json = $json_class->load( $parametry );
if ( isset( $json->data->destination ) && ! empty( $json->data->destination ) ) {
$pobocky = $json_class->sortName( $json->data->destination );
foreach ( $pobocky as $pobocka ) {
echo '<option value="' . $pobocka . '"' . selected( $pobocka, $dpd_parcelshop_branches ) . '>' . $pobocka . '</option>';
}
} ?>
</select>
</div>
</td>
</tr>
<?php }
}
}
}
function ceske_sluzby_dpd_parcelshop_ulozeni_pobocky( $item_id, $item ) {
if ( isset( $_POST["dpd_parcelshop_branches"] ) ) {
if ( $_POST["dpd_parcelshop_branches"] && $_POST["shipping_method"][0] == "ceske_sluzby_dpd_parcelshop" ) {
if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
$item_type = $item['order_item_type'];
} else {
$item_type = $item->get_type();
}
if ( $item_type == 'shipping' ) {
wc_add_order_item_meta( $item_id, 'ceske_sluzby_dpd_parcelshop_pobocka_nazev', esc_attr( $_POST['dpd_parcelshop_branches'] ), true );
}
}
}
}
function ceske_sluzby_dpd_parcelshop_overit_pobocku() {
if ( isset( $_POST["dpd_parcelshop_branches"] ) ) {
if ( $_POST["dpd_parcelshop_branches"] == "Vyberte pobočku" && $_POST["shipping_method"][0] == "ceske_sluzby_dpd_parcelshop" ) {
wc_add_notice( 'Pokud chcete doručit zboží prostřednictvím DPD ParcelShop, zvolte prosím pobočku.', 'error' );
}
}
}
function ceske_sluzby_dpd_parcelshop_objednavka_zobrazit_pobocku( $order ) {
if ( $order->has_shipping_method( 'ceske_sluzby_dpd_parcelshop' ) ) {
foreach ( $order->get_shipping_methods() as $shipping_item_id => $shipping_item ) {
if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
$pobocka = $order->get_item_meta( $shipping_item_id, 'ceske_sluzby_dpd_parcelshop_pobocka_nazev', true );
} else {
$pobocka = wc_get_order_item_meta( $shipping_item_id, 'ceske_sluzby_dpd_parcelshop_pobocka_nazev', true );
}
if ( ! empty( $pobocka ) ) {
echo "<p><strong>DPD ParcelShop:</strong> " . $pobocka . "</p>";
}
}
}
}
function ceske_sluzby_dpd_parcelshop_dobirka_pay4pay( $amount ) {
$available_shipping = WC()->shipping->load_shipping_methods();
$chosen_shipping_method = WC()->session->get( 'chosen_shipping_methods' );
if ( $chosen_shipping_method[0] == "ceske_sluzby_dpd_parcelshop" ) {
$settings = $available_shipping[ $chosen_shipping_method[0] ]->settings;
$zeme = WC()->customer->get_shipping_country();
if ( $zeme == "CZ" ) {
if ( ! empty( $settings['dpd_parcelshop_dobirka'] ) ) {
$amount = $settings['dpd_parcelshop_dobirka'];
}
}
if ( $zeme == "SK" ) {
if ( ! empty( $settings['dpd_parcelshop_dobirka-slovensko'] ) ) {
$amount = $settings['dpd_parcelshop_dobirka-slovensko'];
}
}
if ( class_exists( 'WOOCS' ) ) {
$amount = apply_filters( 'woocs_exchange_value', $amount );
}
}
return $amount;
}
function ceske_sluzby_doprava_zasilkovna_init() {
if ( ! class_exists( 'WC_Shipping_Ceske_Sluzby_Zasilkovna' ) ) {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-ceske-sluzby-zasilkovna.php';
}
}
function ceske_sluzby_doprava_zasilkovna( $methods ) {
$methods['ceske_sluzby_zasilkovna'] = 'WC_Shipping_Ceske_Sluzby_Zasilkovna';
return $methods;
}
function ceske_sluzby_zasilkovna_zobrazit_pobocky() {
if ( is_ajax() ) {
$zasilkovna_branches = '';
if ( isset( $_POST['post_data'] ) ) {
parse_str( $_POST['post_data'], $post_data );
if ( isset( $post_data['packeta-point-id'] ) ) {
$zasilkovna_branches = $post_data['packeta-point-id'];
}
}
$chosen_shipping_method = WC()->session->get( 'chosen_shipping_methods' );
if ( strpos( $chosen_shipping_method[0], "ceske_sluzby_zasilkovna" ) !== false ) { ?>
<tr class="zasilkovna">
<td>
<img src="https://files.packeta.com/web/images/page/Zasilkovna_logo_WEB_tb_nove.png" width="200" border="0">
</td>
<td>
<input type="button" onclick="Packeta.Widget.pick(packetaApiKey, showSelectedPickupPoint)" value="Zvolit pobočku">
<div>Pobočka:
<input type="hidden" id="packeta-point-id" name="packeta-point-id" value="<?php echo $zasilkovna_branches; ?>">
<span id="packeta-point-info" style="font-weight:bold;"><?php if ( $zasilkovna_branches ) { echo $zasilkovna_branches; } else { echo "Zatím nevybráno"; } ?></span>
</div>
</td>
</tr>
<?php } else { ?>
<input type="hidden" id="packeta-point-id" name="packeta-point-id" value="<?php echo $zasilkovna_branches; ?>">
<?php }
}
}
function ceske_sluzby_zasilkovna_ulozeni_pobocky( $item_id, $item ) {
if ( isset( $_POST["packeta-point-id"] ) ) {
if ( ! empty( $_POST["packeta-point-id"] ) && strpos( $_POST["shipping_method"][0], "ceske_sluzby_zasilkovna" ) !== false ) {
if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
$item_type = $item['order_item_type'];
} else {
$item_type = $item->get_type();
}
if ( $item_type == 'shipping' ) {
wc_add_order_item_meta( $item_id, 'ceske_sluzby_zasilkovna_pobocka_nazev', esc_attr( $_POST['packeta-point-id'] ), true );
}
}
}
}
function ceske_sluzby_zasilkovna_overit_pobocku() {
if ( isset( $_POST["packeta-point-id"] ) ) {
if ( empty( $_POST["packeta-point-id"] ) && strpos( $_POST["shipping_method"][0], "ceske_sluzby_zasilkovna" ) !== false ) {
wc_add_notice( 'Pokud chcete doručit zboží prostřednictvím Zásilkovny, zvolte prosím pobočku.', 'error' );
}
}
}
function ceske_sluzby_zasilkovna_objednavka_zobrazit_pobocku( $order ) {
if ( $order->has_shipping_method( 'ceske_sluzby_zasilkovna' ) ) {
foreach ( $order->get_shipping_methods() as $shipping_item_id => $shipping_item ) {
if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
$pobocka = $order->get_item_meta( $shipping_item_id, 'ceske_sluzby_zasilkovna_pobocka_nazev', true );
} else {
$pobocka = wc_get_order_item_meta( $shipping_item_id, 'ceske_sluzby_zasilkovna_pobocka_nazev', true );
}
if ( ! empty( $pobocka ) ) {
echo "<p><strong>Zásilkovna:</strong> " . $pobocka . "</p>";
}
}
}
}
function ceske_sluzby_moznost_menit_dobirku( $zmena, $objednavka ) {
// https://www.separatista.net/forum/tema/woocommerce-a-dobirka
$moznost_zmeny = get_option( 'wc_ceske_sluzby_dalsi_nastaveni_dobirka-zmena' );
$status = $objednavka->get_status();
if ( $moznost_zmeny == "yes" && $status == "processing" ) {
$zmena = true;
}
return $zmena;
}
add_action( 'init', 'ceske_sluzby_aktivace_xml_feed' );
function ceske_sluzby_aktivace_xml_feed() {
$aktivace_xml = get_option( 'wc_ceske_sluzby_heureka_xml_feed-aktivace' );
if ( $aktivace_xml == "yes" ) {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-ceske-sluzby-xml.php';
add_feed( 'heureka', 'xml_feed_zobrazeni' );
add_feed( 'glami', 'xml_feed_zobrazeni' );
add_feed( 'zbozi', 'zbozi_xml_feed_zobrazeni' );
add_feed( 'google', 'google_xml_feed_zobrazeni' );
$heureka_xml = get_option( 'wc_ceske_sluzby_xml_feed_heureka-aktivace' );
if ( $heureka_xml == "yes" ) {
if ( ! wp_next_scheduled( 'ceske_sluzby_heureka_aktualizace_xml' ) ) {
wp_schedule_event( current_time( 'timestamp', 1 ), 'daily', 'ceske_sluzby_heureka_aktualizace_xml' );
}
} else {
if ( wp_next_scheduled( 'ceske_sluzby_heureka_aktualizace_xml' ) ) {
$timestamp = wp_next_scheduled( 'ceske_sluzby_heureka_aktualizace_xml' );
wp_unschedule_event( $timestamp, 'ceske_sluzby_heureka_aktualizace_xml' );
}
}
$zbozi_xml = get_option( 'wc_ceske_sluzby_xml_feed_zbozi-aktivace' );
if ( $zbozi_xml == "yes" ) {
if ( ! wp_next_scheduled( 'ceske_sluzby_zbozi_aktualizace_xml' ) ) {
wp_schedule_event( current_time( 'timestamp', 1 ) + MINUTE_IN_SECONDS, 'daily', 'ceske_sluzby_zbozi_aktualizace_xml' );
}
} else {
if ( wp_next_scheduled( 'ceske_sluzby_zbozi_aktualizace_xml' ) ) {
$timestamp = wp_next_scheduled( 'ceske_sluzby_zbozi_aktualizace_xml' );
wp_unschedule_event( $timestamp, 'ceske_sluzby_zbozi_aktualizace_xml' );
}
}
$pricemania_xml = get_option( 'wc_ceske_sluzby_xml_feed_pricemania-aktivace' );
if ( $pricemania_xml == "yes" ) {
if ( ! wp_next_scheduled( 'ceske_sluzby_pricemania_aktualizace_xml' ) ) {
wp_schedule_event( current_time( 'timestamp', 1 ) + ( 2 * MINUTE_IN_SECONDS ), 'daily', 'ceske_sluzby_pricemania_aktualizace_xml' );
}
} else {
if ( wp_next_scheduled( 'ceske_sluzby_pricemania_aktualizace_xml' ) ) {
$timestamp = wp_next_scheduled( 'ceske_sluzby_pricemania_aktualizace_xml' );
wp_unschedule_event( $timestamp, 'ceske_sluzby_pricemania_aktualizace_xml' );
}
}
$glami_xml = get_option( 'wc_ceske_sluzby_xml_feed_glami-aktivace' );
if ( $glami_xml == "yes" ) {
if ( ! wp_next_scheduled( 'ceske_sluzby_glami_aktualizace_xml' ) ) {
wp_schedule_event( current_time( 'timestamp', 1 ) + ( 3 * MINUTE_IN_SECONDS ), 'daily', 'ceske_sluzby_glami_aktualizace_xml' );
}
} else {
if ( wp_next_scheduled( 'ceske_sluzby_glami_aktualizace_xml' ) ) {
$timestamp = wp_next_scheduled( 'ceske_sluzby_glami_aktualizace_xml' );
wp_unschedule_event( $timestamp, 'ceske_sluzby_glami_aktualizace_xml' );
}
}
} else {
if ( wp_next_scheduled( 'ceske_sluzby_heureka_aktualizace_xml' ) ) {
$timestamp = wp_next_scheduled( 'ceske_sluzby_heureka_aktualizace_xml' );
wp_unschedule_event( $timestamp, 'ceske_sluzby_heureka_aktualizace_xml' );
}
if ( wp_next_scheduled( 'ceske_sluzby_zbozi_aktualizace_xml' ) ) {
$timestamp = wp_next_scheduled( 'ceske_sluzby_zbozi_aktualizace_xml' );
wp_unschedule_event( $timestamp, 'ceske_sluzby_zbozi_aktualizace_xml' );
}
if ( wp_next_scheduled( 'ceske_sluzby_pricemania_aktualizace_xml' ) ) {
$timestamp = wp_next_scheduled( 'ceske_sluzby_pricemania_aktualizace_xml' );
wp_unschedule_event( $timestamp, 'ceske_sluzby_pricemania_aktualizace_xml' );
}
if ( wp_next_scheduled( 'ceske_sluzby_glami_aktualizace_xml' ) ) {
$timestamp = wp_next_scheduled( 'ceske_sluzby_glami_aktualizace_xml' );
wp_unschedule_event( $timestamp, 'ceske_sluzby_glami_aktualizace_xml' );
}
}
}
add_action( 'ceske_sluzby_heureka_aktualizace_xml', 'ceske_sluzby_heureka_xml_feed_aktualizace' );
add_action( 'ceske_sluzby_heureka_aktualizace_xml_batch', 'ceske_sluzby_heureka_xml_feed_aktualizace' );
function ceske_sluzby_heureka_xml_feed_aktualizace() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-ceske-sluzby-xml.php';
xml_feed_aktualizace_nastaveni( 'heureka' );
}
add_action( 'ceske_sluzby_glami_aktualizace_xml', 'ceske_sluzby_glami_xml_feed_aktualizace' );
add_action( 'ceske_sluzby_glami_aktualizace_xml_batch', 'ceske_sluzby_glami_xml_feed_aktualizace' );
function ceske_sluzby_glami_xml_feed_aktualizace() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-ceske-sluzby-xml.php';
xml_feed_aktualizace_nastaveni( 'glami' );
}
add_action( 'ceske_sluzby_zbozi_aktualizace_xml', 'ceske_sluzby_zbozi_xml_feed_aktualizace' );
add_action( 'ceske_sluzby_zbozi_aktualizace_xml_batch', 'ceske_sluzby_zbozi_xml_feed_aktualizace' );
function ceske_sluzby_zbozi_xml_feed_aktualizace() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-ceske-sluzby-xml.php';
zbozi_xml_feed_aktualizace();
}
add_action( 'ceske_sluzby_pricemania_aktualizace_xml', 'ceske_sluzby_pricemania_xml_feed_aktualizace' );
add_action( 'ceske_sluzby_pricemania_aktualizace_xml_batch', 'ceske_sluzby_pricemania_xml_feed_aktualizace' );
function ceske_sluzby_pricemania_xml_feed_aktualizace() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-ceske-sluzby-xml.php';
pricemania_xml_feed_aktualizace();
}
// https://docs.woothemes.com/document/hide-other-shipping-methods-when-free-shipping-is-available/
function ceske_sluzby_omezit_dopravu_pokud_dostupna_zdarma( $rates, $package ) {
$omezit_dopravu = get_option( 'wc_ceske_sluzby_dalsi_nastaveni_doprava-pouze-zdarma' );
if ( $omezit_dopravu == "yes" ) {
$rates_omezeno = array();
if ( version_compare( WC_VERSION, '2.6', '<' ) ) {
if ( isset( $rates['free_shipping'] ) ) {
$free_shipping = $rates['free_shipping'];
if ( isset( $rates['local_pickup'] ) ) {
$local_pickup = $rates['local_pickup'];
}
$rates_omezeno['free_shipping'] = $free_shipping;
if ( isset( $local_pickup ) ) {
$rates_omezeno['local_pickup'] = $local_pickup;
}
}
} else {
if ( isset( $rates['legacy_free_shipping'] ) ) {
$free_shipping = $rates['legacy_free_shipping'];
if ( isset( $rates['legacy_local_pickup'] ) ) {
$local_pickup = $rates['legacy_local_pickup'];
}
$rates_omezeno['legacy_free_shipping'] = $free_shipping;
if ( isset( $local_pickup ) ) {
$rates_omezeno['legacy_local_pickup'] = $local_pickup;
}
}
$free = $pickup = array();
foreach ( $rates as $rate_id => $rate ) {
if ( 'free_shipping' === $rate->method_id ) {
$rates_omezeno[ $rate_id ] = $rate;
$free[] = $rate_id;
}
if ( 'local_pickup' === $rate->method_id ) {
$rates_omezeno[ $rate_id ] = $rate;
$pickup[] = $rate_id;
}
}
if ( empty( $free ) && ! empty( $pickup ) ) {
foreach ( $pickup as $pickup_id ) {
unset( $rates_omezeno[ $pickup_id ] );
}
}
}
}
if ( ! empty( $rates_omezeno ) ) {
return $rates_omezeno;
} else {
return $rates;
}
}
function ceske_sluzby_heureka_recenze_obchodu( $atts ) {
$process = true;
$output = '<div class="recenze-zakazniku">';
$api = get_option( 'wc_ceske_sluzby_heureka_overeno-api' );
if ( ! empty( $api ) ) {
if ( false === ( $source_xml = get_transient( 'ceske_sluzby_heureka_recenze_zakazniku' ) ) ) {
$url = "https://www." . HEUREKA_URL . "/direct/dotaznik/export-review.php?key=" . $api;
$response = wp_remote_get( $url );
if ( ! is_wp_error( $response ) ) {
$source_xml = wp_remote_retrieve_body( $response );
if ( ! empty( $source_xml ) && wp_remote_retrieve_response_code( $response ) == 200 ) {
set_transient( 'ceske_sluzby_heureka_recenze_zakazniku', $source_xml, 24 * HOUR_IN_SECONDS );
} else {
$process = false;
}
} else {
$output .= 'Nepodařilo se získat data:' . $response->get_error_message();
}
}
if ( $process ) {
$recenze_xml = simplexml_load_string( $source_xml, 'SimpleXMLElement', LIBXML_NOCDATA );
$atributy = shortcode_atts( array( 'limit' => null ), $atts );
$limit = $atributy['limit'];
$i = 0;
if ( ! empty( $recenze_xml ) && ! is_scalar( $recenze_xml ) ) {
foreach( $recenze_xml as $recenze ) {
if ( ( ! empty( $limit ) && $i < $limit ) || empty( $limit ) ) {
if ( ! empty( $recenze->summary ) ) {
$i = $i + 1;
$output .= '<ul>';
$output .= '<li>';
$output .= '<strong>' . $recenze->summary . '</strong><br />';
if ( ! empty( $recenze->total_rating ) ) {
$output .= 'Hodnocení: ' . $recenze->total_rating . '/5 | ';
}
$output .= 'Datum: před ' . human_time_diff( $recenze->unix_timestamp );
if ( ! empty( $recenze->name ) ) {
$output .= ' | Autor: ' . $recenze->name;
}
$output .= '</li>';
$output .= '</ul>';
}
}
else {
break;
}
}
}
else {
$output .= 'Zatím žádné hodnocení.';
}
} else {
$output .= 'Nepodařilo se získat data.';
}
} else {
$output .= 'Pro zobrazení recenzí musíte ještě <a href="' . admin_url(). 'admin.php?page=wc-settings&tab=ceske-sluzby">zadat</a> API klíč pro Ověřeno zákazníky.';
}
$output .= '</div>';
return $output;
}
function ceske_sluzby_heureka_overeno_zakazniky_souhlas() {
$api = get_option( 'wc_ceske_sluzby_heureka_overeno-api' );
$souhlas = get_option( 'wc_ceske_sluzby_heureka_overeno-souhlas' );
if ( ! empty( $api ) ) {
if ( $souhlas == 'nesouhlas_optout' ) {
woocommerce_form_field( 'heureka_overeno_zakazniky_nesouhlas_optout',
array(
'type' => 'checkbox',
'label' => 'Nesouhlasím se zasláním dotazníku spokojenosti v rámci programu Ověřeno zákazníky (Heureka), který pomáhá zlepšovat naše služby.',
)
);
}
if ( $souhlas == 'souhlas_optout' ) {
woocommerce_form_field( 'heureka_overeno_zakazniky_souhlas_optout',
array(
'type' => 'checkbox',
'label' => 'Souhlasím se zasláním dotazníku spokojenosti v rámci programu Ověřeno zákazníky (Heureka), který pomáhá zlepšovat naše služby.',
), 1
);
}
}
}
function ceske_sluzby_xml_kategorie_pridat_pole() {
$global_data = ceske_sluzby_xml_ziskat_globalni_hodnoty();
$xml_feed_heureka = get_option( 'wc_ceske_sluzby_xml_feed_heureka-aktivace' );
$xml_feed_zbozi = get_option( 'wc_ceske_sluzby_xml_feed_zbozi-aktivace' );
$xml_feed_glami = get_option( 'wc_ceske_sluzby_xml_feed_glami-aktivace' );
if ( $xml_feed_heureka == "yes" ) { ?>
<div style="font-size: 14px; font-weight: bold;">České služby: Heureka</div>
<div class="form-field">
<label for="ceske-sluzby-xml-heureka-kategorie">Kategorie</label>
<input name="ceske-sluzby-xml-heureka-kategorie" id="ceske-sluzby-xml-heureka-kategorie" type="text" value="" placeholder="CATEGORYTEXT" size="70"/>
<p>
Zatím je nutné doplnit příslušnou kategorii z Heureky ručně (aktuální přehled naleznete <a href="https://www.<?php echo HEUREKA_URL; ?>/direct/xml-export/shops/heureka-sekce.xml">zde</a>).<br />
Příklad: <strong>Elektronika | Počítače a kancelář | Software | Antiviry</strong><br />
Poznámka: Z <code>CATEGORY_FULLNAME</code> je třeba vynechat část <code><?php echo ucfirst( HEUREKA_URL ); ?> | </code>.
</p>
</div>
<?php if ( empty( $global_data['nazev_produktu'] ) || strpos( $global_data['nazev_produktu'], '{KATEGORIE}' ) !== false ) { ?>
<div class="form-field">
<label for="ceske-sluzby-xml-heureka-productname">Název produktů</label>
<input name="ceske-sluzby-xml-heureka-productname" id="ceske-sluzby-xml-heureka-productname" type="text" value="" placeholder="PRODUCTNAME" size="70"/>