Passed
Push — master ( b9d66b...bdff91 )
by Jacques
05:21
created

woocommerce.php ➔ lsx_wc_scripts_add_styles()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 23
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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