Passed
Push — master ( 934024...c47381 )
by Warwick
03:27
created

woocommerce.php ➔ lsx_wc_product_searchform()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 20
rs 9.4285
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
		// Remove WC Shipping Multiple Addresses specific script causing issues on checkout
55
		wp_dequeue_script( 'wcms-country-select' );
56
	}
57
58
	add_action( 'wp_enqueue_scripts', 'lsx_wc_scripts_add_styles' );
59
60
endif;
61
62
if ( ! function_exists( 'lsx_wc_form_field_args' ) ) :
63
64
	/**
65
	 * WooCommerce form fields.
66
	 *
67
	 * @package    lsx
68
	 * @subpackage woocommerce
69
	 */
70
	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...
71
		$args['input_class'][] = 'form-control';
72
73
		return $args;
74
	}
75
76
	add_action( 'woocommerce_form_field_args', 'lsx_wc_form_field_args', 10, 3 );
77
78
endif;
79
80 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...
81
82
	/**
83
	 * WooCommerce wrapper start.
84
	 *
85
	 * @package    lsx
86
	 * @subpackage woocommerce
87
	 */
88
	function lsx_wc_theme_wrapper_start() {
89
		lsx_content_wrap_before();
90
		echo '<div id="primary" class="content-area ' . esc_attr( lsx_main_class() ) . '">';
91
		lsx_content_before();
92
		echo '<main id="main" class="site-main" role="main">';
93
		lsx_content_top();
94
	}
95
96
	remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
97
	add_action( 'woocommerce_before_main_content', 'lsx_wc_theme_wrapper_start' );
98
99
endif;
100
101 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...
102
103
	/**
104
	 * WooCommerce wrapper end.
105
	 *
106
	 * @package    lsx
107
	 * @subpackage woocommerce
108
	 */
109
	function lsx_wc_theme_wrapper_end() {
110
		lsx_content_bottom();
111
		echo '</main>';
112
		lsx_content_after();
113
		echo '</div>';
114
		lsx_content_wrap_after();
115
	}
116
117
	remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );
118
	add_action( 'woocommerce_after_main_content', 'lsx_wc_theme_wrapper_end' );
119
120
endif;
121
122
if ( ! function_exists( 'lsx_wc_disable_lsx_banner_plugin' ) ) :
123
124
	/**
125
	 * Disable LSX Banners plugin in some WC pages.
126
	 *
127
	 * @package    lsx
128
	 * @subpackage woocommerce
129
	 */
130
	function lsx_wc_disable_lsx_banner_plugin( $disabled ) {
131
		global $post;
132
133
		if ( is_cart() || is_checkout() || is_account_page() ) {
134
			$disabled = true;
135
		}
136
137
		if ( $post && class_exists( 'WC_Wishlists_Pages' ) && WC_Wishlists_Pages::is_wishlist_page( $post->post_name ) ) {
138
			$disabled = true;
139
		}
140
141
		return $disabled;
142
	}
143
144
	add_filter( 'lsx_banner_plugin_disable', 'lsx_wc_disable_lsx_banner_plugin' );
145
146
endif;
147
148
if ( ! function_exists( 'lsx_wc_disable_lsx_banner' ) ) :
149
150
	/**
151
	 * Disable LSX Banners banner in some WC pages.
152
	 *
153
	 * @package    lsx
154
	 * @subpackage woocommerce
155
	 */
156
	function lsx_wc_disable_lsx_banner( $disabled ) {
157
		if ( is_shop() || is_product_category() || is_product_tag() || is_product() ) {
158
			$disabled = true;
159
		}
160
161
		return $disabled;
162
	}
163
164
	add_filter( 'lsx_banner_disable', 'lsx_wc_disable_lsx_banner' );
165
166
endif;
167
168
if ( ! function_exists( 'lsx_wc_add_cart' ) ) :
169
170
	/**
171
	 * Adds WC cart to the header.
172
	 *
173
	 * @package    lsx
174
	 * @subpackage template-tags
175
	 */
