Completed
Push — master ( 3e9b97...4fb7fa )
by Fernando
02:38
created

woocommerce.php ➔ lsx_wc_disable_lsx_banner_plugin()   B

Complexity

Conditions 7
Paths 4

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 7
nc 4
nop 1
dl 0
loc 13
rs 8.2222
c 0
b 0
f 0
1
<?php
2
/**
3
 * LSX functions and definitions - WooCommerce.
4
 *
5
 * @package    lsx
6
 * @subpackage woocommerce
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
		add_theme_support( 'wc-product-gallery-zoom' );
24
		add_theme_support( 'wc-product-gallery-lightbox' );
25
		add_theme_support( 'wc-product-gallery-slider' );
26
	}
27
28
	add_action( 'after_setup_theme', 'lsx_wc_support' );
29
30
endif;
31
32
if ( ! function_exists( 'lsx_wc_scripts_add_styles' ) ) :
33
34
	/**
35
	 * WooCommerce enqueue styles.
36
	 *
37
	 * @package    lsx
38
	 * @subpackage woocommerce
39
	 */
40
	function lsx_wc_scripts_add_styles() {
41
		wp_enqueue_style( 'woocommerce-lsx', get_template_directory_uri() . '/assets/css/woocommerce.css', array( 'lsx_main' ), LSX_VERSION );
42
		wp_style_add_data( 'woocommerce-lsx', 'rtl', 'replace' );
43
44
		// Remove select2 added by WooCommerce
45
46
		if ( ! is_admin() ) {
47
			wp_dequeue_style( 'select2' );
48
			wp_deregister_style( 'select2' );
49
50
			wp_dequeue_script( 'select2' );
51
			//wp_deregister_script( 'select2' );
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
52
		}
53
	}
54
55
	add_action( 'wp_enqueue_scripts', 'lsx_wc_scripts_add_styles' );
56
57
endif;
58
59
if ( ! function_exists( 'lsx_wc_form_field_args' ) ) :
60
61
	/**
62
	 * WooCommerce form fields.
63
	 *
64
	 * @package    lsx
65
	 * @subpackage woocommerce
66
	 */
67
	function lsx_wc_form_field_args( $args, $key, $value ) {
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
68
		$args['input_class'][] = 'form-control';
69
70
		return $args;
71
	}
72
73
	add_action( 'woocommerce_form_field_args', 'lsx_wc_form_field_args', 10, 3 );
74
75
endif;
76
77 View Code Duplication
if ( ! function_exists( 'lsx_wc_theme_wrapper_start' ) ) :
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
79
	/**
80
	 * WooCommerce wrapper start.
81
	 *
82
	 * @package    lsx
83
	 * @subpackage woocommerce
84
	 */
85
	function lsx_wc_theme_wrapper_start() {
86
		lsx_content_wrap_before();
87
		echo '<div id="primary" class="content-area ' . esc_attr( lsx_main_class() ) . '">';
88
		lsx_content_before();
89
		echo '<main id="main" class="site-main" role="main">';
90
		lsx_content_top();
91
	}
92
93
	remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
94
	add_action( 'woocommerce_before_main_content', 'lsx_wc_theme_wrapper_start' );
95
96
endif;
97
98 View Code Duplication
if ( ! function_exists( 'lsx_wc_theme_wrapper_end' ) ) :
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
99
100
	/**
101
	 * WooCommerce wrapper end.
102
	 *
103
	 * @package    lsx
104
	 * @subpackage woocommerce
105
	 */
106
	function lsx_wc_theme_wrapper_end() {
107
		lsx_content_bottom();
108
		echo '</main>';
109
		lsx_content_after();
110
		echo '</div>';
111
		lsx_content_wrap_after();
112
	}
113
114
	remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );
115
	add_action( 'woocommerce_after_main_content', 'lsx_wc_theme_wrapper_end' );
116
117
endif;
118
119
if ( ! function_exists( 'lsx_wc_disable_lsx_banner_plugin' ) ) :
120
121
	/**
122
	 * Disable LSX Banners plugin in some WC pages.
123
	 *
124
	 * @package    lsx
125
	 * @subpackage woocommerce
126
	 */
