-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
executable file
·1518 lines (1296 loc) · 64.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
/**
* Sage includes
*
* The $sage_includes array determines the code library included in your theme.
* Add or remove files to the array as needed. Supports child theme overrides.
*
* Please note that missing files will produce a fatal error.
*
* @link https://github.com/roots/sage/pull/1042
*/
$sage_includes = [
'lib/assets.php', // Scripts and stylesheets
'lib/extras.php', // Custom functions
'lib/wp_bootstrap_navwalker.php', //mega menu
'lib/setup.php', // Theme setup
'lib/titles.php', // Page titles
'lib/wrapper.php', // Theme wrapper class
'lib/customizer.php' // Theme customizer
];
/* Disable the Gutenberg editor. */
add_filter('use_block_editor_for_post', '__return_false');
// Inject instantsearch.js on every page regardless of backend config.
add_filter( 'algolia_wc_should_display_instantsearch', '__return_true' );
// This will make sure the search is displayed on load. Oterwise it waits for the query to change to be displayed.
add_filter( 'algolia_config', function( array $config ) {
$config['woocommerce']['replace_page'] = true;
return $config;
}, 20 );
function aa_algolia_enqueue_scripts() {
wp_deregister_script( 'algolia-instantsearch' );
wp_register_script( 'algolia-instantsearch', 'https://cdn.jsdelivr.net/npm/[email protected]', array( 'jquery', 'underscore', 'wp-util' ), '', true );
}
add_action( 'wp_enqueue_scripts', 'aa_algolia_enqueue_scripts' );
function aa_algolia_enqueue_styles() {
wp_deregister_style( 'algolia-instantsearch' );
wp_register_style( 'algolia-instantsearch', 'https://cdn.jsdelivr.net/npm/[email protected]/dist/instantsearch.min.css' );
}
add_action( 'wp_enqueue_styles', 'aa_algolia_enqueue_styles' );
/*add_action( 'wp_enqueue_scripts', function () {
// Enqueue the instantsearch.js default styles.
wp_enqueue_style( 'algolia-instantsearch' );
// Ensure jQuery is loaded.
wp_enqueue_script( 'jquery' );
// Enqueue the instantsearch.js library.
wp_enqueue_script( 'algolia-instantsearch' );
// WordPress utility useful for using underscore templating.
wp_enqueue_script( 'wp-util' );
// Allow users to easily enqueue custom styles and scripts.
do_action( 'algolia_instantsearch_scripts' );
} );*/
add_action( 'wp_ajax_nopriv_handle_shortcode', 'handle_shortcode' );
add_action( 'wp_ajax_handle_shortcode', 'handle_shortcode' );
function handle_shortcode( ) {
$shortcode = $_REQUEST['ti_wishlists_addtowishlist product_id=""'];
echo do_shortcode( $shortcode );
exit;
}
/* turns off widget/plugin css from being registered and printed in the head of the header.php */
function remove_assets() {
wp_dequeue_style( 'festi-cart-cart-customize-style' );
wp_dequeue_style( 'festi-cart-dropdown-list-customize-style' );
wp_dequeue_style( 'festi-cart-widget-customize-style' );
wp_dequeue_style( 'festi-cart-popup-customize-style' );
wp_dequeue_style( 'festi-cart-styles' );
wp_dequeue_style( 'festi-jquery-ui-spinner' );
wp_deregister_style( 'festi-cart-cart-customize-style' );
wp_deregister_style( 'festi-cart-dropdown-list-customize-style' );
wp_deregister_style( 'festi-cart-widget-customize-style' );
wp_deregister_style( 'festi-cart-popup-customize-style' );
wp_deregister_style( 'festi-cart-styles' );
wp_deregister_style( 'festi-jquery-ui-spinner' );
wp_dequeue_style( 'algolia-woocommerce-instantsearch' );
wp_deregister_style( 'algolia-woocommerce-instantsearch' );
wp_dequeue_style( 'yith-wcwl-font-awesome' );
wp_deregister_style( 'yith-wcwl-font-awesome' );
/*wp_dequeue_style( 'tinvwl' );
wp_deregister_style( 'tinvwl' );*/
wp_dequeue_style( 'font-awesome' );
wp_deregister_style( 'font-awesome' );
wp_dequeue_script( 'font-awesome' );
wp_dequeue_script( 'wc_price_slider' );
//wp_dequeue_script( 'wc-single-product' );
//wp_dequeue_script( 'wc-add-to-cart' );
//wp_dequeue_script( 'wc-cart-fragments' ); //Top right mini cart needs this!
//wp_dequeue_script( 'wc-checkout' );
wp_dequeue_script( 'wc-add-to-cart-variation' );
//wp_dequeue_script( 'wc-single-product' );
//wp_dequeue_script( 'wc-cart' );
wp_dequeue_script( 'wc-chosen' );
wp_dequeue_script( 'woocommerce' );
//wp_dequeue_script( 'prettyPhoto' );
//wp_dequeue_script( 'prettyPhoto-init' );
wp_dequeue_script( 'jquery-blockui' );
wp_dequeue_script( 'jquery-placeholder' );
wp_dequeue_script( 'fancybox' );
wp_dequeue_script( 'jqueryui' );
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
/* wp_dequeue_style( 'yith-quick-view' );
wp_deregister_style( 'yith-quick-view' );
*/
wp_dequeue_style( 'tm-woowishlist' );
wp_deregister_style( 'tm-woowishlist' );
wp_dequeue_style( 'woo-slg-public-style' );
wp_deregister_style( 'woo-slg-public-style' );
wp_dequeue_style( 'bootstrap-grid' );
wp_deregister_style( 'bootstrap-grid' );
wp_dequeue_style( 'wpeae-ali-variation-css' );
wp_deregister_style( 'wpeae-ali-variation-css' );
wp_dequeue_style( 'dgwt-wcas-style ' );
wp_deregister_style( 'dgwt-wcas-style ' );
}
add_action( 'wp_enqueue_scripts', 'remove_assets', 9999 );
// remove dashicons in frontend to non-admin
function wpdocs_dequeue_dashicon() {
if (current_user_can( 'update_core' )) {
return;
}
wp_deregister_style('dashicons');
}
add_action( 'wp_enqueue_scripts', 'wpdocs_dequeue_dashicon' );
/*
function crunchify_print_scripts_styles() {
// Print all loaded Styles (CSS)
global $wp_styles;
foreach( $wp_styles->queue as $style ) :
echo $style . ' || ';
endforeach;
}
add_action( 'wp_print_scripts', 'crunchify_print_scripts_styles' );
*/
/*
Function to defer all scripts which are not excluded
function crave_js_defer_attr($tag) {
if (is_admin()) {
return $tag;
}
// Do not add defer attribute to these scripts
$scripts_to_exclude = array('jquery.js'); // add a string of js file e.g. script.js
foreach($scripts_to_exclude as $exclude_script) {
if (true == strpos($tag, $exclude_script ) )
return $tag;
}
// Defer all remaining scripts not excluded above
return str_replace( ' src', ' defer src', $tag );
}
add_filter( 'script_loader_tag', 'crave_js_defer_attr', 10);
*/
remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );
foreach ($sage_includes as $file) {
if (!$filepath = locate_template($file)) {
trigger_error(sprintf(__('Error locating %s for inclusion', 'sage'), $file), E_USER_ERROR);
}
require_once $filepath;
}
unset($file, $filepath);
add_action( 'send_headers', 'tgm_io_strict_transport_security' );
/**
* Enables the HTTP Strict Transport Security (HSTS) header.
*
* @since 1.0.0
*/
function tgm_io_strict_transport_security() {
header( 'Strict-Transport-Security: max-age=10886400; includeSubDomains; preload' );
}
/**
* @snippet Disable Variable Product Price Range
* @how-to Watch tutorial @ https://businessbloomer.com/?p=19055
* @sourcecode https://businessbloomer.com/disable-variable-product-price-range-woocommerce/
* @author Rodolfo Melogli
* @compatible WooCommerce 2.4.7
*/
add_filter( 'woocommerce_variable_sale_price_html', 'bbloomer_variation_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'bbloomer_variation_price_format', 10, 2 );
function bbloomer_variation_price_format( $price, $product ) {
// Main Price
$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
$price = $prices[0] !== $prices[1] ? sprintf( __( '<div class="pricefrom"><span class="from">From:</span> %1$s</div>', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
// Sale Price
$prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) );
sort( $prices );
$saleprice = $prices[0] !== $prices[1] ? sprintf( __( '<div class="pricefrom"><span class="from">From:</span> %1$s</div>' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
if ( $price !== $saleprice ) {
$price = '<del>' . $saleprice . '</del> <ins>' . $price . '</ins>';
}
return $price;
}
/* ---------> ***************** <-------- */
/* ---------> WooCommerce Stuff <-------- */
/* ---------> ***************** <-------- */
/** https://businessbloomer.com/woocommerce-display-total-discount-savings-cart/
* @snippet Display Total Discount / Savings @ WooCommerce Cart/Checkout
* @how-to Watch tutorial @ https://businessbloomer.com/?p=19055
* @sourcecode https://businessbloomer.com/?p=20362
* @author Jamie Gill, Rodolfo Melogli, Lubo Enev
* @testedwith WooCommerce 2.6.14
*/
function bbloomer_wc_discount_total() {
global $woocommerce;
$discount_total = 0;
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values) {
$_product = $values['data'];
if ( $_product->is_on_sale() ) {
$discount = ($_product->regular_price - $_product->sale_price) * $values['quantity'];
$discount_total += $discount;
}
}
if ( $discount_total > 0 ) {
echo '<tr class="cart-discount">
<th>'. __( 'You Saved', 'woocommerce' ) .'</th>
<td data-title=" '. __( 'You Saved', 'woocommerce' ) .' ">'
. wc_price( $discount_total + $woocommerce->cart->discount_cart ) .'</td>
</tr>';
}
}
// Hook our values to the Basket and Checkout pages
add_action( 'woocommerce_cart_totals_after_order_total', 'bbloomer_wc_discount_total', 99);
add_action( 'woocommerce_review_order_after_order_total', 'bbloomer_wc_discount_total', 99);
/* Code to Remove the description tab */
add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
function woo_remove_product_tabs( $tabs ) {
//unset( $tabs['description'] ); // Remove the description tab
unset( $tabs['additional_information'] ); // Remove the description tab
return $tabs;
}
// Use the following snippet to rename tabs.
// add_filter( 'woocommerce_product_tabs', 'woo_rename_tabs', 98 );
// function woo_rename_tabs( $tabs ) {
// $tabs['reviews']['title'] = __( 'Reviews' ); // Rename the reviews tab
// $tabs['additional_information']['title'] = __( 'Product Data' ); // Rename the additional information tab
// return $tabs;
// }
/**
* Hide shipping rates when free shipping is available.
* Updated to support WooCommerce 2.6 Shipping Zones.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
foreach ( $rates as $rate_id => $rate ) {
if ( 'free_shipping' === $rate->method_id ) {
$free[ $rate_id ] = $rate;
break;
}
}
return ! empty( $free ) ? $free : $rates;
}
add_filter( 'woocommerce_package_rates', 'my_hide_shipping_when_free_is_available', 100 );
/**
* WooCommerce Extra Feature
* --------------------------
*
* Change number of related products on product page
* Set your own value for 'posts_per_page'
*
*/
function woo_related_products_limit() {
global $product;
$args['posts_per_page'] = 5;
return $args;
}
add_filter( 'woocommerce_output_related_products_args', 'jk_related_products_args' );
function jk_related_products_args( $args ) {
$args['posts_per_page'] = 10; // 4 related products
$args['columns'] = 1; // arranged in 2 columns
return $args;
}
/**
* @snippet Move & Change Number of Cross-Sells @ WooCommerce Cart
* @how-to Watch tutorial @ https://businessbloomer.com/?p=19055
* @sourcecode https://businessbloomer.com/?p=20449
* @author Rodolfo Melogli
* @testedwith WooCommerce 2.6.2
*/
// ---------------------------------------------
// Remove Cross Sells From Default Position
remove_action( 'woocommerce_cart_collaterals', 'woocommerce_cross_sell_display' );
// ---------------------------------------------
// Add them back UNDER the Cart Table
add_action( 'woocommerce_after_cart', 'woocommerce_cross_sell_display' );
// ---------------------------------------------
// Display Cross Sells on 3 columns instead of default 4
add_filter( 'woocommerce_cross_sells_columns', 'bbloomer_change_cross_sells_columns' );
function bbloomer_change_cross_sells_columns( $columns ) {
return 2;
}
// ---------------------------------------------
// Display Only 3 Cross Sells instead of default 4
add_filter( 'woocommerce_cross_sells_total', 'bbloomer_change_cross_sells_product_no' );
function bbloomer_change_cross_sells_product_no( $columns ) {
return 5;
}
add_filter( 'wc_add_to_cart_message', '__return_empty_string' );
function wooc_extra_register_fields() {?>
<p class="form-row form-row-wide"><label for="reg_billing_phone"><?php _e( 'Phone', 'woocommerce' ); ?></label>
<input type="text" class="input-text" name="billing_phone" id="reg_billing_phone" value="<?php esc_attr_e( $_POST['billing_phone'] ); ?>" />
</p>
<p class="form-row form-row-first"><label for="reg_billing_first_name"><?php _e( 'First name', 'woocommerce' ); ?><span class="required">*</span></label>
<input type="text" class="input-text" name="billing_first_name" id="reg_billing_first_name" value="<?php if ( ! empty( $_POST['billing_first_name'] ) ) esc_attr_e( $_POST['billing_first_name'] ); ?>" />
</p>
<p class="form-row form-row-last"><label for="reg_billing_last_name"><?php _e( 'Last name', 'woocommerce' ); ?><span class="required">*</span></label>
<input type="text" class="input-text" name="billing_last_name" id="reg_billing_last_name" value="<?php if ( ! empty( $_POST['billing_last_name'] ) ) esc_attr_e( $_POST['billing_last_name'] ); ?>" />
</p>
<?php
}
add_action( 'woocommerce_register_form_start', 'wooc_extra_register_fields' );
/**
* register fields Validating.
*/
function wooc_validate_extra_register_fields( $username, $email, $validation_errors ) {
if ( isset( $_POST['billing_first_name'] ) && empty( $_POST['billing_first_name'] ) ) {
$validation_errors->add( 'billing_first_name_error', __( '<strong>Error</strong>: First name is required!', 'woocommerce' ) );
}
if ( isset( $_POST['billing_last_name'] ) && empty( $_POST['billing_last_name'] ) ) {
$validation_errors->add( 'billing_last_name_error', __( '<strong>Error</strong>: Last name is required!.', 'woocommerce' ) );
}
return $validation_errors;
}
add_action( 'woocommerce_register_post', 'wooc_validate_extra_register_fields', 10, 3 );
/**
* Below code save extra fields.
*/
function wooc_save_extra_register_fields( $customer_id ) {
if ( isset( $_POST['billing_phone'] ) ) {
// Phone input filed which is used in WooCommerce
update_user_meta( $customer_id, 'billing_phone', sanitize_text_field( $_POST['billing_phone'] ) );
}
if ( isset( $_POST['billing_first_name'] ) ) {
//First name field which is by default
update_user_meta( $customer_id, 'first_name', sanitize_text_field( $_POST['billing_first_name'] ) );
// First name field which is used in WooCommerce
update_user_meta( $customer_id, 'billing_first_name', sanitize_text_field( $_POST['billing_first_name'] ) );
}
if ( isset( $_POST['billing_last_name'] ) ) {
// Last name field which is by default
update_user_meta( $customer_id, 'last_name', sanitize_text_field( $_POST['billing_last_name'] ) );
// Last name field which is used in WooCommerce
update_user_meta( $customer_id, 'billing_last_name', sanitize_text_field( $_POST['billing_last_name'] ) );
}
}
add_action( 'woocommerce_created_customer', 'wooc_save_extra_register_fields' );
// Remove WooCommerce core style one by one
add_filter( 'woocommerce_enqueue_styles', 'jk_dequeue_styles' );
function jk_dequeue_styles( $enqueue_styles ) {
unset( $enqueue_styles['woocommerce-general'] ); // Remove the gloss
unset( $enqueue_styles['woocommerce-layout'] ); // Remove the layout
unset( $enqueue_styles['woocommerce-smallscreen'] ); // Remove the smallscreen optimisation
unset( $enqueue_styles['woocommerce_frontend_styles'] ); // Remove the smallscreen optimisation
unset( $enqueue_styles['woocommerce-fancybox_styles'] ); // Remove the smallscreen optimisation
unset( $enqueue_styles['woocommerce-chosen_styles'] ); // Remove the smallscreen optimisation
unset( $enqueue_styles['woocommerce-prettyPhoto_css'] ); // Remove the smallscreen optimisation
return $enqueue_styles;
}
// auto check create account
add_filter('woocommerce_create_account_default_checked' , function ($checked){
return true;
});
// Change 'add to cart' text on single product page
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_add_to_cart_text' );
function woo_add_to_cart_text() {
return __( 'Add to Cart', 'woocommerce' );
}
// Cheapest Price
add_filter( 'woocommerce_variable_sale_price_html', 'wc_wc20_variation_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'wc_wc20_variation_price_format', 10, 2 );
function wc_wc20_variation_price_format( $price, $product ) {
// Main Price
$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
$price = $prices[0] !== $prices[1] ? sprintf( __( '%1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
// Sale Price
$prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) );
sort( $prices );
$saleprice = $prices[0] !== $prices[1] ? sprintf( __( '%1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
if ( $price !== $saleprice ) {
$price = '<del>' . $saleprice . '</del> <ins>' . $price . '</ins>';
}
return $price;
}
// show variation price
add_filter('woocommerce_show_variation_price', function() {return true;});
//override woocommerce function
function woocommerce_template_single_price() {
global $product;
if ( ! $product->is_type('variable') ) {
woocommerce_get_template( 'single-product/price.php' );
}
}
// variable pricing
function shuffle_variable_product_elements(){
if ( is_product() ) {
global $post;
$product = wc_get_product( $post->ID );
if ( $product->is_type( 'variable' ) ) {
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 10 );
add_action( 'woocommerce_before_variations_form', 'woocommerce_single_variation', 20 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
add_action( 'woocommerce_before_variations_form', 'woocommerce_template_single_title', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
add_action( 'woocommerce_before_variations_form', 'woocommerce_template_single_excerpt', 30 );
}
}
}
add_action( 'woocommerce_before_single_product', 'shuffle_variable_product_elements' );
// add hook
add_filter( 'wp_nav_menu_objects', 'my_wp_nav_menu_objects_sub_menu', 10, 2 );
// filter_hook function to react on sub_menu flag
function my_wp_nav_menu_objects_sub_menu( $sorted_menu_items, $args ) {
if ( isset( $args->sub_menu ) ) {
$root_id = 0;
// find the current menu item
foreach ( $sorted_menu_items as $menu_item ) {
if ( $menu_item->current ) {
// set the root id based on whether the current menu item has a parent or not
$root_id = ( $menu_item->menu_item_parent ) ? $menu_item->menu_item_parent : $menu_item->ID;
break;
}
}
// find the top level parent
if ( ! isset( $args->direct_parent ) ) {
$prev_root_id = $root_id;
while ( $prev_root_id != 0 ) {
foreach ( $sorted_menu_items as $menu_item ) {
if ( $menu_item->ID == $prev_root_id ) {
$prev_root_id = $menu_item->menu_item_parent;
// don't set the root_id to 0 if we've reached the top of the menu
if ( $prev_root_id != 0 ) $root_id = $menu_item->menu_item_parent;
break;
}
}
}
}
$menu_item_parents = array();
foreach ( $sorted_menu_items as $key => $item ) {
// init menu_item_parents
if ( $item->ID == $root_id ) $menu_item_parents[] = $item->ID;
if ( in_array( $item->menu_item_parent, $menu_item_parents ) ) {
// part of sub-tree: keep!
$menu_item_parents[] = $item->ID;
} else if ( ! ( isset( $args->show_parent ) && in_array( $item->ID, $menu_item_parents ) ) ) {
// not part of sub-tree: away with it!
unset( $sorted_menu_items[$key] );
}
}
return $sorted_menu_items;
} else {
return $sorted_menu_items;
}
}
add_filter( 'woocommerce_add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment' );
function woocommerce_header_add_to_cart_fragment( $fragments ) {
ob_start();
?>
<a class="cart-contents" href="<?php echo wc_get_cart_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>"><?php echo sprintf (_n( '%d item', '%d items', WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?> - <?php echo WC()->cart->get_cart_total(); ?></a>
<?php
$fragments['a.cart-contents'] = ob_get_clean();
return $fragments;
}
add_action( 'after_setup_theme', 'getkunst_setup' );
function getkunst_setup() {
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
}
// First, make sure Jetpack doesn't concatenate all its CSS
add_filter( 'jetpack_implode_frontend_css', '__return_false' );
// Then, remove each CSS file, one at a time
function jeherve_remove_all_jp_css() {
wp_deregister_style( 'AtD_style' ); // After the Deadline
wp_deregister_style( 'jetpack_likes' ); // Likes
wp_deregister_style( 'jetpack_related-posts' ); //Related Posts
wp_deregister_style( 'jetpack-carousel' ); // Carousel
wp_deregister_style( 'grunion.css' ); // Grunion contact form
wp_deregister_style( 'the-neverending-homepage' ); // Infinite Scroll
wp_deregister_style( 'infinity-twentyten' ); // Infinite Scroll - Twentyten Theme
wp_deregister_style( 'infinity-twentyeleven' ); // Infinite Scroll - Twentyeleven Theme
wp_deregister_style( 'infinity-twentytwelve' ); // Infinite Scroll - Twentytwelve Theme
wp_deregister_style( 'noticons' ); // Notes
wp_deregister_style( 'post-by-email' ); // Post by Email
wp_deregister_style( 'publicize' ); // Publicize
wp_deregister_style( 'sharedaddy' ); // Sharedaddy
wp_deregister_style( 'sharing' ); // Sharedaddy Sharing
wp_deregister_style( 'stats_reports_css' ); // Stats
wp_deregister_style( 'jetpack-widgets' ); // Widgets
wp_deregister_style( 'jetpack-slideshow' ); // Slideshows
wp_deregister_style( 'presentations' ); // Presentation shortcode
wp_deregister_style( 'jetpack-subscriptions' ); // Subscriptions
wp_deregister_style( 'tiled-gallery' ); // Tiled Galleries
wp_deregister_style( 'widget-conditions' ); // Widget Visibility
wp_deregister_style( 'jetpack_display_posts_widget' ); // Display Posts Widget
wp_deregister_style( 'gravatar-profile-widget' ); // Gravatar Widget
wp_deregister_style( 'widget-grid-and-list' ); // Top Posts widget
wp_deregister_style( 'jetpack-widgets' ); // Widgets
}
add_action('wp_print_styles', 'jeherve_remove_all_jp_css' );
/////////////////************woocommerce user backend************////////////////////
/////////////////************woocommerce user backend************////////////////////
/**
* @snippet WooCommerce Add New Tab @ My Account
* @how-to Watch tutorial @ https://businessbloomer.com/?p=19055
* @sourcecode https://businessbloomer.com/?p=21253
* @credits https://github.com/woothemes/woocommerce/wiki/2.6-Tabbed-My-Account-page
* @author Rodolfo Melogli
* @testedwith WooCommerce 2.6.7
*/
// ------------------
// 1. Register new endpoint to use for My Account page
// Note: Resave Permalinks or it will give 404 error
function bbloomer_add_wishlist_ba_endpoint() {
add_rewrite_endpoint( 'wishlist-ba', EP_ROOT | EP_PAGES );
}
add_action( 'init', 'bbloomer_add_wishlist_ba_endpoint' );
// ------------------
// 2. Add new query var
function bbloomer_wishlist_ba_query_vars( $vars ) {
$vars[] = 'wishlist-ba';
return $vars;
}
add_filter( 'query_vars', 'bbloomer_wishlist_ba_query_vars', 0 );
// ------------------
// 3. Insert the new endpoint into the My Account menu
function bbloomer_add_wishlist_ba_link_my_account( $items ) {
$items['wishlist-ba'] = 'Wishlist';
return $items;
}
add_filter( 'woocommerce_account_menu_items', 'bbloomer_add_wishlist_ba_link_my_account' );
// ------------------
// 4. Add content to the new endpoint
function bbloomer_wishlist_ba_content() {
echo '<h3>My Wishlist</h3><p></p>';
echo do_shortcode( '[tm_woo_wishlist_table]' );
}
add_action( 'woocommerce_account_wishlist-ba_endpoint', 'bbloomer_wishlist_ba_content' );
/*Allow customers to login with their email address or username */
add_filter('authenticate', 'internet_allow_email_login', 20, 3);
/**
* internet_allow_email_login filter to the authenticate filter hook, to fetch a username based on entered email
* @param obj $user
* @param string $username [description]
* @param string $password [description]
* @return boolean
*/
function internet_allow_email_login( $user, $username, $password ) {
if ( is_email( $username ) ) {
$user = get_user_by_email( $username );
if ( $user ) $username = $user->user_login;
}
return wp_authenticate_username_password( null, $username, $password );
}
/*Ajax login*/
function ajax_login_init(){
wp_register_script('ajax-login-script', get_template_directory_uri() . '/ajax-login-script.js', array('jquery'), false, true );
wp_enqueue_script('ajax-login-script');
wp_localize_script( 'ajax-login-script', 'ajax_login_object', array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'redirecturl' => get_permalink(''),
'loadingmessage' => __('Sending user info, please wait...')
));
// Enable the user with no privileges to run ajax_login() in AJAX
add_action( 'wp_ajax_nopriv_ajaxlogin', 'ajax_login' );
}
// Execute the action only if the user isn't logged in
if (!is_user_logged_in()) {
add_action('init', 'ajax_login_init');
}
function ajax_login(){
// First check the nonce, if it fails the function will break
check_ajax_referer( 'ajax-login-nonce', 'security' );
// Nonce is checked, get the POST data and sign user on
$info = array();
$info['user_login'] = $_POST['username'];
$info['user_password'] = $_POST['password'];
$info['remember'] = true;
$user_signon = wp_signon( $info, false );
if ( is_wp_error($user_signon) ){
echo json_encode(array('loggedin'=>false, 'message'=>__('Wrong username or password.')));
} else {
echo json_encode(array('loggedin'=>true, 'message'=>__('Login successful, redirecting...')));
}
die();
}
/**
* Modify the "must_log_in" string of the comment form.
*
* @see http://wordpress.stackexchange.com/a/170492/26350
*/
add_filter( 'comment_form_defaults', function( $fields ) {
$fields['must_log_in'] = sprintf(
__( '<p class="must-log-in">
You must <a href="/my-account/">Register</a> or
<a data-toggle="modal" data-target="#loginmodal" href="#">Login</a> to post a comment.</p>'
),
wp_registration_url(),
wp_login_url( apply_filters( 'the_permalink', get_permalink() ) )
);
return $fields;
});
function wc_bypass_logout_confirmation() {
global $wp;
if ( isset( $wp->query_vars['customer-logout'] ) ) {
wp_redirect( str_replace( '&', '&', wp_logout_url( wc_get_page_permalink( 'myaccount' ) ) ) );
exit;
}
}
add_action( 'template_redirect', 'wc_bypass_logout_confirmation' );
/*cm to inch calculater*/
add_action( 'woocommerce_product_meta_end', 'add_content_after_addtocart_button_func' );
/*
* Content below "Add to cart" Button.
*/
function add_content_after_addtocart_button_func() {
global $post;
if ( has_term( 'canvas', 'product_cat', $post->ID ) ) {
// Echo content.
echo '<div class="calculate-cm">
<h3>cm to Inches Converter</h3>
<div class="col-sm-6">
<label>cm</label>
<input id="inputcm2" class="inputcm2" type="number" placeholder="CM" oninput="LengthConverter2(this.value)" onchange="LengthConverter2(this.value)">
<div class="convert"><span id="outputInches2"></span> <span class="small">(Inch)</span></div>
</div>
<div class="col-sm-6">
<label>cm</label>
<input id="inputcm" class="inputcm" type="number" placeholder="CM" oninput="LengthConverter(this.value)" onchange="LengthConverter(this.value)">
<div class="convert"><span id="outputInches"></span> <span class="small">(Inch)</span></div>
</div>
</div>';
}
}
/* Compare size lightbox */
add_action( 'woocommerce_after_add_to_cart_form', 'add_comparisons_after_addtocart_button_func' );
/*
* Content below "Add to cart" Button.
*/
function add_comparisons_after_addtocart_button_func() {
global $post;
if ( has_term( 'canvas', 'product_cat', $post->ID ) ) {
// Echo content.
echo '<button type="button" data-toggle="modal" data-target="#comparisons" class="button btn btn-default compare-size">
<span class="text">Size comparisons</span></button>';
}
}
add_action( 'woocommerce_after_add_to_cart_form', 'add_wishlist_after_addtocart_button_func' );
/*
* Content below "Add to cart" Button.
*/
function add_wishlist_after_addtocart_button_func() {
global $post;
// Echo content.
echo do_shortcode('[ti_wishlists_addtowishlist product_id="'.get_the_ID().'"]');
}
/* Inser coupon code into single product
add_action( 'woocommerce_product_meta_end', 'add_content_after_addtocart_button_unlock' );
/*
* Content below "Add to cart" Button.
function add_content_after_addtocart_button_unlock() {
$options = get_option('futurewave_theme_options'); echo do_shortcode('
[sociallocker]
<div class="outer-couponcode"><div class="inner-couponcode">
<h4>Thank you! Here is your Couponcode!</h4>
<div class="couponcode">'.$options['couponcode'].'</div></div></div>
[/sociallocker]');
}*/
/**
* Filter the except length to 20 words.
*
* @param int $length Excerpt length.
* @return int (Maybe) modified excerpt length.
*/
function wpdocs_custom_excerpt_length( $length ) {
return 35;
}
add_filter( 'excerpt_length', 'wpdocs_custom_excerpt_length', 999 );
function misha_my_load_more_scripts() {
global $wp_query;
// In most cases it is already included on the page and this line can be removed
wp_enqueue_script('jquery');
// register our main script but do not enqueue it yet
wp_register_script( 'my_loadmore', get_stylesheet_directory_uri() . '/myloadmore.js', array('jquery') );
// now the most interesting part
// we have to pass parameters to myloadmore.js script but we can get the parameters values only in PHP
// you can define variables directly in your HTML but I decided that the most proper way is wp_localize_script()
wp_localize_script( 'my_loadmore', 'misha_loadmore_params', array(
'ajaxurl' => site_url() . '/wp-admin/admin-ajax.php', // WordPress AJAX
'posts' => serialize( $wp_query->query_vars ), // everything about your loop is here
'current_page' => get_query_var( 'paged' ) ? get_query_var('paged') : 1,
'max_page' => $wp_query->max_num_pages
) );
wp_enqueue_script( 'my_loadmore' );
}
add_action( 'wp_enqueue_scripts', 'misha_my_load_more_scripts' );
function misha_loadmore_ajax_handler(){
// prepare our arguments for the query
$args = unserialize( stripslashes( $_POST['query'] ) );
$args['paged'] = $_POST['page'] + 1; // we need next page to be loaded
$args['post_status'] = 'publish';
// it is always better to use WP_Query but not here
query_posts( $args );
if( have_posts() ) :
// run the loop
while( have_posts() ): the_post();
// look into your theme code how the posts are inserted, but you can use your own HTML of course
// do you remember? - my example is adapted for Twenty Seventeen theme
get_template_part('templates/content', get_post_type() != 'post' ? get_post_type() : get_post_format());
// for the test purposes comment the line above and uncomment the below one
// the_title();
endwhile;
endif;
die; // here we exit the script and even no wp_reset_query() required!
}
add_action('wp_ajax_loadmore', 'misha_loadmore_ajax_handler'); // wp_ajax_{action}
add_action('wp_ajax_nopriv_loadmore', 'misha_loadmore_ajax_handler'); // wp_ajax_nopriv_{action}
add_filter( 'woocommerce_email_styles', 'patricks_woocommerce_email_styles' );
function patricks_woocommerce_email_styles( $css ) {
$css .= "
#wrapper{ background: #fff;}
#template_header {
background: #2b2b2b url(https://d1zczzapudl1mr.cloudfront.net/gk-pattern-white.png) 50% repeat;
}
ul.top-menu {
display:block;
}
ul.top-menu li {
display:inline-block;
}
ul.top-menu li a {
color:#0f0f0f;
font-weight:600;
text-decoration:none;
font-size:0.9em;
font-family:sans-serif;
padding:10px
}
#credit{
padding: 48px;
}
#body_content_inner{
font-size: 14px;
line-height: 180%!important;
text-align: left;
}
#template_footer{
background: #2b2b2b url(https://d1zczzapudl1mr.cloudfront.net/gk-pattern-white.png) 50% repeat;
padding-top: 45px;
}
#header_wrapper{
padding: 36px 48px;
display: block;
}
#header_wrapper h1{
color: #ffffff;
font-size: 22px!important;
font-weight: 300!important;
line-height: 150%!important;
margin: 0!important;
text-align: center!important;
}
";
return $css;
}
/* ------------------------------------------------------------------------ *
* Setting Registration
* ------------------------------------------------------------------------ */
add_action( 'admin_init', 'theme_options_init' );
add_action( 'admin_menu', 'theme_options_add_page' );
/**
* Init plugin options to white list our options
*/
function theme_options_init(){
register_setting( 'futurewave_options', 'futurewave_theme_options', 'theme_options_validate' );
}
/**
* Load up the menu page
*/
function theme_options_add_page() {
add_theme_page( __( 'Theme Options', 'futurewavetheme' ), __( 'Theme Options', 'futurewavetheme' ), 'edit_theme_options', 'theme_options', 'theme_options_do_page' );
}
/**
* Create the options page
*/
function theme_options_do_page() {
global $select_options, $radio_options;
if ( ! isset( $_REQUEST['settings-updated'] ) )
$_REQUEST['settings-updated'] = false;
?>
<div class="wrap">
<?php screen_icon(); echo "<h2>" . get_current_theme() . __( ' Theme Options', 'futurewavetheme' ) . "</h2>"; ?>
<?php if ( false !== $_REQUEST['settings-updated'] ) : ?>
<div class="updated fade"><p><strong><?php _e( 'Options saved', 'futurewavetheme' ); ?></strong></p></div>
<?php endif; ?>
<form method="post" action="options.php">
<?php settings_fields( 'futurewave_options' ); ?>
<?php $options = get_option( 'futurewave_theme_options' ); ?>
<table class="form-table">
<?php
/**
* A futurewave text input option
*/
?>
<tr valign="top"><th scope="row"><?php _e( 'SocialLocker Content Product page (couponCode)', 'futurewavetheme' ); ?></th>
<td>
<input id="futurewave_theme_options[couponcode]" class="regular-text" type="text" name="futurewave_theme_options[couponcode]" value="<?php esc_attr_e( $options['couponcode'] ); ?>" />
<label class="description" for="futurewave_theme_options[couponcode]"><?php _e( 'SocialLocker Content Product page (couponCode)', 'futurewavetheme' ); ?></label>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e( 'Phone number', 'futurewavetheme' ); ?></th>
<td>
<input id="futurewave_theme_options[phone]" class="regular-text" type="text" name="futurewave_theme_options[phone]" value="<?php esc_attr_e( $options['phone'] ); ?>" />
<label class="description" for="futurewave_theme_options[phone]"><?php _e( 'phone number', 'futurewavetheme' ); ?></label>
</td>
</tr>
<tr><th scope="row"><?php _e( 'banner inner content title', 'futurewavetheme' ); ?></th>
<td>
<input id="futurewave_theme_options[gktitle]" class="regular-text" type="text" name="futurewave_theme_options[gktitle]" value="<?php esc_attr_e( $options['gktitle'] ); ?>" />
<label class="description" for="futurewave_theme_options[gktitle]"><?php _e( 'banner inner content title', 'futurewavetheme' ); ?></label>
</td>
</tr>
<tr><th scope="row"><?php _e( 'banner inner content', 'futurewavetheme' ); ?></th>
<td>
<textarea id="futurewave_theme_options[gkcontent]" class="large-text" cols="50" rows="10" name="futurewave_theme_options[gkcontent]">
<?php echo esc_html( $options['gkcontent'] ); ?></textarea>
<label class="description" for="futurewave_theme_options[gkcontent]"><?php _e( 'futurewave text box', 'futurewavetheme' ); ?></label>
</td>
</tr>
<tr><th scope="row"><?php _e( 'LinkedIn Link', 'futurewavetheme' ); ?></th>
<td>
<input id="futurewave_theme_options[linkedin]" class="regular-text" type="text" name="futurewave_theme_options[linkedin]" value="<?php esc_attr_e( $options['linkedin'] ); ?>" />
<label class="description" for="futurewave_theme_options[linkedin]"><?php _e( 'LinkedIn Link', 'futurewavetheme' ); ?></label>
</td>
</tr>
<tr><th scope="row"><?php _e( 'Pinterest Link', 'futurewavetheme' ); ?></th>
<td>