176
	function lsx_wc_add_cart( $items, $args ) {
177
		$cart_menu_item_position = apply_filters( 'lsx_wc_cart_menu_item_position', 'primary' );
178
179
		$cart_logged_out_position = $cart_menu_item_position . '_logged_out';
180
181
		if ( $cart_menu_item_position === $args->theme_location || $cart_logged_out_position === $args->theme_location ) {
182
			$customizer_option  = get_theme_mod( 'lsx_header_wc_cart', false );
183
184
			if ( ! empty( $customizer_option ) ) {
185
				ob_start();
186
				the_widget( 'WC_Widget_Cart', 'title=' );
187
				$widget = ob_get_clean();
188
189
				if ( is_cart() ) {
190
					$class = 'current-menu-item';
191
				} else {
192
					$class = '';
193
				}
194
195
				$item_class = 'menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children dropdown lsx-wc-cart-menu-item ' . $class;
196
				$item_class = apply_filters( 'lsx_wc_cart_menu_item_class', $item_class );
197
198
				$item = '<li class="' . $item_class . '">' .
199
							'<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">' .
200
								'<span class="lsx-wc-cart-amount">' . wp_kses_data( WC()->cart->get_cart_subtotal() ) . '</span>' .
201
								/* Translators: %s: items quantity */
202
								'<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>' .
203
								( ! empty( WC()->cart->get_cart_contents_count() ) ? '<span class="lsx-wc-cart-count-badge">' . wp_kses_data( WC()->cart->get_cart_contents_count() ) . '</span>' : '' ) .
204
							'</a>' .
205
							'<ul role="menu" class=" dropdown-menu lsx-wc-cart-sub-menu">' .
206
								'<li>' .
207
									'<div class="lsx-wc-cart-dropdown">' . $widget . '</div>' .
208
								'</li>' .
209
							'</ul>' .
210
						'</li>';
211
212
				if ( 'top-menu' === $args->theme_location ) {
213
					$items = $item . $items;
214
				} else {
215
					$items = $items . $item;
216
				}
217
			}
218
		}
219
220
		return $items;
221
	}
222
223
	add_filter( 'wp_nav_menu_items', 'lsx_wc_add_cart', 10, 2 );
224
225
endif;
226
227
if ( ! function_exists( 'lsx_wc_products_widget_wrapper_before' ) ) :
228
229
	/**
230
	 * Change WC products widget wrapper (before).
231
	 *
232
	 * @package    lsx
233
	 * @subpackage woocommerce
234
	 */
235
	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...
236
		$html = '<div class="lsx-woocommerce-slider lsx-woocommerce-shortcode">';
237
		return $html;
238
	}
239
240
	add_filter( 'woocommerce_before_widget_product_list', 'lsx_wc_products_widget_wrapper_before', 15 );
241
242
endif;
243
244
if ( ! function_exists( 'lsx_wc_products_widget_wrapper_after' ) ) :
245
246
	/**
247
	 * Change WC products widget wrapper (after).
248
	 *
249
	 * @package    lsx
250
	 * @subpackage woocommerce
251
	 */
252
	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...
253
		$html = '</div>';
254
		return $html;
255
	}
256
257
	add_filter( 'woocommerce_after_widget_product_list', 'lsx_wc_products_widget_wrapper_after', 15 );
258
259
endif;
260
261
if ( ! function_exists( 'lsx_wc_reviews_widget_override' ) ) :
262
263
	/**
264
	 * Override WC ewviews widget.
265
	 *
266
	 * @package    lsx
267
	 * @subpackage woocommerce
268
	 */
269
	function lsx_wc_reviews_widget_override() {
270
		if ( class_exists( 'WC_Widget_Recent_Reviews' ) ) {
271
			unregister_widget( 'WC_Widget_Recent_Reviews' );
272
			require get_template_directory() . '/includes/classes/class-lsx-wc-widget-recent-reviews.php';
273
			register_widget( 'LSX_WC_Widget_Recent_Reviews' );
274
		}
275
	}
276
277
	add_action( 'widgets_init', 'lsx_wc_reviews_widget_override', 15 );
