Completed
Push — add/docker-env-vars ( 4a8926...023c1d )
by
unknown
48:02 queued 36:58
created

woocommerce.php ➔ jetpack_woocommerce_infinite_scroll_render()   B

Complexity

Conditions 6
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 8
nc 3
nop 0
dl 0
loc 14
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file contains compatibility functions for WooCommerce to improve Jetpack feature support.
4
 */
5
add_action( 'woocommerce_init', 'jetpack_woocommerce_integration' );
6
7
function jetpack_woocommerce_integration() {
8
	/**
9
	 * Double check WooCommerce exists - unlikely to fail due to the hook being used but better safe than sorry.
10
	 */
11
	if ( ! class_exists( 'WooCommerce' ) ) {
12
		return;
13
	}
14
15
	add_action( 'woocommerce_share', 'jetpack_woocommerce_social_share_icons', 10 );
16
17
	/**
18
	 * Wrap in function exists check since this requires WooCommerce 3.3+.
19
	 */
20
	if ( function_exists( 'wc_get_default_products_per_row' ) ) {
21
		add_filter( 'infinite_scroll_render_callbacks', 'jetpack_woocommerce_infinite_scroll_render_callback', 10 );
22
		add_action( 'wp_enqueue_scripts', 'jetpack_woocommerce_infinite_scroll_style', 10 );
23
	}
24
}
25
26
/*
27
 * Make sure the social sharing icons show up under the product's short description
28
 */
29
function jetpack_woocommerce_social_share_icons() {
30
	if ( function_exists( 'sharing_display' ) ) {
31
		remove_filter( 'the_content', 'sharing_display', 19 );
32
		remove_filter( 'the_excerpt', 'sharing_display', 19 );
33
		echo sharing_display();
34
	}
35
}
36
37
/**
38
 * Add a callback for WooCommerce product rendering in infinite scroll.
39
 *
40
 * @param array $callbacks
41
 * @return array
42
 */
43
function jetpack_woocommerce_infinite_scroll_render_callback( $callbacks ) {
44
	$callbacks[] = 'jetpack_woocommerce_infinite_scroll_render';
45
	return $callbacks;
46
}
47
48
/**
49
 * Add a default renderer for WooCommerce products within infinite scroll.
50
 */
51
function jetpack_woocommerce_infinite_scroll_render() {
52
	if ( ! is_shop() && ! is_product_taxonomy() && ! is_product_category() && ! is_product_tag() ) {
53
		return;
54
	}
55
56
	woocommerce_product_loop_start();
57
58
	while ( have_posts() ) {
59
		the_post();
60
		wc_get_template_part( 'content', 'product' );
61
	}
62
63
	woocommerce_product_loop_end();
64
}
65
66
/**
67
 * Basic styling when infinite scroll is active only.
68
 */
69
function jetpack_woocommerce_infinite_scroll_style() {
70
	$custom_css = "
71
	.infinite-scroll .woocommerce-pagination {
72
		display: none;
73
	}";
74
	wp_add_inline_style( 'woocommerce-layout', $custom_css );
75
}
76