127
	function lsx_wc_disable_lsx_banner_plugin( $disabled ) {
128
		global $post;
129
130
		if ( is_cart() || is_checkout() || is_account_page() ) {
131
			$disabled = true;
132
		}
133
134
		if ( $post && class_exists( 'WC_Wishlists_Pages' ) && WC_Wishlists_Pages::is_wishlist_page( $post->post_name ) ) {
135
			$disabled = true;
136
		}
137
138
		return $disabled;
139
	}
140
141
	add_filter( 'lsx_banner_plugin_disable', 'lsx_wc_disable_lsx_banner_plugin' );
142
143
endif;
144
145
if ( ! function_exists( 'lsx_wc_disable_lsx_banner' ) ) :
146
147
	/**
148
	 * Disable LSX Banners banner in some WC pages.
149
	 *
150
	 * @package    lsx
151
	 * @subpackage woocommerce
152
	 */
153
	function lsx_wc_disable_lsx_banner( $disabled ) {
154
		if ( is_shop() || is_product_category() || is_product_tag() || is_product() ) {
155
			$disabled = true;
156
		}
157
158
		return $disabled;
159
	}
160
161
	add_filter( 'lsx_banner_disable', 'lsx_wc_disable_lsx_banner' );
162
163
endif;
164
165
if ( ! function_exists( 'lsx_wc_add_cart' ) ) :
166
167
	/**
168
	 * Adds WC cart to the header.
169
	 *
170
	 * @package    lsx
171
	 * @subpackage template-tags
172
	 */
173
	function lsx_wc_add_cart( $items, $args ) {
174
		$cart_menu_item_position = apply_filters( 'lsx_wc_cart_menu_item_position', 'primary' );
175
176
		if ( $cart_menu_item_position === $args->theme_location ) {
177
			$customizer_option  = get_theme_mod( 'lsx_header_wc_cart', false );
178
179
			if ( ! empty( $customizer_option ) ) {
180
				ob_start();
181
				the_widget( 'WC_Widget_Cart', 'title=' );
182
				$widget = ob_get_clean();
183
184
				if ( is_cart() ) {
185
					$item_class = 'current-menu-item';
0 ignored issues
show
Unused Code introduced by
$item_class is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
186
				} else {
187
					$item_class = '';
0 ignored issues
show
Unused Code introduced by
$item_class is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
188
				}
189
190
				$item_class = 'menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children dropdown lsx-wc-cart-menu-item ' . $class;
0 ignored issues
show
Bug introduced by
The variable $class does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
191
				$item_class = apply_filters( 'lsx_wc_cart_menu_item_class', $item_class );
192
193
				$item = '<li class="' . $item_class . '">' .
194
							'<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">' .
195
								'<span class="lsx-wc-cart-amount">' . wp_kses_data( WC()->cart->get_cart_subtotal() ) . '</span>' .
196
								/* Translators: %s: items quantity */
197
								'<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>' .
198
								( ! empty( WC()->cart->get_cart_contents_count() ) ? '<span class="lsx-wc-cart-count-badge">' . wp_kses_data( WC()->cart->get_cart_contents_count() ) . '</span>' : '' ) .
199
							'</a>' .
200
							'<ul role="menu" class=" dropdown-menu lsx-wc-cart-sub-menu">' .
201
								'<li>' .
202
									'<div class="lsx-wc-cart-dropdown">' . $widget . '</div>' .
203
								'</li>' .
204
							'</ul>' .
205
						'</li>';
206
207
				if ( 'top-menu' === $args->theme_location ) {
208
					$items = $item . $items;
209
				} else {
210
					$items = $items . $item;
211
				}
212
			}
213
		}
214
215
		return $items;
216
	}
217
218
	add_filter( 'wp_nav_menu_items', 'lsx_wc_add_cart', 10, 2 );
219
220
endif;
221
222
if ( ! function_exists( 'lsx_wc_products_widget_wrapper_before' ) ) :
223
224
	/**
225
	 * Change WC products widget wrapper (before).
226
	 *
227
	 * @package    lsx
228
	 * @subpackage woocommerce
229
	 */
230
	function lsx_wc_products_widget_wrapper_before( $html ) {
0 ignored issues
show
Unused Code introduced by
The parameter $html is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
231
		$html = '<div class="lsx-woocommerce-slider lsx-woocommerce-shortcode">';
232
		return $html;
233
	}
234
235
	add_filter( 'woocommerce_before_widget_product_list', 'lsx_wc_products_widget_wrapper_before', 15 );