278
279
endif;
280
281
if ( ! function_exists( 'lsx_wc_change_price_html' ) ) :
282
283
	/**
284
	 * Change WC ZERO price to "free".
285
	 *
286
	 * @package    lsx
287
	 * @subpackage woocommerce
288
	 *
289
	 * @param $price string
290
	 * @param $product WC_Product
291
	 * @return string
292
	 */
293
	function lsx_wc_change_price_html( $price, $product ) {
294
		if ( empty( $product->get_price() ) ) {
295
			if ( $product->is_on_sale() && $product->get_regular_price() ) {
296
				$regular_price = wc_get_price_to_display( $product, array(
297
					'qty' => 1,
298
					'price' => $product->get_regular_price(),
299
				) );
300
301
				$price = wc_format_price_range( $regular_price, esc_html__( 'Free!', 'lsx' ) );
302
			} else {
303
				$price = '<span class="amount">' . esc_html__( 'Free!', 'lsx' ) . '</span>';
304
			}
305
		}
306
307
		return $price;
308
	}
309
310
	add_filter( 'woocommerce_get_price_html', 'lsx_wc_change_price_html', 15, 2 );
311
312
endif;
313
314
if ( ! function_exists( 'lsx_wc_cart_link_fragment' ) ) :
315
316
	/**
317
	 * Cart Fragments.
318
	 * Ensure cart contents update when products are added to the cart via AJAX.
319
	 *
320
	 * @package    lsx
321
	 * @subpackage woocommerce
322
	 */
323
	function lsx_wc_cart_link_fragment( $fragments ) {
324
		global $woocommerce;
325
326
		ob_start();
327
		lsx_wc_cart_link();
328
		$fragments['li.lsx-wc-cart-menu-item > a'] = ob_get_clean();
329
330
		ob_start();
331
		lsx_wc_items_counter();
332
		$items_counter = ob_get_clean();
333
334
		if ( ! empty( $items_counter ) ) {
335
			$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'] );
336
		}
337
338
		return $fragments;
339
	}
340
341
endif;
342
343
if ( ! function_exists( 'lsx_wc_cart_link' ) ) :
344
345
	/**
346
	 * Cart Link.
347
	 * Displayed a link to the cart including the number of items present and the cart total.
348
	 *
349
	 * @package    lsx
350
	 * @subpackage woocommerce
351
	 */
352
	function lsx_wc_cart_link() {
353
		?>
354
			<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">
355
				<span class="lsx-wc-cart-amount"><?php echo wp_kses_data( WC()->cart->get_cart_subtotal() ); ?></span>
356
357
				<?php /* Translators: %s: items quantity */ ?>
358
				<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>
359
360
				<?php if ( ! empty( WC()->cart->get_cart_contents_count() ) ) : ?>
361
					<span class="lsx-wc-cart-count-badge"><?php echo wp_kses_data( WC()->cart->get_cart_contents_count() );?></span>
362
				<?php endif; ?>
363
			</a>
364
		<?php
365
	}
366
367
endif;
368
369
if ( ! function_exists( 'lsx_wc_items_counter' ) ) :
370
371
	/**
372
	 * Add car item hidden items counter.
373
	 *
374
	 * @package    lsx
375
	 * @subpackage woocommerce
376
	 */
377
	function lsx_wc_items_counter() {
378
		$count = (int) WC()->cart->get_cart_contents_count();
379
		$items_counter = '';
380
381
		if ( ! empty( $count ) ) {
382
			$count -= 3;
383
384
			if ( 1 === $count ) {
385
				$items_counter = esc_html__( '1 other item in cart', 'lsx' );
386
			} elseif ( $count > 1 ) {
387
				/* Translators: %s: items counter */
388
				$items_counter = sprintf( esc_html__( '%s other items in cart', 'lsx' ), $count );
389
			}
390
		}
391
392
		if ( ! empty( $items_counter ) ) :
393
			?>
394
				<li class="woocommerce-mini-cart-item mini_cart_item" style="display: block;">
395
					<a href="<?php echo esc_url( WC()->cart->get_cart_url() ); ?>"><?php echo esc_html( $items_counter ); ?></a>
396
				</li>
397
			<?php
398
		endif;
399
	}
