1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* LSX functions and definitions - WooCommerce. |
4
|
|
|
* |
5
|
|
|
* @package lsx |
6
|
|
|
* @subpackage layout |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
10
|
|
|
exit; |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
if ( ! function_exists( 'lsx_wc_support' ) ) : |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* WooCommerce support. |
17
|
|
|
* |
18
|
|
|
* @package lsx |
19
|
|
|
* @subpackage woocommerce |
20
|
|
|
*/ |
21
|
|
|
function lsx_wc_support() { |
22
|
|
|
add_theme_support( 'woocommerce' ); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
add_action( 'after_setup_theme', 'lsx_wc_support' ); |
26
|
|
|
|
27
|
|
|
endif; |
28
|
|
|
|
29
|
|
|
if ( ! function_exists( 'lsx_wc_scripts_add_styles' ) ) : |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* WooCommerce enqueue styles. |
33
|
|
|
* |
34
|
|
|
* @package lsx |
35
|
|
|
* @subpackage woocommerce |
36
|
|
|
*/ |
37
|
|
|
function lsx_wc_scripts_add_styles() { |
38
|
|
|
wp_enqueue_style( 'woocommerce-lsx', get_template_directory_uri() . '/assets/css/woocommerce.css', array( 'lsx_main' ), LSX_VERSION ); |
39
|
|
|
wp_style_add_data( 'woocommerce-lsx', 'rtl', 'replace' ); |
40
|
|
|
|
41
|
|
|
// Remove select2 added by WooCommerce |
42
|
|
|
|
43
|
|
|
wp_dequeue_style( 'select2' ); |
44
|
|
|
wp_deregister_style( 'select2' ); |
45
|
|
|
|
46
|
|
|
wp_dequeue_script( 'select2' ); |
47
|
|
|
wp_deregister_script( 'select2' ); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
add_action( 'wp_enqueue_scripts', 'lsx_wc_scripts_add_styles' ); |
51
|
|
|
|
52
|
|
|
endif; |
53
|
|
|
|
54
|
|
|
if ( ! function_exists( 'lsx_wc_form_field_args' ) ) : |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* WooCommerce form fields. |
58
|
|
|
* |
59
|
|
|
* @package lsx |
60
|
|
|
* @subpackage woocommerce |
61
|
|
|
*/ |
62
|
|
|
function lsx_wc_form_field_args( $args, $key, $value ) { |
|
|
|
|
63
|
|
|
$args['input_class'][] = 'form-control'; |
64
|
|
|
|
65
|
|
|
return $args; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
add_action( 'woocommerce_form_field_args', 'lsx_wc_form_field_args', 10, 3 ); |
69
|
|
|
|
70
|
|
|
endif; |
71
|
|
|
|
72
|
|
|
if ( ! function_exists( 'lsx_wc_theme_wrapper_start' ) ) : |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* WooCommerce wrapper start. |
76
|
|
|
* |
77
|
|
|
* @package lsx |
78
|
|
|
* @subpackage woocommerce |
79
|
|
|
*/ |
80
|
|
|
function lsx_wc_theme_wrapper_start() { |
81
|
|
|
lsx_content_wrap_before(); |
82
|
|
|
echo '<div id="primary" class="content-area col-sm-12">'; |
83
|
|
|
lsx_content_before(); |
84
|
|
|
echo '<main id="main" class="site-main" role="main">'; |
85
|
|
|
lsx_content_top(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 ); |
89
|
|
|
add_action( 'woocommerce_before_main_content', 'lsx_wc_theme_wrapper_start' ); |
90
|
|
|
|
91
|
|
|
endif; |
92
|
|
|
|
93
|
|
|
if ( ! function_exists( 'lsx_wc_theme_wrapper_end' ) ) : |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* WooCommerce wrapper end. |
97
|
|
|
* |
98
|
|
|
* @package lsx |
99
|
|
|
* @subpackage woocommerce |
100
|
|
|
*/ |
101
|
|
|
function lsx_wc_theme_wrapper_end() { |
102
|
|
|
lsx_content_bottom(); |
103
|
|
|
echo '</div>'; |
104
|
|
|
lsx_content_after(); |
105
|
|
|
echo '</div>'; |
106
|
|
|
lsx_content_wrap_after(); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 ); |
110
|
|
|
add_action( 'woocommerce_after_main_content', 'lsx_wc_theme_wrapper_end' ); |
111
|
|
|
|
112
|
|
|
endif; |
113
|
|
|
|
114
|
|
|
if ( ! function_exists( 'lsx_wc_disable_lsx_banner_plugin' ) ) : |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Disable LSX Banners plugin in some WC pages. |
118
|
|
|
* |
119
|
|
|
* @package lsx |
120
|
|
|
* @subpackage woocommerce |
121
|
|
|
*/ |
122
|
|
|
function lsx_wc_disable_lsx_banner_plugin( $disabled ) { |
123
|
|
|
if ( is_cart() || is_checkout() || is_account_page() ) { |
124
|
|
|
$disabled = true; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
return $disabled; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
add_filter( 'lsx_banner_plugin_disable', 'lsx_wc_disable_lsx_banner_plugin' ); |
131
|
|
|
|
132
|
|
|
endif; |
133
|
|
|
|
134
|
|
|
if ( ! function_exists( 'lsx_wc_disable_lsx_banner' ) ) : |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Disable LSX Banners banner in some WC pages. |
138
|
|
|
* |
139
|
|
|
* @package lsx |
140
|
|
|
* @subpackage woocommerce |
141
|
|
|
*/ |
142
|
|
|
function lsx_wc_disable_lsx_banner( $disabled ) { |
143
|
|
|
if ( is_shop() || is_product_category() || is_product_tag() || is_product() ) { |
144
|
|
|
$disabled = true; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
return $disabled; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
add_filter( 'lsx_banner_disable', 'lsx_wc_disable_lsx_banner' ); |
151
|
|
|
|
152
|
|
|
endif; |
153
|
|
|
|
154
|
|
|
if ( ! function_exists( 'lsx_wc_add_cart' ) ) : |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Adds WC cart to the header. |
158
|
|
|
* |
159
|
|
|
* @package lsx |
160
|
|
|
* @subpackage template-tags |
161
|
|
|
*/ |
162
|
|
|
function lsx_wc_add_cart( $items, $args ) { |
163
|
|
|
if ( 'primary' === $args->theme_location ) { |
164
|
|
|
$customizer_option = get_theme_mod( 'lsx_header_wc_cart', false ); |
165
|
|
|
|
166
|
|
|
if ( ! empty( $customizer_option ) ) { |
167
|
|
|
ob_start(); |
168
|
|
|
the_widget( 'WC_Widget_Cart', 'title=' ); |
169
|
|
|
$widget = ob_get_clean(); |
170
|
|
|
|
171
|
|
|
if ( is_cart() ) { |
172
|
|
|
$class = 'current-menu-item'; |
173
|
|
|
} else { |
174
|
|
|
$class = ''; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
$item = '<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children dropdown lsx-wc-cart-menu-item ' . $class . '">' . |
178
|
|
|
'<a title="' . esc_attr__( 'View your shopping cart', 'lsx' ) . '" href="' . esc_url( wc_get_cart_url() ) . '" data-toggle="dropdown" class="dropdown-toggle" aria-haspopup="true">' . |
179
|
|
|
/* Translators: %s: items quantity */ |
180
|
|
|
'<span class="lsx-wc-cart-amount">' . wp_kses_data( WC()->cart->get_cart_subtotal() ) . '</span> <span class="lsx-wc-cart-count">' . wp_kses_data( sprintf( _n( '%d item', '%d items', WC()->cart->get_cart_contents_count(), 'lsx' ), WC()->cart->get_cart_contents_count() ) ) . '</span>' . |
181
|
|
|
'</a>' . |
182
|
|
|
'<ul role="menu" class=" dropdown-menu lsx-wc-cart-sub-menu">' . |
183
|
|
|
'<li>' . |
184
|
|
|
'<div class="lsx-wc-cart-dropdown">' . $widget . '</div>' . |
185
|
|
|
'</li>' . |
186
|
|
|
'</ul>' . |
187
|
|
|
'</li>'; |
188
|
|
|
|
189
|
|
|
$items .= $item; |
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
return $items; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
add_filter( 'wp_nav_menu_items', 'lsx_wc_add_cart', 10, 2 ); |
197
|
|
|
|
198
|
|
|
endif; |
199
|
|
|
|
200
|
|
|
if ( ! function_exists( 'lsx_wc_products_widget_wrapper_before' ) ) : |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Change WC products widget wrapper (before). |
204
|
|
|
* |
205
|
|
|
* @package lsx |
206
|
|
|
* @subpackage woocommerce |
207
|
|
|
*/ |
208
|
|
|
function lsx_wc_products_widget_wrapper_before( $html ) { |
|
|
|
|
209
|
|
|
$html = '<div class="lsx-woocommerce-slider lsx-woocommerce-shortcode">'; |
210
|
|
|
return $html; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
add_filter( 'woocommerce_before_widget_product_list', 'lsx_wc_products_widget_wrapper_before', 15 ); |
214
|
|
|
|
215
|
|
|
endif; |
216
|
|
|
|
217
|
|
|
if ( ! function_exists( 'lsx_wc_products_widget_wrapper_after' ) ) : |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Change WC products widget wrapper (after). |
221
|
|
|
* |
222
|
|
|
* @package lsx |
223
|
|
|
* @subpackage woocommerce |
224
|
|
|
*/ |
225
|
|
|
function lsx_wc_products_widget_wrapper_after( $html ) { |
|
|
|
|
226
|
|
|
$html = '</div>'; |
227
|
|
|
return $html; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
add_filter( 'woocommerce_after_widget_product_list', 'lsx_wc_products_widget_wrapper_after', 15 ); |
231
|
|
|
|
232
|
|
|
endif; |
233
|
|
|
|
234
|
|
|
if ( ! function_exists( 'lsx_wc_reviews_widget_override' ) ) : |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Override WC ewviews widget. |
238
|
|
|
* |
239
|
|
|
* @package lsx |
240
|
|
|
* @subpackage woocommerce |
241
|
|
|
*/ |
242
|
|
|
function lsx_wc_reviews_widget_override() { |
243
|
|
|
if ( class_exists( 'WC_Widget_Recent_Reviews' ) ) { |
244
|
|
|
unregister_widget( 'WC_Widget_Recent_Reviews' ); |
245
|
|
|
require get_template_directory() . '/includes/classes/class-lsx-wc-widget-recent-reviews.php'; |
246
|
|
|
register_widget( 'LSX_WC_Widget_Recent_Reviews' ); |
247
|
|
|
} |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
add_action( 'widgets_init', 'lsx_wc_reviews_widget_override', 15 ); |
251
|
|
|
|
252
|
|
|
endif; |
253
|
|
|
|
254
|
|
|
if ( ! function_exists( 'lsx_wc_change_price_html' ) ) : |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* Change WC ZERO price to "free". |
258
|
|
|
* |
259
|
|
|
* @package lsx |
260
|
|
|
* @subpackage woocommerce |
261
|
|
|
*/ |
262
|
|
|
function lsx_wc_change_price_html( $price, $product ) { |
263
|
|
|
if ( empty( $product->get_price() ) ) { |
264
|
|
|
if ( $product->is_on_sale() && $product->get_regular_price() ) { |
265
|
|
|
$regular_price = wc_get_price_to_display( $product, array( |
266
|
|
|
'qty' => 1, |
267
|
|
|
'price' => $product->get_regular_price(), |
268
|
|
|
) ); |
269
|
|
|
|
270
|
|
|
$price = wc_format_price_range( $regular_price, esc_html__( 'Free!', 'lsx' ) ); |
271
|
|
|
} else { |
272
|
|
|
$price = '<span class="amount">' . esc_html__( 'Free!', 'lsx' ) . '</span>'; |
273
|
|
|
} |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
return $price; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
add_filter( 'woocommerce_get_price_html', 'lsx_wc_change_price_html', 15, 2 ); |
280
|
|
|
|
281
|
|
|
endif; |
282
|
|
|
|
283
|
|
|
if ( ! function_exists( 'lsx_wc_cart_link_fragment' ) ) : |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* Cart Fragments. |
287
|
|
|
* Ensure cart contents update when products are added to the cart via AJAX. |
288
|
|
|
* |
289
|
|
|
* @package lsx |
290
|
|
|
* @subpackage woocommerce |
291
|
|
|
*/ |
292
|
|
|
function lsx_wc_cart_link_fragment( $fragments ) { |
293
|
|
|
global $woocommerce; |
294
|
|
|
|
295
|
|
|
ob_start(); |
296
|
|
|
lsx_wc_cart_link(); |
297
|
|
|
$fragments['li.lsx-wc-cart-menu-item > a'] = ob_get_clean(); |
298
|
|
|
|
299
|
|
|
return $fragments; |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
endif; |
303
|
|
|
|
304
|
|
|
if ( ! function_exists( 'lsx_wc_cart_link' ) ) : |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* Cart Link. |
308
|
|
|
* Displayed a link to the cart including the number of items present and the cart total. |
309
|
|
|
* |
310
|
|
|
* @package lsx |
311
|
|
|
* @subpackage woocommerce |
312
|
|
|
*/ |
313
|
|
|
function lsx_wc_cart_link() { |
314
|
|
|
?> |
315
|
|
|
<a title="<?php esc_attr_e( 'View your shopping cart', 'lsx' ); ?>" href="<?php echo esc_url( wc_get_cart_url() ); ?>" data-toggle="dropdown" class="dropdown-toggle" aria-haspopup="true"> |
316
|
|
|
<?php /* Translators: %s: items quantity */ ?> |
317
|
|
|
<span class="lsx-wc-cart-amount"><?php echo wp_kses_data( WC()->cart->get_cart_subtotal() ); ?></span> <span class="lsx-wc-cart-count"><?php echo wp_kses_data( sprintf( _n( '%d item', '%d items', WC()->cart->get_cart_contents_count(), 'lsx' ), WC()->cart->get_cart_contents_count() ) );?></span> |
318
|
|
|
</a> |
319
|
|
|
<?php |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
endif; |
323
|
|
|
|
324
|
|
|
if ( ! function_exists( 'lsx_wc_loop_shop_per_page' ) ) : |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* Changes the number of products to display on shop. |
328
|
|
|
* |
329
|
|
|
* @package lsx |
330
|
|
|
* @subpackage woocommerce |
331
|
|
|
*/ |
332
|
|
|
function lsx_wc_loop_shop_per_page( $items ) { |
|
|
|
|
333
|
|
|
$items = 20; |
334
|
|
|
return $items; |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
add_filter( 'loop_shop_per_page', 'lsx_wc_loop_shop_per_page', 20 ); |
338
|
|
|
|
339
|
|
|
endif; |
340
|
|
|
|
341
|
|
|
if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.3', '>=' ) ) { |
342
|
|
|
add_filter( 'woocommerce_add_to_cart_fragments', 'lsx_wc_cart_link_fragment' ); |
343
|
|
|
} else { |
344
|
|
|
add_filter( 'add_to_cart_fragments', 'lsx_wc_cart_link_fragment' ); |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
remove_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 10 ); |
348
|
|
|
|
349
|
|
|
add_action( 'woocommerce_after_shop_loop', 'lsx_wc_sorting_wrapper', 9 ); |
350
|
|
|
add_action( 'woocommerce_after_shop_loop', 'woocommerce_catalog_ordering', 10 ); |
351
|
|
|
add_action( 'woocommerce_after_shop_loop', 'woocommerce_result_count', 20 ); |
352
|
|
|
add_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 30 ); |
353
|
|
|
add_action( 'woocommerce_after_shop_loop', 'lsx_wc_sorting_wrapper_close', 31 ); |
354
|
|
|
|
355
|
|
|
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 ); |
356
|
|
|
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 ); |
357
|
|
|
|
358
|
|
|
add_action( 'woocommerce_before_shop_loop', 'lsx_wc_sorting_wrapper', 9 ); |
359
|
|
|
add_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 10 ); |
360
|
|
|
add_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 ); |
361
|
|
|
add_action( 'woocommerce_before_shop_loop', 'lsx_wc_woocommerce_pagination', 30 ); |
362
|
|
|
add_action( 'woocommerce_before_shop_loop', 'lsx_wc_sorting_wrapper_close', 31 ); |
363
|
|
|
|
364
|
|
|
if ( ! function_exists( 'lsx_wc_sorting_wrapper' ) ) : |
365
|
|
|
|
366
|
|
|
/** |
367
|
|
|
* Sorting wrapper. |
368
|
|
|
* |
369
|
|
|
* @package lsx |
370
|
|
|
* @subpackage woocommerce |
371
|
|
|
*/ |
372
|
|
|
function lsx_wc_sorting_wrapper() { |
373
|
|
|
echo '<div class="lsx-wc-sorting">'; |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
endif; |
377
|
|
|
|
378
|
|
|
if ( ! function_exists( 'lsx_wc_sorting_wrapper_close' ) ) : |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* Sorting wrapper close. |
382
|
|
|
* |
383
|
|
|
* @package lsx |
384
|
|
|
* @subpackage woocommerce |
385
|
|
|
*/ |
386
|
|
|
function lsx_wc_sorting_wrapper_close() { |
387
|
|
|
echo '</div>'; |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
endif; |
391
|
|
|
|
392
|
|
|
if ( ! function_exists( 'lsx_wc_product_columns_wrapper_close' ) ) : |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* Product columns wrapper close. |
396
|
|
|
* |
397
|
|
|
* @package lsx |
398
|
|
|
* @subpackage woocommerce |
399
|
|
|
*/ |
400
|
|
|
function lsx_wc_product_columns_wrapper_close() { |
401
|
|
|
echo '</div>'; |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
endif; |
405
|
|
|
|
406
|
|
|
if ( ! function_exists( 'lsx_wc_woocommerce_pagination' ) ) : |
407
|
|
|
|
408
|
|
|
/** |
409
|
|
|
* LSX WooCommerce Pagination |
410
|
|
|
* WooCommerce disables the product pagination inside the woocommerce_product_subcategories() function |
411
|
|
|
* but since LSX adds pagination before that function is excuted we need a separate function to |
412
|
|
|
* determine whether or not to display the pagination. |
413
|
|
|
* |
414
|
|
|
* @package lsx |
415
|
|
|
* @subpackage woocommerce |
416
|
|
|
*/ |
417
|
|
|
function lsx_wc_woocommerce_pagination() { |
418
|
|
|
if ( woocommerce_products_will_display() ) { |
419
|
|
|
woocommerce_pagination(); |
420
|
|
|
} |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
endif; |
424
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.