1 | <?php |
||||
2 | /** |
||||
3 | * LSX Search FacetWP filters and actions |
||||
4 | * |
||||
5 | * @package lsx-search |
||||
6 | */ |
||||
7 | class LSX_Search_FacetWP { |
||||
8 | |||||
9 | /** |
||||
10 | * @var object \lsx\search\classes\facetwp\Hierarchy() |
||||
11 | */ |
||||
12 | public $hierarchy; |
||||
13 | |||||
14 | /** |
||||
15 | * @var object \lsx\search\classes\facetwp\Post_Connections() |
||||
16 | */ |
||||
17 | public $post_connections; |
||||
18 | |||||
19 | /** |
||||
20 | * Class Constructor. |
||||
21 | */ |
||||
22 | public function __construct() { |
||||
23 | |||||
24 | require_once LSX_SEARCH_PATH . '/classes/facetwp/class-hierarchy.php'; |
||||
25 | $this->hierarchy = lsx\search\classes\facetwp\Hierarchy::get_instance(); |
||||
26 | |||||
27 | require_once LSX_SEARCH_PATH . '/classes/facetwp/class-post-connections.php'; |
||||
28 | $this->post_connections = lsx\search\classes\facetwp\Post_Connections::get_instance(); |
||||
29 | |||||
30 | add_filter( 'facetwp_pager_html', array( $this, 'facetwp_pager_html' ), 10, 2 ); |
||||
31 | add_filter( 'facetwp_result_count', array( $this, 'facetwp_result_count' ), 10, 2 ); |
||||
32 | add_filter( 'facetwp_facet_html', array( $this, 'facetwp_slide_html' ), 10, 2 ); |
||||
33 | add_filter( 'facetwp_load_css', array( $this, 'facetwp_load_css' ), 10, 1 ); |
||||
34 | add_filter( 'facetwp_index_row', array( $this, 'index_row' ), 10, 2 ); |
||||
35 | } |
||||
36 | |||||
37 | /** |
||||
38 | * Change FaceWP pagination HTML to be equal LSX pagination. |
||||
39 | */ |
||||
40 | public function facetwp_pager_html( $output, $params ) { |
||||
41 | $output = ''; |
||||
42 | $page = (int) $params['page']; |
||||
43 | $per_page = (int) $params['per_page']; |
||||
44 | $total_pages = (int) $params['total_pages']; |
||||
45 | |||||
46 | if ( 1 < $total_pages ) { |
||||
47 | $output .= '<div class="lsx-pagination-wrapper facetwp-custom">'; |
||||
48 | $output .= '<div class="lsx-pagination">'; |
||||
49 | // $output .= '<span class="pages">Page '. $page .' of '. $total_pages .'</span>'; |
||||
50 | |||||
51 | if ( 1 < $page ) { |
||||
52 | $output .= '<a class="prev page-numbers facetwp-page" rel="prev" data-page="' . ( $page - 1 ) . '">«</a>'; |
||||
53 | } |
||||
54 | |||||
55 | $temp = false; |
||||
56 | |||||
57 | for ( $i = 1; $i <= $total_pages; $i++ ) { |
||||
58 | if ( $i == $page ) { |
||||
59 | $output .= '<span class="page-numbers current">' . $i . '</span>'; |
||||
60 | } elseif ( ( $page - 2 ) < $i && ( $page + 2 ) > $i ) { |
||||
61 | $output .= '<a class="page-numbers facetwp-page" data-page="' . $i . '">' . $i . '</a>'; |
||||
62 | } elseif ( ( $page - 2 ) >= $i && $page > 2 ) { |
||||
63 | if ( ! $temp ) { |
||||
64 | $output .= '<span class="page-numbers dots">...</span>'; |
||||
65 | $temp = true; |
||||
66 | } |
||||
67 | } elseif ( ( $page + 2 ) <= $i && ( $page + 2 ) <= $total_pages ) { |
||||
68 | $output .= '<span class="page-numbers dots">...</span>'; |
||||
69 | break; |
||||
70 | } |
||||
71 | } |
||||
72 | |||||
73 | if ( $page < $total_pages ) { |
||||
74 | $output .= '<a class="next page-numbers facetwp-page" rel="next" data-page="' . ( $page + 1 ) . '">»</a>'; |
||||
75 | } |
||||
76 | |||||
77 | $output .= '</div>'; |
||||
78 | $output .= '</div>'; |
||||
79 | } |
||||
80 | |||||
81 | return $output; |
||||
82 | } |
||||
83 | |||||
84 | /** |
||||
85 | * Change FaceWP result count HTML. |
||||
86 | */ |
||||
87 | public function facetwp_result_count( $output, $params ) { |
||||
88 | $output = $params['total']; |
||||
89 | return $output; |
||||
90 | } |
||||
91 | |||||
92 | /** |
||||
93 | * Change FaceWP slider HTML. |
||||
94 | */ |
||||
95 | public function facetwp_slide_html( $html, $args ) { |
||||
96 | if ( 'slider' === $args['facet']['type'] ) { |
||||
97 | $html = str_replace( 'class="facetwp-slider-reset"', 'class="btn btn-md facetwp-slider-reset"', $html ); |
||||
98 | } |
||||
99 | |||||
100 | return $html; |
||||
101 | } |
||||
102 | |||||
103 | /** |
||||
104 | * Change FaceWP slider HTML. |
||||
105 | */ |
||||
106 | public function facetwp_counts_html( $html, $args ) { |
||||
107 | if ( 'slider' === $args['facet']['type'] ) { |
||||
108 | $html = str_replace( 'class="facetwp-slider-reset"', 'class="btn btn-md facetwp-slider-reset"', $html ); |
||||
109 | } |
||||
110 | return $html; |
||||
111 | } |
||||
112 | |||||
113 | /** |
||||
114 | * Disable FacetWP styles. |
||||
115 | */ |
||||
116 | public function facetwp_load_css( $boolean ) { |
||||
117 | $boolean = false; |
||||
118 | return $boolean; |
||||
119 | } |
||||
120 | |||||
121 | /** |
||||
122 | * Get the price including the tax |
||||
123 | * @param $params |
||||
124 | * @param $class |
||||
125 | * |
||||
126 | * @return mixed |
||||
127 | */ |
||||
128 | public function index_row( $params, $class ) { |
||||
129 | // Custom woo fields |
||||
130 | if ( 0 === strpos( $params['facet_source'], 'woo' ) ) { |
||||
131 | $product = wc_get_product( $params['post_id'] ); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
132 | |||||
133 | // Price |
||||
134 | if ( in_array( $params['facet_source'], array( 'woo/price', 'woo/sale_price', 'woo/regular_price' ) ) ) { |
||||
135 | $price = $params['facet_value']; |
||||
136 | if ( $product->is_taxable() ) { |
||||
137 | $price = wc_get_price_including_tax( $product ); |
||||
0 ignored issues
–
show
The function
wc_get_price_including_tax was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
138 | } |
||||
139 | $params['facet_value'] = $price; |
||||
140 | $params['facet_display_value'] = $price; |
||||
141 | |||||
142 | } |
||||
143 | } |
||||
144 | return $params; |
||||
145 | } |
||||
146 | |||||
147 | } |
||||
148 |