-
Notifications
You must be signed in to change notification settings - Fork 16
/
wcapf.php
executable file
·928 lines (801 loc) · 23.9 KB
/
wcapf.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
<?php
/**
* Plugin Name: WC Ajax Product Filter
* Description: A plugin to filter woocommerce products with AJAX request.
* Version: 2.0
* Author: Shamim Al Mamun
* Author URI: https://github.com/shamimmoeen
* Text Domain: wcapf
* Domain Path: /languages
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License version 2, as published by the Free Software Foundation. You may NOT assume
* that you can use any other version of the GPL.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* @since 1.0
* @copyright Copyright (c) 2015, Shamim Al Mamun
* @author Shamim Al Mamun
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
// Exit if accessed directly
if (!defined('ABSPATH')) {
exit;
}
/**
* WCAPF main class
*/
if (!class_exists('WCAPF')) {
class WCAPF
{
/**
* Plugin version, used for cache-busting of style and script file references.
*
* @var string
*/
public $version = '1.0';
/**
* Unique identifier for the plugin.
*
* The variable name is used as the text domain when internationalizing strings of text.
*
* @var string
*/
public $plugin_slug;
/**
* A reference to an instance of this class.
*
* @var WCAPF
*/
private static $_instance = null;
/**
* Initialize the plugin.
*/
public function __construct()
{
add_action('plugins_loaded', array($this, 'init'));
}
/**
* Returns an instance of this class.
*
* @return WCAPF
*/
public static function instance()
{
if (!isset(self::$_instance)) {
self::$_instance = new WCAPF();
}
return self::$_instance;
}
/**
* Init this plugin when WordPress Initializes.
*/
public function init()
{
$this->plugin_slug = 'wcapf';
// Grab the translation for the plugin.
add_action('init', array($this, 'loadPluginTextdomain'));
// If woocommerce class exists and woocommerce version is greater than required version.
if (class_exists('woocommerce') && WC()->version >= 2.1) {
$this->defineConstants();
$this->includes();
// plugin action links
add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'pluginActionLinks'));
// plugin settings page
if (is_admin()) {
$this->pluginSettingsPageInit();
}
}
// If woocommerce class exists but woocommerce version is older than required version.
elseif (class_exists('woocommerce')) {
add_action('admin_notices', array($this, 'updateWoocommerce'));
}
// If woocommerce plugin not found.
else {
add_action('admin_notices', array($this, 'needWoocommerce'));
}
}
/**
* Defind constants for this plugin.
*/
public function defineConstants()
{
$this->define('WCAPF_LOCALE', $this->plugin_slug);
$this->define('WCAPF_PATH', $this->pluginPath());
$this->define('WCAPF_ASSETS_PATH', $this->assetsPath());
$this->define('WCAPF_CACHE_TIME', 60*60*12);
}
/**
* Include required core files.
*/
public function includes()
{
require_once 'includes/functions.php';
require_once 'includes/hooks.php';
require_once 'widgets/widget-category-filter.php';
require_once 'widgets/widget-attribute-filter.php';
require_once 'widgets/widget-price-filter.php';
require_once 'widgets/widget-active-filter.php';
}
/**
* Define constants if not already defined.
*
* @param string $name
* @param string|bool $value
*/
public function define($name, $value)
{
if (!defined($name)) {
define($name, $value);
}
}
/**
* Register and enqueue frontend scripts.
*
* @return mixed
*/
public function frontendScripts()
{
wp_register_style('wcapf-style', WCAPF_ASSETS_PATH . 'css/wcapf-styles.css');
wp_register_style('font-awesome', WCAPF_ASSETS_PATH . 'css/font-awesome.min.css');
wp_register_script('wcapf-script', WCAPF_ASSETS_PATH . 'js/scripts.js', array('jquery'), '20120206', true);
wp_localize_script('wcapf-script', 'wcapf_price_filter_params', array(
'currency_symbol' => get_woocommerce_currency_symbol(),
'currency_pos' => get_option('woocommerce_currency_pos')
));
if ($settings = get_option('wcapf_settings')) {
wp_localize_script('wcapf-script', 'wcapf_params', $settings);
}
wp_register_style('wcapf-nouislider-style', WCAPF_ASSETS_PATH . 'css/nouislider.min.css');
wp_register_script('wcapf-nouislider-script', WCAPF_ASSETS_PATH . 'js/nouislider.min.js', array ('jquery'), '1.0', true);
wp_register_script('wcapf-price-filter-script', WCAPF_ASSETS_PATH . 'js/price-filter.js', array ('jquery'), '1.0', true);
wp_register_style('wcapf-select2', WCAPF_ASSETS_PATH . 'css/select2.css');
wp_register_script('wcapf-select2', WCAPF_ASSETS_PATH . 'js/select2.min.js', array ('jquery'), '1.0', true);
}
/**
* Get plugin settings.
*/
public function pluginSettingsPageInit()
{
add_action('admin_menu', array($this, 'adminMenu'));
add_action('admin_init', array($this, 'registerSettings'));
add_action('admin_init', array($this, 'saveDefultSettings'));
}
/**
* Register admin menu.
*/
public function adminMenu()
{
add_options_page(__('WC Ajax Product Filter', $this->plugin_slug), __('WC Ajax Product Filter', $this->plugin_slug), 'manage_options', 'wcapf-settings', array($this, 'settingsPage'));
}
/**
* Render HTML for settings page.
*/
public function settingsPage()
{
require 'includes/settings.php';
}
/**
* Default settings for this plugin.
*
* @return array
*/
public function defaultSettings()
{
return array(
'shop_loop_container' => '.wcapf-before-products',
'not_found_container' => '.wcapf-before-products',
'pagination_container' => '.woocommerce-pagination',
'overlay_bg_color' => '#fff',
'sorting_control' => '1',
'scroll_to_top' => '1',
'scroll_to_top_offset' => '100',
'custom_scripts' => ''
);
}
/**
* Register settings.
*/
public function registerSettings()
{
register_setting('wcapf_settings', 'wcapf_settings', array($this, 'validateSettings'));
}
/**
* If settings are not found then save it.
*/
public function saveDefultSettings()
{
if (!get_option('wcapf_settings')) {
// check if filter is applied
$settings = apply_filters('wcapf_settings', $this->defaultSettings());
update_option('wcapf_settings', $settings);
}
}
/**
* Check for if filter is applied.
*
* @param array $input
* @return array
*/
public function validateSettings($input)
{
if (has_filter('wcapf_settings')) {
$input = apply_filters('wcapf_settings', $input);
}
return $input;
}
/**
* Get chosen filters.
*
* @return array
*/
public function getChosenFilters()
{
// parse url
$url = $_SERVER['QUERY_STRING'];
parse_str($url, $query);
$chosen = array();
$term_ancestors = array();
$active_filters = array();
// keyword
if (isset($_GET['keyword'])) {
$keyword = (!empty($_GET['keyword'])) ? $_GET['keyword'] : '';
$active_filters['keyword'] = $keyword;
}
// orderby
if (isset($_GET['orderby'])) {
$orderby = (!empty($_GET['orderby'])) ? $_GET['orderby'] : '';
$active_filters['orderby'] = $orderby;
}
foreach ($query as $key => $value) {
// attribute
if (preg_match('/^attr/', $key) && !empty($query[$key])) {
$terms = explode(',', $value);
$new_key = str_replace(array('attra-', 'attro-'), '', $key);
$taxonomy = 'pa_' . $new_key;
if (preg_match('/^attra/', $key)) {
$query_type = 'and';
} else {
$query_type = 'or';
}
$chosen[$taxonomy] = array(
'terms' => $terms,
'query_type' => $query_type
);
foreach ($terms as $term_id) {
$ancestors = wcapf_get_term_ancestors($term_id, $taxonomy);
$term_data = wcapf_get_term_data($term_id, $taxonomy);
$term_ancestors[$key][] = $ancestors;
$active_filters['term'][$key][$term_id] = $term_data->name;
}
}
// category
if (preg_match('/product-cat/', $key) && !empty($query[$key])) {
$terms = explode(',', $value);
$taxonomy = 'product_cat';
if (preg_match('/^product-cata/', $key)) {
$query_type = 'and';
} else {
$query_type = 'or';
}
$chosen[$taxonomy] = array(
'terms' => $terms,
'query_type' => $query_type
);
foreach ($terms as $term_id) {
$ancestors = wcapf_get_term_ancestors($term_id, $taxonomy);
$term_data = wcapf_get_term_data($term_id, $taxonomy);
$term_ancestors[$key][] = $ancestors;
$active_filters['term'][$key][$term_id] = $term_data->name;
}
}
}
// min-price
if (isset($_GET['min-price'])) {
$active_filters['min_price'] = $_GET['min-price'];
}
// max-price
if (isset($_GET['max-price'])) {
$active_filters['max_price'] = $_GET['max-price'];
}
return array(
'chosen' => $chosen,
'term_ancestors' => $term_ancestors,
'active_filters' => $active_filters
);
}
/**
* Filtered product ids for given terms.
*
* @return array
*/
public function filteredProductIdsForTerms()
{
$chosen_filters = $this->getChosenFilters();
$chosen_filters = $chosen_filters['chosen'];
$results = array();
// 99% copy of WC_Query
if (sizeof($chosen_filters) > 0) {
$matched_products = array(
'and' => array(),
'or' => array()
);
$filtered_attribute = array(
'and' => false,
'or' => false
);
foreach ($chosen_filters as $attribute => $data) {
$matched_products_from_attribute = array();
$filtered = false;
if (sizeof($data['terms']) > 0) {
foreach ($data['terms'] as $value) {
$posts = get_posts(
array(
'post_type' => 'product',
'numberposts' => -1,
'post_status' => 'publish',
'fields' => 'ids',
'no_found_rows' => true,
'tax_query' => array(
array(
'taxonomy' => $attribute,
'terms' => $value,
'field' => 'term_id'
)
)
)
);
if (!is_wp_error($posts)) {
if (sizeof($matched_products_from_attribute) > 0 || $filtered) {
$matched_products_from_attribute = ($data['query_type'] === 'or') ? array_merge($posts, $matched_products_from_attribute) : array_intersect($posts, $matched_products_from_attribute);
} else {
$matched_products_from_attribute = $posts;
}
$filtered = true;
}
}
}
if (sizeof($matched_products[$data['query_type']]) > 0 || $filtered_attribute[$data['query_type']] === true) {
$matched_products[$data['query_type']] = ($data['query_type'] === 'or') ? array_merge($matched_products_from_attribute, $matched_products[$data['query_type']]) : array_intersect($matched_products_from_attribute, $matched_products[$data['query_type']]);
} else {
$matched_products[$data['query_type']] = $matched_products_from_attribute;
}
$filtered_attribute[$data['query_type']] = true;
}
// combine our AND and OR result sets
if ($filtered_attribute['and'] && $filtered_attribute['or']) {
$results = array_intersect($matched_products['and'], $matched_products['or']);
$results[] = 0;
} else {
$results = array_merge($matched_products['and'], $matched_products['or']);
$results[] = 0;
}
}
return $results;
}
/**
* Query for meta that should be set to the main query.
*
* @return array
*/
public function queryForMeta()
{
$meta_query = array();
// rating filter
if (isset($_GET['min_rating'])) {
$meta_query[] = array(
'key' => '_wc_average_rating',
'value' => isset($_GET['min_rating']) ? floatval($_GET['min_rating']) : 0,
'compare' => '>=',
'type' => 'DECIMAL',
'rating_filter' => true,
);
}
// price range for all published products
$unfiltered_price_range = $this->getPriceRange(false);
if (isset($_GET['min-price']) || isset($_GET['max-price'])) {
if (sizeof($unfiltered_price_range) === 2) {
$min = (!empty($_GET['min-price'])) ? (int)$_GET['min-price'] : '';
$max = (!empty($_GET['max-price'])) ? (int)$_GET['max-price'] : '';
$min = (!empty($min)) ? $min : (int)$unfiltered_price_range[0];
$max = (!empty($max)) ? $max : (int)$unfiltered_price_range[1];
// if tax enabled
if (wc_tax_enabled() && 'incl' === get_option('woocommerce_tax_display_shop') && ! wc_prices_include_tax()) {
$tax_classes = array_merge(array( ''), WC_Tax::get_tax_classes());
foreach ($tax_classes as $tax_class) {
$tax_rates = WC_Tax::get_rates($tax_class);
$class_min = $min - WC_Tax::get_tax_total(WC_Tax::calc_exclusive_tax($min, $tax_rates));
$class_max = $max - WC_Tax::get_tax_total(WC_Tax::calc_exclusive_tax($max, $tax_rates));
$min = $max = false;
if ($min === false || $min > (int)$class_min) {
$min = floor($class_min);
}
if ($max === false || $max < (int)$class_max) {
$max = ceil($class_max);
}
}
}
// if WooCommerce Currency Switcher plugin is activated
if (class_exists('WOOCS')) {
$woocs = new WOOCS();
$chosen_currency = $woocs->get_woocommerce_currency();
$currencies = $woocs->get_currencies();
if (sizeof($currencies) > 0) {
foreach ($currencies as $currency) {
if ($currency['name'] == $chosen_currency) {
$rate = $currency['rate'];
}
}
$min = floor($min / $rate);
$max = ceil($max / $rate);
}
}
$meta_query[] = array(
'key' => '_price',
'value' => array($min, $max),
'type' => 'numeric',
'compare' => 'BETWEEN',
'price_filter' => true,
);
}
}
return $meta_query;
}
/**
* Set filter.
*
* @param wp_query $q
*/
public function setFilter($q)
{
// check for if we are on main query and product archive page
if (!is_main_query() && !is_post_type_archive('product') && !is_tax(get_object_taxonomies('product'))) {
return;
}
$search_results = $this->productIdsForGivenKeyword();
$taxono_results = $this->filteredProductIdsForTerms();
if (sizeof($search_results) > 0 && sizeof($taxono_results) > 0) {
$post__in = array_intersect($search_results, $taxono_results);
} elseif (sizeof($search_results) > 0 && sizeof($taxono_results) === 0) {
$post__in = $search_results;
} else {
$post__in = $taxono_results;
}
$q->set('meta_query', $this->queryForMeta());
$q->set('post__in', $post__in);
return;
}
/**
* Retrive Product ids for given keyword.
*
* @return array
*/
public function productIdsForGivenKeyword()
{
if (isset($_GET['keyword']) && !empty($_GET['keyword'])) {
$keyword = $_GET['keyword'];
$args = array(
's' => $keyword,
'post_type' => 'product',
'post_status' => 'publish',
'numberposts' => -1,
'fields' => 'ids'
);
$results = get_posts($args);
$results[] = 0;
} else {
$results = array();
}
return $results;
}
/**
* Get the unfiltered product ids.
*
* @return array
*/
public function unfilteredProductIds()
{
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'numberposts' => -1,
'fields' => 'ids'
);
// get unfiltered products using transients
$transient_name = 'wcapf_unfiltered_product_ids';
if (false === ($unfiltered_product_ids = get_transient($transient_name))) {
$unfiltered_product_ids = get_posts($args);
set_transient($transient_name, $unfiltered_product_ids, WCAPF_CACHE_TIME);
}
return $unfiltered_product_ids;
}
/**
* Get filtered product ids.
*
* @return array
*/
public function filteredProductIds()
{
global $wp_query;
$current_query = $wp_query;
if (!is_object($current_query) && !is_main_query() && !is_post_type_archive('product') && !is_tax(get_object_taxonomies('product'))) {
return;
}
$modified_query = $current_query->query;
unset($modified_query['paged']);
$meta_query = (key_exists('meta_query', $current_query->query_vars)) ? $current_query->query_vars['meta_query'] : array();
$tax_query = (key_exists('tax_query', $current_query->query_vars)) ? $current_query->query_vars['tax_query'] : array();
$post__in = (key_exists('post__in', $current_query->query_vars)) ? $current_query->query_vars['post__in'] : array();
$filtered_product_ids = get_posts(
array_merge(
$modified_query,
array(
'post_type' => 'product',
'numberposts' => -1,
'post_status' => 'publish',
'post__in' => $post__in,
'meta_query' => $meta_query,
'tax_query' => $tax_query,
'fields' => 'ids',
'no_found_rows' => true,
'update_post_meta_cache' => false,
'update_post_term_cache' => false,
'pagename' => '',
)
)
);
return $filtered_product_ids;
}
/**
* Find Prices for given products.
*
* @param array $products
* @return array
*/
public function findPriceRange($products)
{
$price_range = array();
foreach ($products as $id) {
$meta_value = get_post_meta($id, '_price', true);
if ($meta_value) {
$price_range[] = $meta_value;
}
// for child posts
$product_variation = get_children(
array(
'post_type' => 'product_variation',
'post_parent' => $id,
'numberposts' => -1
)
);
if (sizeof($product_variation) > 0) {
foreach ($product_variation as $variation) {
$meta_value = get_post_meta($variation->ID, '_price', true);
if ($meta_value) {
$price_range[] = $meta_value;
}
}
}
}
$price_range = array_unique($price_range);
return $price_range;
}
/**
* Find price range for filtered products.
*
* @return array
*/
public function filteredProductsPriceRange()
{
$products = $this->filteredProductIds();
if (sizeof($products) < 1) {
return;
}
$filtered_products_price_range = $this->findPriceRange($products);
return $filtered_products_price_range;
}
/**
* Find price range for unfiltered products.
*
* @return array
*/
public function unfilteredProductsPriceRange()
{
$products = $this->unfilteredProductIds();
if (sizeof($products) < 1) {
return;
}
// get unfiltered products price range using transients
$transient_name = 'wcapf_unfiltered_product_price_range';
if (false === ($unfiltered_products_price_range = get_transient($transient_name))) {
$unfiltered_products_price_range = $this->findPriceRange($products);
set_transient($transient_name, $unfiltered_products_price_range, WCAPF_CACHE_TIME);
}
return $unfiltered_products_price_range;
}
/**
* Get Price Range for given product ids.
* If filtered is true then return price range for filtered products,
* otherwise return price range for all products.
*
* @param boolean $filtered
* @return array
*/
public function getPriceRange($filtered = true)
{
if ($filtered === true) {
$price_range = $this->filteredProductsPriceRange();
} else {
$price_range = $this->unfilteredProductsPriceRange();
}
if (sizeof($price_range) > 2) {
$min = $max = false;
foreach ($price_range as $price) {
if ($min === false || $min > (int)$price) {
$min = floor($price);
}
if ($max === false || $max < (int)$price) {
$max = ceil($price);
}
}
// if tax enabled and shop page shows price including tax
if (wc_tax_enabled() && 'incl' === get_option('woocommerce_tax_display_shop') && ! wc_prices_include_tax()) {
$tax_classes = array_merge(array( ''), WC_Tax::get_tax_classes());
foreach ($tax_classes as $tax_class) {
$tax_rates = WC_Tax::get_rates($tax_class);
$class_min = $min + WC_Tax::get_tax_total(WC_Tax::calc_exclusive_tax($min, $tax_rates));
$class_max = $max + WC_Tax::get_tax_total(WC_Tax::calc_exclusive_tax($max, $tax_rates));
$min = $max = false;
if ($min === false || $min > (int)$class_min) {
$min = floor($class_min);
}
if ($max === false || $max < (int)$class_max) {
$max = ceil($class_max);
}
}
}
// if WooCommerce Currency Switcher plugin is activated
if (class_exists('WOOCS')) {
$woocs = new WOOCS();
$chosen_currency = $woocs->get_woocommerce_currency();
$currencies = $woocs->get_currencies();
if (sizeof($currencies) > 0) {
foreach ($currencies as $currency) {
if ($currency['name'] == $chosen_currency) {
$rate = $currency['rate'];
}
}
$min = floor($min * $rate);
$max = ceil($max * $rate);
}
}
if ($min == $max) {
// empty array
return array();
} else {
// array with min and max values
return array($min, $max);
}
} else {
// empty array
return array();
}
}
/**
* HTML wrapper to insert before the shop loop.
*
* @return string
*/
public static function beforeProductsHolder()
{
echo '<div class="wcapf-before-products">';
}
/**
* HTML wrapper to insert after the shop loop.
*
* @return string
*/
public static function afterProductsHolder()
{
echo '</div>';
}
/**
* HTML wrapper to insert before the not found product loops.
*
* @param string $template_name
* @param string $template_path
* @param string $located
* @return string
*/
public static function beforeNoProducts($template_name = '', $template_path = '', $located = '') {
if ($template_name == 'loop/no-products-found.php') {
echo '<div class="wcapf-before-products">';
}
}
/**
* HTML wrapper to insert after the not found product loops.
*
* @param string $template_name
* @param string $template_path
* @param string $located
* @return string
*/
public static function afterNoProducts($template_name = '', $template_path = '', $located = '') {
if ($template_name == 'loop/no-products-found.php') {
echo '</div>';
}
}
/**
* Decode pagination links.
*
* @param string $link
*
* @return string
*/
public static function paginateLinks($link)
{
$link = urldecode($link);
return $link;
}
/**
* Load the plugin text domain for translation.
*/
public function loadPluginTextdomain()
{
load_plugin_textdomain('wcapf', FALSE, basename(dirname(__FILE__)) . '/languages/');
}
/**
* Get the plugin Path.
*
* @return string
*/
public function pluginPath()
{
return untrailingslashit(plugin_dir_url(__FILE__));
}
/**
* Get the plugin assets path.
*
* @return string
*/
public function assetsPath()
{
return trailingslashit(plugin_dir_url(__FILE__) . 'assets/');
}
/**
* Show admin notice if woocommerce plugin not found.
*/
public function needWoocommerce()
{
echo '<div class="error">';
echo '<p>' . __('WC Ajax Product Filter needs WooCommerce plguin to work.', $this->plugin_slug) . '</p>';
echo '</div>';
}
/**
* Show admin notice if woocommerce plugin version is older than required version.
*/
public function updateWoocommerce()
{
echo '<div class="error">';
echo '<p>' . __('To use WC Ajax Product Filter update your WooCommerce plugin.', $this->plugin_slug) . '</p>';
echo '</div>';
}
/**
* Show action links on the plugins page.
*
* @param array $links
* @return array
*/
public function pluginActionLinks($links)
{
$links[] = '<a href="' . admin_url('options-general.php?page=wcapf-settings') . '">' . __('Settings', $this->plugin_slug) . '</a>';
return $links;
}
}
}
/**
* Instantiate this class globally.
*/
$GLOBALS['wcapf'] = WCAPF::instance();