400
401
endif;
402
403
if ( ! function_exists( 'lsx_wc_loop_shop_per_page' ) ) :
404
405
	/**
406
	 * Changes the number of products to display on shop.
407
	 *
408
	 * @package    lsx
409
	 * @subpackage woocommerce
410
	 */
411
	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...
412
		$items = 20;
413
		return $items;
414
	}
415
416
	add_filter( 'loop_shop_per_page', 'lsx_wc_loop_shop_per_page', 20 );
417
418
endif;
419
420
if ( ! function_exists( 'lsx_wc_add_to_cart_message_html' ) ) :
421
422
	/**
423
	 * Changes the "added to cart" message HTML.
424
	 *
425
	 * @package    lsx
426
	 * @subpackage woocommerce
427
	 */
428
	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...
429
		$message = '<div class="woocommerce-message-added-to-cart">' . $message . '</div>';
430
		return $message;
431
	}
432
433
	add_filter( 'wc_add_to_cart_message_html', 'lsx_wc_add_to_cart_message_html', 20, 2 );
434
435
endif;
436
437
if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.3', '>=' ) ) {
438
	add_filter( 'woocommerce_add_to_cart_fragments', 'lsx_wc_cart_link_fragment' );
439
} else {
440
	add_filter( 'add_to_cart_fragments', 'lsx_wc_cart_link_fragment' );
441
}
442
443
remove_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 10 );
444
445
add_action( 'woocommerce_after_shop_loop', 'lsx_wc_sorting_wrapper', 9 );
446
add_action( 'woocommerce_after_shop_loop', 'woocommerce_catalog_ordering', 10 );
447
add_action( 'woocommerce_after_shop_loop', 'woocommerce_result_count', 20 );
448
add_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 30 );
449
add_action( 'woocommerce_after_shop_loop', 'lsx_wc_sorting_wrapper_close', 31 );
450
451
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
452
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
453
454
add_action( 'woocommerce_before_shop_loop', 'lsx_wc_sorting_wrapper', 9 );
455
add_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 10 );
456
add_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
457
add_action( 'woocommerce_before_shop_loop', 'lsx_wc_woocommerce_pagination', 30 );
458
add_action( 'woocommerce_before_shop_loop', 'lsx_wc_sorting_wrapper_close', 31 );
459
460
if ( ! function_exists( 'lsx_wc_sorting_wrapper' ) ) :
461
462
	/**
463
	 * Sorting wrapper.
464
	 *
465
	 * @package    lsx
466
	 * @subpackage woocommerce
467
	 */
468
	function lsx_wc_sorting_wrapper() {
469
		echo '<div class="lsx-wc-sorting">';
470
	}
471
472
endif;
473
474
if ( ! function_exists( 'lsx_wc_sorting_wrapper_close' ) ) :
475
476
	/**
477
	 * Sorting wrapper close.
478
	 *
479
	 * @package    lsx
480
	 * @subpackage woocommerce
481
	 */
482
	function lsx_wc_sorting_wrapper_close() {
483
		echo '</div>';
484
	}
485
486
endif;
487
488
if ( ! function_exists( 'lsx_wc_product_columns_wrapper_close' ) ) :
489
490
	/**
491
	 * Product columns wrapper close.
492
	 *
493
	 * @package    lsx
494
	 * @subpackage woocommerce
495
	 */
496
	function lsx_wc_product_columns_wrapper_close() {
497
		echo '</div>';
498
	}
499
500
endif;
501
502
if ( ! function_exists( 'lsx_wc_woocommerce_pagination' ) ) :
503
504
	/**
505
	 * LSX WooCommerce Pagination
506
	 * WooCommerce disables the product pagination inside the woocommerce_product_subcategories() function
507
	 * but since LSX adds pagination before that function is excuted we need a separate function to
508
	 * determine whether or not to display the pagination.
509
	 *
510
	 * @package    lsx
511
	 * @subpackage woocommerce
512
	 */
