Completed
Push — update/infinite-scroll-woocomm... ( 927894 )
by Mike
16:41
created

woocommerce.php ➔ jetpack_woocommerce_infinite_scroll_render()   B

Complexity

Conditions 6
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 3
Ratio 21.43 %

Importance

Changes 0
Metric Value
cc 6
eloc 8
nc 3
nop 0
dl 3
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_filter( 'infinite_scroll_settings', 'jetpack_woocommerce_infinite_scroll_settings', 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 View Code Duplication
	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
 * Adjust settings
68
 *
69
 * @param [type] $settings
0 ignored issues
show
Documentation introduced by
The doc-type [type] could not be parsed: Unknown type name "" 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...
70
 * @return void
71
 */
72
function jetpack_woocommerce_infinite_scroll_settings( $settings ) {
73 View Code Duplication
	if ( ! is_shop() && ! is_product_taxonomy() && ! is_product_category() && ! is_product_tag() ) {
74
		return $settings;
75
	}
76
	$settings['posts_per_page'] = absint( apply_filters( 'loop_shop_per_page', wc_get_default_products_per_row() * wc_get_default_product_rows_per_page() ) );
77
	return $settings;
78
}
79