236
237
endif;
238
239
if ( ! function_exists( 'lsx_wc_products_widget_wrapper_after' ) ) :
240
241
	/**
242
	 * Change WC products widget wrapper (after).
243
	 *
244
	 * @package    lsx
245
	 * @subpackage woocommerce
246
	 */
247
	function lsx_wc_products_widget_wrapper_after( $html ) {
0 ignored issues
show
Unused Code introduced by
The parameter $html is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
248
		$html = '</div>';
249
		return $html;
250
	}
251
252
	add_filter( 'woocommerce_after_widget_product_list', 'lsx_wc_products_widget_wrapper_after', 15 );
253
254
endif;
255
256
if ( ! function_exists( 'lsx_wc_reviews_widget_override' ) ) :
257
258
	/**
259
	 * Override WC ewviews widget.
260
	 *
261
	 * @package    lsx
262
	 * @subpackage woocommerce
263
	 */
264
	function lsx_wc_reviews_widget_override() {
265
		if ( class_exists( 'WC_Widget_Recent_Reviews' ) ) {
266
			unregister_widget( 'WC_Widget_Recent_Reviews' );
267
			require get_template_directory() . '/includes/classes/class-lsx-wc-widget-recent-reviews.php';
268
			register_widget( 'LSX_WC_Widget_Recent_Reviews' );
269
		}
270
	}
271
272
	add_action( 'widgets_init', 'lsx_wc_reviews_widget_override', 15 );
273
274
endif;
275
276
if ( ! function_exists( 'lsx_wc_change_price_html' ) ) :
277
278
	/**
279
	 * Change WC ZERO price to "free".
280
	 *
281
	 * @package    lsx
282
	 * @subpackage woocommerce
283
	 */
284
	function lsx_wc_change_price_html( $price, $product ) {
285
		if ( empty( $product->get_price() ) ) {
286
			if ( $product->is_on_sale() && $product->get_regular_price() ) {
287
				$regular_price = wc_get_price_to_display( $product, array(
288
					'qty' => 1,
289
					'price' => $product->get_regular_price(),
290
				) );
291
292
				$price = wc_format_price_range( $regular_price, esc_html__( 'Free!', 'lsx' ) );
293
			} else {
294
				$price = '<span class="amount">' . esc_html__( 'Free!', 'lsx' ) . '</span>';
295
			}
296
		}
297
298
		return $price;
299
	}
300
301
	add_filter( 'woocommerce_get_price_html', 'lsx_wc_change_price_html', 15, 2 );
302
303
endif;
304
305
if ( ! function_exists( 'lsx_wc_cart_link_fragment' ) ) :
306
307
	/**
308
	 * Cart Fragments.
309
	 * Ensure cart contents update when products are added to the cart via AJAX.
310
	 *
311
	 * @package    lsx
312
	 * @subpackage woocommerce
313
	 */
314
	function lsx_wc_cart_link_fragment( $fragments ) {
315
		global $woocommerce;
316
317
		ob_start();
318
		lsx_wc_cart_link();
319
		$fragments['li.lsx-wc-cart-menu-item > a'] = ob_get_clean();
320
321
		ob_start();
322
		lsx_wc_items_counter();
323
		$items_counter = ob_get_clean();
324
325
		if ( ! empty( $items_counter ) ) {
326
			$fragments['div.widget_shopping_cart_content'] = preg_replace( '/(.+)(<\/ul>)[\s\n]*(<p class="woocommerce-mini-cart__total)(.+)/', '$1' . $items_counter . '$2$3$4', $fragments['div.widget_shopping_cart_content'] );
327
		}
328
329
		return $fragments;
330
	}
331
332
endif;
333
334
if ( ! function_exists( 'lsx_wc_cart_link' ) ) :
335
336
	/**
337
	 * Cart Link.
338
	 * Displayed a link to the cart including the number of items present and the cart total.
339
	 *
340
	 * @package    lsx
341
	 * @subpackage woocommerce
342
	 */
343
	function lsx_wc_cart_link() {
344
		?>
345
			<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">
346
				<span class="lsx-wc-cart-amount"><?php echo wp_kses_data( WC()->cart->get_cart_subtotal() ); ?></span>
347
348
				<?php /* Translators: %s: items quantity */ ?>
349
				<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>
350
351
				<?php if ( ! empty( WC()->cart->get_cart_contents_count() ) ) : ?>
352
					<span class="lsx-wc-cart-count-badge"><?php echo wp_kses_data( WC()->cart->get_cart_contents_count() );?></span>
353
				<?php endif; ?>
354
			</a>
355
		<?php
356
	}