513
	function lsx_wc_woocommerce_pagination() {
514
		if ( woocommerce_products_will_display() ) {
515
			woocommerce_pagination();
516
		}
517
	}
518
519
endif;
520
521
if ( ! function_exists( 'lsx_customizer_wc_controls' ) ) :
522
523
	/**
524
	 * Returns an array of the core panel.
525
	 *
526
	 * @package    lsx
527
	 * @subpackage customizer
528
	 *
529
	 * @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...
530
	 */
531
	function lsx_customizer_wc_controls( $lsx_controls ) {
532
		$lsx_controls['panels']['lsx-wc'] = array(
533
			'title'       => esc_html__( 'WooCommerce', 'lsx' ),
534
			'description' => esc_html__( 'Change the WooCommerce settings.', 'lsx' ),
535
			'priority'    => 23,
536
		);
537
538
		/**
539
		 * Global.
540
		 */
541
542
		$lsx_controls['sections']['lsx-wc-global'] = array(
543
			'title'       => esc_html__( 'Global', 'lsx' ),
544
			'description' => esc_html__( 'Change the WooCommerce global settings.', 'lsx' ),
545
			'panel'       => 'lsx-wc',
546
			'priority'    => 1,
547
		);
548
549
		$lsx_controls['settings']['lsx_wc_mobile_footer_bar_status'] = array(
550
			'default'           => '1',
551
			'sanitize_callback' => 'lsx_sanitize_checkbox',
552
		);
553
554
		$lsx_controls['fields']['lsx_wc_mobile_footer_bar_status'] = array(
555
			'label'       => esc_html__( 'Footer Bar', 'lsx' ),
556
			'description' => esc_html__( 'Enable the mobile footer bar.', 'lsx' ),
557
			'section'     => 'lsx-wc-global',
558
			'type'        => 'checkbox',
559
			'priority'    => 1,
560
		);
561
562
		/**
563
		 * Cart.
564
		 */
565
566
		$lsx_controls['sections']['lsx-wc-cart'] = array(
567
			'title'       => esc_html__( 'Cart', 'lsx' ),
568
			'description' => esc_html__( 'Change the WooCommerce cart settings.', 'lsx' ),
569
			'panel'       => 'lsx-wc',
570
			'priority'    => 2,
571
		);
572
573
		$lsx_controls['settings']['lsx_header_wc_cart'] = array(
574
			'default'           => false,
575
			'sanitize_callback' => 'lsx_sanitize_checkbox',
576
		);
577
578
		$lsx_controls['fields']['lsx_header_wc_cart'] = array(
579
			'label'       => esc_html__( 'Menu Item', 'lsx' ),
580
			'description' => esc_html__( 'Enable the cart menu item.', 'lsx' ),
581
			'section'     => 'lsx-wc-cart',
582
			'type'        => 'checkbox',
583
			'priority'    => 1,
584
		);
585
586
		return $lsx_controls;
587
	}
588
589
	add_filter( 'lsx_customizer_controls', 'lsx_customizer_wc_controls' );
590
591
endif;
592
593
if ( ! function_exists( 'lsx_wc_footer_bar' ) ) :
594
595
	/**
596
	 * Display WC footer bar.
597
	 *
598
	 * @package    lsx
599
	 * @subpackage woocommerce
600
	 */
