debug-bar
5 years ago
3rd-party.php
5 years ago
bbpress.php
5 years ago
beaverbuilder.php
5 years ago
bitly.php
5 years ago
buddypress.php
5 years ago
class-domain-mapping.php
5 years ago
class-jetpack-bbpress-rest-api.php
5 years ago
class-jetpack-crm-data.php
5 years ago
class-jetpack-modules-overrides.php
5 years ago
class.jetpack-amp-support.php
5 years ago
creative-mail.php
5 years ago
crowdsignal.php
5 years ago
debug-bar.php
5 years ago
qtranslate-x.php
5 years ago
vaultpress.php
5 years ago
web-stories.php
5 years ago
woocommerce-services.php
5 years ago
woocommerce.php
5 years ago
wpml.php
5 years ago
woocommerce.php
130 lines
| 1 | <?php |
| 2 | /** |
| 3 | * This file contains compatibility functions for WooCommerce to improve Jetpack feature support. |
| 4 | * |
| 5 | * @package automattic/jetpack |
| 6 | */ |
| 7 | |
| 8 | add_action( 'woocommerce_init', 'jetpack_woocommerce_integration' ); |
| 9 | |
| 10 | /** |
| 11 | * Loads JP+WC integration. |
| 12 | * |
| 13 | * Fires on `woocommerce_init` hook |
| 14 | */ |
| 15 | function jetpack_woocommerce_integration() { |
| 16 | /** |
| 17 | * Double check WooCommerce exists - unlikely to fail due to the hook being used but better safe than sorry. |
| 18 | */ |
| 19 | if ( ! class_exists( 'WooCommerce' ) ) { |
| 20 | return; |
| 21 | } |
| 22 | |
| 23 | add_action( 'woocommerce_share', 'jetpack_woocommerce_social_share_icons', 10 ); |
| 24 | |
| 25 | /** |
| 26 | * Wrap in function exists check since this requires WooCommerce 3.3+. |
| 27 | */ |
| 28 | if ( function_exists( 'wc_get_default_products_per_row' ) ) { |
| 29 | add_filter( 'infinite_scroll_render_callbacks', 'jetpack_woocommerce_infinite_scroll_render_callback', 10 ); |
| 30 | add_action( 'wp_enqueue_scripts', 'jetpack_woocommerce_infinite_scroll_style', 10 ); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Make sure the social sharing icons show up under the product's short description |
| 36 | */ |
| 37 | function jetpack_woocommerce_social_share_icons() { |
| 38 | if ( function_exists( 'sharing_display' ) ) { |
| 39 | remove_filter( 'the_content', 'sharing_display', 19 ); |
| 40 | remove_filter( 'the_excerpt', 'sharing_display', 19 ); |
| 41 | sharing_display( '', true ); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Remove sharing display from account, cart, and checkout pages in WooCommerce. |
| 47 | */ |
| 48 | function jetpack_woocommerce_remove_share() { |
| 49 | /** |
| 50 | * Double check WooCommerce exists - unlikely to fail due to the hook being used but better safe than sorry. |
| 51 | */ |
| 52 | if ( ! class_exists( 'WooCommerce' ) ) { |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | if ( is_cart() || is_checkout() || is_account_page() ) { |
| 57 | remove_filter( 'the_content', 'sharing_display', 19 ); |
| 58 | if ( class_exists( 'Jetpack_Likes' ) ) { |
| 59 | remove_filter( 'the_content', array( Jetpack_Likes::init(), 'post_likes' ), 30, 1 ); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | add_action( 'loop_start', 'jetpack_woocommerce_remove_share' ); |
| 64 | |
| 65 | /** |
| 66 | * Add a callback for WooCommerce product rendering in infinite scroll. |
| 67 | * |
| 68 | * @param array $callbacks Array of render callpacks for IS. |
| 69 | * @return array |
| 70 | */ |
| 71 | function jetpack_woocommerce_infinite_scroll_render_callback( $callbacks ) { |
| 72 | $callbacks[] = 'jetpack_woocommerce_infinite_scroll_render'; |
| 73 | return $callbacks; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Add a default renderer for WooCommerce products within infinite scroll. |
| 78 | */ |
| 79 | function jetpack_woocommerce_infinite_scroll_render() { |
| 80 | if ( ! is_shop() && ! is_product_taxonomy() && ! is_product_category() && ! is_product_tag() ) { |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | woocommerce_product_loop_start(); |
| 85 | |
| 86 | while ( have_posts() ) { |
| 87 | the_post(); |
| 88 | wc_get_template_part( 'content', 'product' ); |
| 89 | } |
| 90 | |
| 91 | woocommerce_product_loop_end(); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Basic styling when infinite scroll is active only. |
| 96 | */ |
| 97 | function jetpack_woocommerce_infinite_scroll_style() { |
| 98 | $custom_css = ' |
| 99 | .infinite-scroll .woocommerce-pagination { |
| 100 | display: none; |
| 101 | }'; |
| 102 | wp_add_inline_style( 'woocommerce-layout', $custom_css ); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Adds compat for WooCommerce and Lazy Loading. |
| 107 | */ |
| 108 | function jetpack_woocommerce_lazy_images_compat() { |
| 109 | wp_add_inline_script( |
| 110 | 'wc-cart-fragments', |
| 111 | " |
| 112 | jQuery( 'body' ).bind( 'wc_fragments_refreshed', function() { |
| 113 | var jetpackLazyImagesLoadEvent; |
| 114 | try { |
| 115 | jetpackLazyImagesLoadEvent = new Event( 'jetpack-lazy-images-load', { |
| 116 | bubbles: true, |
| 117 | cancelable: true |
| 118 | } ); |
| 119 | } catch ( e ) { |
| 120 | jetpackLazyImagesLoadEvent = document.createEvent( 'Event' ) |
| 121 | jetpackLazyImagesLoadEvent.initEvent( 'jetpack-lazy-images-load', true, true ); |
| 122 | } |
| 123 | jQuery( 'body' ).get( 0 ).dispatchEvent( jetpackLazyImagesLoadEvent ); |
| 124 | } ); |
| 125 | " |
| 126 | ); |
| 127 | } |
| 128 | |
| 129 | add_action( 'wp_enqueue_scripts', 'jetpack_woocommerce_lazy_images_compat', 11 ); |
| 130 |