357
358
endif;
359
360
if ( ! function_exists( 'lsx_wc_items_counter' ) ) :
361
362
	/**
363
	 * Add car item hidden items counter.
364
	 *
365
	 * @package    lsx
366
	 * @subpackage woocommerce
367
	 */
368
	function lsx_wc_items_counter() {
369
		$count = (int) WC()->cart->get_cart_contents_count();
370
		$items_counter = '';
371
372
		if ( ! empty( $count ) ) {
373
			$count -= 3;
374
375
			if ( 1 === $count ) {
376
				$items_counter = esc_html__( '1 other item in cart', 'lsx' );
377
			} elseif ( $count > 1 ) {
378
				/* Translators: %s: items counter */
379
				$items_counter = sprintf( esc_html__( '%s other items in cart', 'lsx' ), $count );
380
			}
381
		}
382
383
		if ( ! empty( $items_counter ) ) :
384
			?>
385
				<li class="woocommerce-mini-cart-item mini_cart_item" style="display: block;">
386
					<a href="<?php echo esc_url( WC()->cart->get_cart_url() ); ?>"><?php echo esc_html( $items_counter ); ?></a>
387
				</li>
388
			<?php
389
		endif;
390
	}
391
392
endif;
393
394
if ( ! function_exists( 'lsx_wc_loop_shop_per_page' ) ) :
395
396
	/**
397
	 * Changes the number of products to display on shop.
398
	 *
399
	 * @package    lsx
400
	 * @subpackage woocommerce
401
	 */
402
	function lsx_wc_loop_shop_per_page( $items ) {
0 ignored issues
show
Unused Code introduced by
The parameter $items is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
403
		$items = 20;
404
		return $items;
405
	}
406
407
	add_filter( 'loop_shop_per_page', 'lsx_wc_loop_shop_per_page', 20 );
408
409
endif;
410
411
if ( ! function_exists( 'lsx_wc_add_to_cart_message_html' ) ) :
412
413
	/**
414
	 * Changes the "added to cart" message HTML.
415
	 *
416
	 * @package    lsx
417
	 * @subpackage woocommerce
418
	 */
419
	function lsx_wc_add_to_cart_message_html( $message, $products ) {
0 ignored issues
show
Unused Code introduced by
The parameter $products is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
420
		$message = '<div class="woocommerce-message-added-to-cart">' . $message . '</div>';
421
		return $message;
422
	}
423
424
	add_filter( 'wc_add_to_cart_message_html', 'lsx_wc_add_to_cart_message_html', 20, 2 );
425
426
endif;
427
428
if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.3', '>=' ) ) {
429
	add_filter( 'woocommerce_add_to_cart_fragments', 'lsx_wc_cart_link_fragment' );
430
} else {
431
	add_filter( 'add_to_cart_fragments', 'lsx_wc_cart_link_fragment' );
432
}
433
434
remove_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 10 );
435
436
add_action( 'woocommerce_after_shop_loop', 'lsx_wc_sorting_wrapper', 9 );
437
add_action( 'woocommerce_after_shop_loop', 'woocommerce_catalog_ordering', 10 );
438
add_action( 'woocommerce_after_shop_loop', 'woocommerce_result_count', 20 );
439
add_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 30 );
440
add_action( 'woocommerce_after_shop_loop', 'lsx_wc_sorting_wrapper_close', 31 );
441
442
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
443
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
444
445
add_action( 'woocommerce_before_shop_loop', 'lsx_wc_sorting_wrapper', 9 );
446
add_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 10 );
447
add_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
448
add_action( 'woocommerce_before_shop_loop', 'lsx_wc_woocommerce_pagination', 30 );
449
add_action( 'woocommerce_before_shop_loop', 'lsx_wc_sorting_wrapper_close', 31 );
450
451
if ( ! function_exists( 'lsx_wc_sorting_wrapper' ) ) :
452
453
	/**
454
	 * Sorting wrapper.
455
	 *
456
	 * @package    lsx
457
	 * @subpackage woocommerce
458
	 */
459
	function lsx_wc_sorting_wrapper() {
460
		echo '<div class="lsx-wc-sorting">';
461
	}
462
463
endif;
464
465
if ( ! function_exists( 'lsx_wc_sorting_wrapper_close' ) ) :
466
467
	/**
468
	 * Sorting wrapper close.
469
	 *
470
	 * @package    lsx
471
	 * @subpackage woocommerce
472
	 */