601
	function lsx_wc_footer_bar() {
602
		if ( ! empty( get_theme_mod( 'lsx_wc_mobile_footer_bar_status', '1' ) ) ) :
603
			?>
604
			<div class="lsx-wc-footer-bar">
605
				<form role="search" method="get" action="<?php echo esc_url( home_url() ); ?>" class="lsx-wc-footer-bar-form">
606
					<fieldset>
607
						<legend class="screen-reader-text"><?php esc_html_e( 'Search products', 'lsx' ); ?></legend>
608
						<input type="search" name="s" placeholder="<?php esc_attr_e( 'Search products...', 'lsx' ); ?>" class="form-control">
609
					</fieldset>
610
				</form>
611
612
				<ul class="lsx-wc-footer-bar-items">
613
					<li class="lsx-wc-footer-bar-item">
614
						<a href="<?php echo esc_url( home_url() ); ?>" class="lsx-wc-footer-bar-link">
615
							<i class="fa fa-home" aria-hidden="true"></i>
616
							<span><?php esc_html_e( 'Home', 'lsx' ); ?></span>
617
						</a>
618
					</li>
619
620
					<li class="lsx-wc-footer-bar-item">
621
						<a href="<?php echo esc_url( get_permalink( get_option( 'woocommerce_myaccount_page_id' ) ) ); ?>" class="lsx-wc-footer-bar-link">
622
							<i class="fa fa-user" aria-hidden="true"></i>
623
							<span><?php esc_html_e( 'Account', 'lsx' ); ?></span>
624
						</a>
625
					</li>
626
627
					<li class="lsx-wc-footer-bar-item">
628
						<a href="#" class="lsx-wc-footer-bar-link lsx-wc-footer-bar-link-toogle">
629
							<i class="fa fa-search" aria-hidden="true"></i>
630
							<span><?php esc_html_e( 'Search', 'lsx' ); ?></span>
631
						</a>
632
					</li>
633
634
					<li class="lsx-wc-footer-bar-item">
635
						<a href="<?php echo esc_url( WC()->cart->get_cart_url() ); ?>" class="lsx-wc-footer-bar-link">
636
							<i class="fa fa-shopping-basket" aria-hidden="true"></i>
637
							<?php $count = WC()->cart->get_cart_contents_count(); ?>
638
							<?php if ( ! empty( $count ) ) : ?>
639
								<span class="lsx-wc-footer-bar-count"><?php echo wp_kses_data( $count ); ?></span>
640
							<?php endif; ?>
641
							<span><?php esc_html_e( 'Cart', 'lsx' ); ?></span>
642
						</a>
643
					</li>
644
				</ul>
645
			</div>
646
			<?php
647
		endif;
648
	}
649
650
	add_action( 'lsx_body_bottom', 'lsx_wc_footer_bar', 15 );
651
652
endif;
653
654
if ( ! function_exists( 'lsx_wc_body_class' ) ) :
655
656
	/**
657
	 * Changes body class.
658
	 *
659
	 * @package    lsx
660
	 * @subpackage woocommerce
661
	 */
662
	function lsx_wc_body_class( $classes ) {
663
		global $post;
664
665
		if ( $post && class_exists( 'WC_Wishlists_Pages' ) && WC_Wishlists_Pages::is_wishlist_page( $post->post_name ) ) {
666
			$classes[] = 'woocommerce-page woocommerce-wishlist';
667
		}
668
669
		if ( ! empty( get_theme_mod( 'lsx_wc_mobile_footer_bar_status', '1' ) ) ) {
670
			$classes[] = 'lsx-wc-has-footer-bar';
671
		}
672
673
		return $classes;
674
	}
675
676
	add_filter( 'body_class', 'lsx_wc_body_class', 2999 );
677
678
endif;
679
680
if ( ! function_exists( 'lsx_wc_downloadable_products' ) ) :
681
682
	/**
683
	 * Changes downloads "download" button text.
684
	 *
685
	 * @package    lsx
686
	 * @subpackage woocommerce
687
	 */
688
	function lsx_wc_downloadable_products( $downloads ) {
689
		foreach ( $downloads as $i => $download ) {
690
			$downloads[ $i ]['download_name'] = esc_html__( 'Download', 'lsx' );
691
		}
692
693
		return $downloads;
694
	}
695
696
	add_filter( 'woocommerce_customer_get_downloadable_products', 'lsx_wc_downloadable_products', 2999 );
697
698
endif;
699
700
if ( ! function_exists( 'lsx_wc_move_bundle_products' ) ) :
701
702
	/**
703
	 * WooCommerce - Move the bundle products to a tab.
704
	 *
705
	 * @package    lsx
706
	 * @subpackage woocommerce
707
	 */
