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
|
|
|
add_action( 'wp_enqueue_scripts', 'jetpack_woocommerce_infinite_scroll_style', 10 ); |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/* |
28
|
|
|
* Make sure the social sharing icons show up under the product's short description |
29
|
|
|
*/ |
30
|
|
|
function jetpack_woocommerce_social_share_icons() { |
31
|
|
|
if ( function_exists( 'sharing_display' ) ) { |
32
|
|
|
remove_filter( 'the_content', 'sharing_display', 19 ); |
33
|
|
|
remove_filter( 'the_excerpt', 'sharing_display', 19 ); |
34
|
|
|
echo sharing_display(); |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Add a callback for WooCommerce product rendering in infinite scroll. |
40
|
|
|
* |
41
|
|
|
* @param array $callbacks |
42
|
|
|
* @return array |
43
|
|
|
*/ |
44
|
|
|
function jetpack_woocommerce_infinite_scroll_render_callback( $callbacks ) { |
45
|
|
|
$callbacks[] = 'jetpack_woocommerce_infinite_scroll_render'; |
46
|
|
|
return $callbacks; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Add a default renderer for WooCommerce products within infinite scroll. |
51
|
|
|
*/ |
52
|
|
|
function jetpack_woocommerce_infinite_scroll_render() { |
53
|
|
View Code Duplication |
if ( ! is_shop() && ! is_product_taxonomy() && ! is_product_category() && ! is_product_tag() ) { |
54
|
|
|
return; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
woocommerce_product_loop_start(); |
58
|
|
|
|
59
|
|
|
while ( have_posts() ) { |
60
|
|
|
the_post(); |
61
|
|
|
wc_get_template_part( 'content', 'product' ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
woocommerce_product_loop_end(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Adjust settings |
69
|
|
|
* |
70
|
|
|
* @param [type] $settings |
|
|
|
|
71
|
|
|
* @return void |
72
|
|
|
*/ |
73
|
|
|
function jetpack_woocommerce_infinite_scroll_settings( $settings ) { |
74
|
|
View Code Duplication |
if ( ! is_shop() && ! is_product_taxonomy() && ! is_product_category() && ! is_product_tag() ) { |
75
|
|
|
return $settings; |
76
|
|
|
} |
77
|
|
|
$settings['posts_per_page'] = absint( apply_filters( 'loop_shop_per_page', wc_get_default_products_per_row() * wc_get_default_product_rows_per_page() ) ); |
78
|
|
|
return $settings; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Basic styling when infinite scroll is active only. |
83
|
|
|
*/ |
84
|
|
|
function jetpack_woocommerce_infinite_scroll_style() { |
85
|
|
|
$custom_css = " |
86
|
|
|
.infinite-scroll .woocommerce-pagination { |
87
|
|
|
display: none; |
88
|
|
|
}"; |
89
|
|
|
wp_add_inline_style( 'woocommerce-layout', $custom_css ); |
90
|
|
|
} |
91
|
|
|
|
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.