473
	function lsx_wc_sorting_wrapper_close() {
474
		echo '</div>';
475
	}
476
477
endif;
478
479
if ( ! function_exists( 'lsx_wc_product_columns_wrapper_close' ) ) :
480
481
	/**
482
	 * Product columns wrapper close.
483
	 *
484
	 * @package    lsx
485
	 * @subpackage woocommerce
486
	 */
487
	function lsx_wc_product_columns_wrapper_close() {
488
		echo '</div>';
489
	}
490
491
endif;
492
493
if ( ! function_exists( 'lsx_wc_woocommerce_pagination' ) ) :
494
495
	/**
496
	 * LSX WooCommerce Pagination
497
	 * WooCommerce disables the product pagination inside the woocommerce_product_subcategories() function
498
	 * but since LSX adds pagination before that function is excuted we need a separate function to
499
	 * determine whether or not to display the pagination.
500
	 *
501
	 * @package    lsx
502
	 * @subpackage woocommerce
503
	 */
504
	function lsx_wc_woocommerce_pagination() {
505
		if ( woocommerce_products_will_display() ) {
506
			woocommerce_pagination();
507
		}
508
	}
509
510
endif;
511
512
if ( ! function_exists( 'lsx_customizer_wc_controls' ) ) :
513
514
	/**
515
	 * Returns an array of the core panel.
516
	 *
517
	 * @package    lsx
518
	 * @subpackage customizer
519
	 *
520
	 * @return $lsx_controls array()
0 ignored issues
show
Documentation introduced by
The doc-type $lsx_controls could not be parsed: Unknown type name "$lsx_controls" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
521
	 */
522
	function lsx_customizer_wc_controls( $lsx_controls ) {
523
		$lsx_controls['panels']['lsx-wc'] = array(
524
			'title'       => esc_html__( 'WooCommerce', 'lsx' ),
525
			'description' => esc_html__( 'Change the WooCommerce settings.', 'lsx' ),
526
			'priority'    => 23,
527
		);
528
529
		/**
530
		 * Global.
531
		 */
532
533
		$lsx_controls['sections']['lsx-wc-global'] = array(
534
			'title'       => esc_html__( 'Global', 'lsx' ),
535
			'description' => esc_html__( 'Change the WooCommerce global settings.', 'lsx' ),
536
			'panel'       => 'lsx-wc',
537
			'priority'    => 1,
538
		);
539
540
		$lsx_controls['settings']['lsx_wc_mobile_footer_bar_status'] = array(
541
			'default'           => '1',
542
			'sanitize_callback' => 'lsx_sanitize_checkbox',
543
		);
544
545
		$lsx_controls['fields']['lsx_wc_mobile_footer_bar_status'] = array(
546
			'label'       => esc_html__( 'Footer Bar', 'lsx' ),
547
			'description' => esc_html__( 'Enable the mobile footer bar.', 'lsx' ),
548
			'section'     => 'lsx-wc-global',
549
			'type'        => 'checkbox',
550
			'priority'    => 1,
551
		);
552
553
		/**
554
		 * Cart.
555
		 */
556
557
		$lsx_controls['sections']['lsx-wc-cart'] = array(
558
			'title'       => esc_html__( 'Cart', 'lsx' ),
559
			'description' => esc_html__( 'Change the WooCommerce cart settings.', 'lsx' ),
560
			'panel'       => 'lsx-wc',
561
			'priority'    => 2,
562
		);
563
564
		$lsx_controls['settings']['lsx_header_wc_cart'] = array(
565
			'default'           => false,
566
			'sanitize_callback' => 'lsx_sanitize_checkbox',
567
		);
568
569
		$lsx_controls['fields']['lsx_header_wc_cart'] = array(
570
			'label'       => esc_html__( 'Menu Item', 'lsx' ),
571
			'description' => esc_html__( 'Enable the cart menu item.', 'lsx' ),
572
			'section'     => 'lsx-wc-cart',
573
			'type'        => 'checkbox',
574
			'priority'    => 1,
575
		);
576
577
		return $lsx_controls;
578
	}
579
580
	add_filter( 'lsx_customizer_controls', 'lsx_customizer_wc_controls' );