708
	function lsx_wc_move_bundle_products( $tabs ) {
709
		global $product, $post;
710
711
		if ( method_exists( $product , 'get_bundled_items' ) ) {
712
			$bundled_items = $product->get_bundled_items();
713
714
			if ( ! empty( $bundled_items ) ) {
715
				$tabs['bundled_products'] = array(
716
					'title'    => __( 'Included Products', 'lsx' ),
717
					'priority' => 10,
718
					'callback' => 'lsx_wc_bundle_products',
719
				);
720
			}
721
		}
722
723
		if ( isset( $tabs['description'] ) ) {
724
			$tabs['description']['priority'] = 5;
725
		}
726
727
		if ( isset( $tabs['reviews'] ) ) {
728
			$tabs['reviews']['priority'] = 15;
729
		}
730
731
		if ( isset( $tabs['product_enquiry'] ) ) {
732
			$tabs['product_enquiry']['priority'] = 20;
733
		}
734
735
		return $tabs;
736
	}
737
738
	add_action( 'woocommerce_product_tabs', 'lsx_wc_move_bundle_products', 50 );
739
740
endif;
741
742
if ( ! function_exists( 'lsx_wc_bundle_products' ) ) :
743
744
	function lsx_wc_bundle_products() {
745
		global $product, $post;
746
747
		if ( method_exists( $product , 'get_bundled_items' ) ) {
748
			$bundled_items = $product->get_bundled_items();
749
750
			// do_action( 'woocommerce_before_bundled_items', $product );
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% 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...
751
752
			// foreach ( $bundled_items as $bundled_item ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
753
			// 	do_action( 'woocommerce_bundled_item_details', $bundled_item, $product );
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...
754
			// }
755
756
			// do_action( 'woocommerce_after_bundled_items', $product );
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% 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...
757
758
			$product_original = $product;
759
760
			// $this->widget_start( $args, $instance );
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
761
762
			// @codingStandardsIgnoreLine
763
			echo apply_filters( 'woocommerce_before_widget_product_list', '<ul class="product_list_widget">' );
764
765
			foreach ( $bundled_items as $bundled_item ) {
766
				$product = wc_get_product( $bundled_item->item_data['product_id'] );
767
				wc_get_template( 'content-widget-product.php' );
768
				$product = $product_original;
769
			}
770
771
			// @codingStandardsIgnoreLine
772
			echo apply_filters( 'woocommerce_after_widget_product_list', '</ul>' );
773
		}
774
775
		// $this->widget_end( $args );
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
776
	}
777
778
endif;
779
780
781
if ( ! function_exists( 'lsx_wc_product_searchform' ) ) :
782
	/**
783
	 * woo_custom_product_searchform
784
	 *
785
	 * @access      public
786
	 * @since       1.0
787
	 * @return      void
788
	 */
789
	function lsx_wc_product_searchform( $form ) {
0 ignored issues
show
Unused Code introduced by
The parameter $form 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...
790
791
		$form = '
792
			<form role="search" method="get" class="search-form form-inline" id="searchform" action="<?php echo esc_url( home_url( \'/\' ) ); ?>">
793
				<div class="input-group">
794
					<input type="search" value="<?php if ( is_search() ) { echo get_search_query(); } ?>" name="s" class="search-field form-control" placeholder="<?php esc_attr_e( \'Search\', \'lsx\' ); ?> <?php echo esc_attr( get_bloginfo( \'name\' ) ); ?>">
795
					<label class="hide"><?php esc_attr_e( \'Search for:\', \'lsx\' ); ?></label>
796
			
797
					<span class="input-group-btn">
798
						<button type="submit" class="search-submit btn btn-default"><span class="fa fa-search"></span></button>
799
					</span>
800
				</div>
801
			
802
				<input type="hidden" name="post_type" value="product" />
803
			</form>		
804
		';
805
806
		return $form;
807
808
	}
809
endif;
810
add_filter( 'get_product_search_form' , 'lsx_wc_product_searchform', 10, 1 );
811