|
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
|
|
|
* Remove sharing display from account, cart, and checkout pages in WooCommerce. |
|
39
|
|
|
*/ |
|
40
|
|
|
function jetpack_woocommerce_remove_share() { |
|
41
|
|
|
/** |
|
42
|
|
|
* Double check WooCommerce exists - unlikely to fail due to the hook being used but better safe than sorry. |
|
43
|
|
|
*/ |
|
44
|
|
|
if ( ! class_exists( 'WooCommerce' ) ) { |
|
45
|
|
|
return; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
if ( is_cart() || is_checkout() || is_account_page() ) { |
|
49
|
|
|
remove_filter( 'the_content', 'sharing_display', 19 ); |
|
50
|
|
|
if ( class_exists( 'Jetpack_Likes' ) ) { |
|
51
|
|
|
remove_filter( 'the_content', array( Jetpack_Likes::init(), 'post_likes' ), 30, 1 ); |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
add_action( 'loop_start', 'jetpack_woocommerce_remove_share' ); |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Add a callback for WooCommerce product rendering in infinite scroll. |
|
59
|
|
|
* |
|
60
|
|
|
* @param array $callbacks |
|
61
|
|
|
* @return array |
|
62
|
|
|
*/ |
|
63
|
|
|
function jetpack_woocommerce_infinite_scroll_render_callback( $callbacks ) { |
|
64
|
|
|
$callbacks[] = 'jetpack_woocommerce_infinite_scroll_render'; |
|
65
|
|
|
return $callbacks; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Add a default renderer for WooCommerce products within infinite scroll. |
|
70
|
|
|
*/ |
|
71
|
|
|
function jetpack_woocommerce_infinite_scroll_render() { |
|
72
|
|
|
if ( ! is_shop() && ! is_product_taxonomy() && ! is_product_category() && ! is_product_tag() ) { |
|
73
|
|
|
return; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
woocommerce_product_loop_start(); |
|
77
|
|
|
|
|
78
|
|
|
while ( have_posts() ) { |
|
79
|
|
|
the_post(); |
|
80
|
|
|
wc_get_template_part( 'content', 'product' ); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
woocommerce_product_loop_end(); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Basic styling when infinite scroll is active only. |
|
88
|
|
|
*/ |
|
89
|
|
|
function jetpack_woocommerce_infinite_scroll_style() { |
|
90
|
|
|
$custom_css = " |
|
91
|
|
|
.infinite-scroll .woocommerce-pagination { |
|
92
|
|
|
display: none; |
|
93
|
|
|
}"; |
|
94
|
|
|
wp_add_inline_style( 'woocommerce-layout', $custom_css ); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
function jetpack_woocommerce_lazy_images_compat() { |
|
98
|
|
|
wp_add_inline_script( 'wc-cart-fragments', " |
|
99
|
|
|
jQuery( 'body' ).bind( 'wc_fragments_refreshed', function() { |
|
100
|
|
|
var jetpackLazyImagesLoadEvent; |
|
101
|
|
|
try { |
|
102
|
|
|
jetpackLazyImagesLoadEvent = new Event( 'jetpack-lazy-images-load', { |
|
103
|
|
|
bubbles: true, |
|
104
|
|
|
cancelable: true |
|
105
|
|
|
} ); |
|
106
|
|
|
} catch ( e ) { |
|
107
|
|
|
jetpackLazyImagesLoadEvent = document.createEvent( 'Event' ) |
|
108
|
|
|
jetpackLazyImagesLoadEvent.initEvent( 'jetpack-lazy-images-load', true, true ); |
|
109
|
|
|
} |
|
110
|
|
|
jQuery( 'body' ).get( 0 ).dispatchEvent( jetpackLazyImagesLoadEvent ); |
|
111
|
|
|
} ); |
|
112
|
|
|
" ); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
add_action( 'wp_enqueue_scripts', 'jetpack_woocommerce_lazy_images_compat', 11 ); |
|
116
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.