581
582
endif;
583
584
if ( ! function_exists( 'lsx_wc_footer_bar' ) ) :
585
586
	/**
587
	 * Display WC footer bar.
588
	 *
589
	 * @package    lsx
590
	 * @subpackage woocommerce
591
	 */
592
	function lsx_wc_footer_bar() {
593
		if ( ! empty( get_theme_mod( 'lsx_wc_mobile_footer_bar_status', '1' ) ) ) :
594
			?>
595
			<div class="lsx-wc-footer-bar">
596
				<form role="search" method="get" action="<?php echo esc_url( home_url() ); ?>" class="lsx-wc-footer-bar-form">
597
					<fieldset>
598
						<legend class="screen-reader-text"><?php esc_html_e( 'Search products', 'lsx' ); ?></legend>
599
						<input type="search" name="s" placeholder="<?php esc_attr_e( 'Search products…', 'lsx' ); ?>" class="form-control">
600
					</fieldset>
601
				</form>
602
603
				<ul class="lsx-wc-footer-bar-items">
604
					<li class="lsx-wc-footer-bar-item">
605
						<a href="<?php echo esc_url( home_url() ); ?>" class="lsx-wc-footer-bar-link">
606
							<i class="fa fa-home" aria-hidden="true"></i>
607
							<span><?php esc_html_e( 'Home', 'lsx' ); ?></span>
608
						</a>
609
					</li>
610
611
					<li class="lsx-wc-footer-bar-item">
612
						<a href="<?php echo esc_url( get_permalink( get_option( 'woocommerce_myaccount_page_id' ) ) ); ?>" class="lsx-wc-footer-bar-link">
613
							<i class="fa fa-user" aria-hidden="true"></i>
614
							<span><?php esc_html_e( 'Account', 'lsx' ); ?></span>
615
						</a>
616
					</li>
617
618
					<li class="lsx-wc-footer-bar-item">
619
						<a href="#" class="lsx-wc-footer-bar-link lsx-wc-footer-bar-link-toogle">
620
							<i class="fa fa-search" aria-hidden="true"></i>
621
							<span><?php esc_html_e( 'Search', 'lsx' ); ?></span>
622
						</a>
623
					</li>
624
625
					<li class="lsx-wc-footer-bar-item">
626
						<a href="<?php echo esc_url( WC()->cart->get_cart_url() ); ?>" class="lsx-wc-footer-bar-link">
627
							<i class="fa fa-shopping-basket" aria-hidden="true"></i>
628
							<?php $count = WC()->cart->get_cart_contents_count(); ?>
629
							<?php if ( ! empty( $count ) ) : ?>
630
								<span class="lsx-wc-footer-bar-count"><?php echo wp_kses_data( $count ); ?></span>
631
							<?php endif; ?>
632
							<span><?php esc_html_e( 'Cart', 'lsx' ); ?></span>
633
						</a>
634
					</li>
635
				</ul>
636
			</div>
637
			<?php
638
		endif;
639
	}
640
641
	add_action( 'lsx_body_bottom', 'lsx_wc_footer_bar', 15 );
642
643
endif;
644
645
if ( ! function_exists( 'lsx_wc_body_class' ) ) :
646
647
	/**
648
	 * Changes body class.
649
	 *
650
	 * @package    lsx
651
	 * @subpackage woocommerce
652
	 */
653
	function lsx_wc_body_class( $classes ) {
654
		global $post;
655
656
		if ( $post && class_exists( 'WC_Wishlists_Pages' ) && WC_Wishlists_Pages::is_wishlist_page( $post->post_name ) ) {
657
			$classes[] = 'woocommerce-page woocommerce-wishlist';
658
		}
659
660
		return $classes;
661
	}
662
663
	add_filter( 'body_class', 'lsx_wc_body_class', 2999 );
664
665
endif;
666
667
if ( ! function_exists( 'lsx_wc_downloadable_products' ) ) :
668
669
	/**
670
	 * Changes downloads "download" button text.
671
	 *
672
	 * @package    lsx
673
	 * @subpackage woocommerce
674
	 */
675
	function lsx_wc_downloadable_products( $downloads ) {
676
		foreach ( $downloads as $i => $download ) {
677
			$downloads[ $i ]['download_name'] = esc_html__( 'Download', 'lsx' );
678
		}
679
680
		return $downloads;
681
	}
682
683
	add_filter( 'woocommerce_customer_get_downloadable_products', 'lsx_wc_downloadable_products', 2999 );
684
685
endif;
686