debug-bar
1 year ago
3rd-party.php
1 year ago
amp.php
3 years ago
atomic.php
2 years ago
bbpress.php
3 years ago
beaverbuilder.php
1 year ago
bitly.php
3 years ago
buddypress.php
5 years ago
class-domain-mapping.php
2 years ago
class-jetpack-bbpress-rest-api.php
2 years ago
class.jetpack-amp-support.php
1 year ago
creative-mail.php
1 year ago
debug-bar.php
5 years ago
jetpack-backup.php
1 year ago
jetpack-boost.php
1 year ago
qtranslate-x.php
2 years ago
vaultpress.php
2 years ago
web-stories.php
1 year ago
woocommerce-services.php
1 year ago
woocommerce.php
1 year ago
wpcom-reader.php
2 years ago
wpml.php
5 years ago
woocommerce.php
137 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 | * Add product post type to Jetpack sitemap while skipping hidden products. |
| 27 | */ |
| 28 | add_filter( 'jetpack_sitemap_post_types', 'jetpack_woocommerce_add_to_sitemap' ); |
| 29 | add_filter( 'jetpack_sitemap_skip_post', 'jetpack_woocommerce_skip_hidden_products_in_sitemap', 10, 2 ); |
| 30 | |
| 31 | /** |
| 32 | * Wrap in function exists check since this requires WooCommerce 3.3+. |
| 33 | */ |
| 34 | if ( function_exists( 'wc_get_default_products_per_row' ) ) { |
| 35 | add_filter( 'infinite_scroll_render_callbacks', 'jetpack_woocommerce_infinite_scroll_render_callback', 10 ); |
| 36 | add_action( 'wp_enqueue_scripts', 'jetpack_woocommerce_infinite_scroll_style', 10 ); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Add product post type to sitemap if Woocommerce is present. |
| 42 | * |
| 43 | * @param array $post_types Array of post types included in sitemap. |
| 44 | */ |
| 45 | function jetpack_woocommerce_add_to_sitemap( $post_types ) { |
| 46 | $post_types[] = 'product'; |
| 47 | |
| 48 | return $post_types; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Skip hidden products when generating the sitemap. |
| 53 | * |
| 54 | * @param bool $skip Whether to skip the post. |
| 55 | * @param WP_Post $post The post object. |
| 56 | */ |
| 57 | function jetpack_woocommerce_skip_hidden_products_in_sitemap( $skip, $post ) { |
| 58 | if ( $post !== null && $post->post_type === 'product' ) { |
| 59 | $product = wc_get_product( $post->ID ); |
| 60 | if ( $product ) { |
| 61 | $skip = ! $product->is_visible(); |
| 62 | } |
| 63 | } |
| 64 | return $skip; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Make sure the social sharing icons show up under the product's short description |
| 69 | */ |
| 70 | function jetpack_woocommerce_social_share_icons() { |
| 71 | if ( function_exists( 'sharing_display' ) ) { |
| 72 | remove_filter( 'the_content', 'sharing_display', 19 ); |
| 73 | remove_filter( 'the_excerpt', 'sharing_display', 19 ); |
| 74 | sharing_display( '', true ); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Remove sharing display from account, cart, and checkout pages in WooCommerce. |
| 80 | */ |
| 81 | function jetpack_woocommerce_remove_share() { |
| 82 | /** |
| 83 | * Double check WooCommerce exists - unlikely to fail due to the hook being used but better safe than sorry. |
| 84 | */ |
| 85 | if ( ! class_exists( 'WooCommerce' ) ) { |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | if ( is_cart() || is_checkout() || is_account_page() ) { |
| 90 | remove_filter( 'the_content', 'sharing_display', 19 ); |
| 91 | if ( class_exists( 'Jetpack_Likes' ) ) { |
| 92 | remove_filter( 'the_content', array( Jetpack_Likes::init(), 'post_likes' ), 30 ); |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | add_action( 'loop_start', 'jetpack_woocommerce_remove_share' ); |
| 97 | |
| 98 | /** |
| 99 | * Add a callback for WooCommerce product rendering in infinite scroll. |
| 100 | * |
| 101 | * @param array $callbacks Array of render callpacks for IS. |
| 102 | * @return array |
| 103 | */ |
| 104 | function jetpack_woocommerce_infinite_scroll_render_callback( $callbacks ) { |
| 105 | $callbacks[] = 'jetpack_woocommerce_infinite_scroll_render'; |
| 106 | return $callbacks; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Add a default renderer for WooCommerce products within infinite scroll. |
| 111 | */ |
| 112 | function jetpack_woocommerce_infinite_scroll_render() { |
| 113 | if ( ! is_shop() && ! is_product_taxonomy() && ! is_product_category() && ! is_product_tag() ) { |
| 114 | return; |
| 115 | } |
| 116 | |
| 117 | woocommerce_product_loop_start(); |
| 118 | |
| 119 | while ( have_posts() ) { |
| 120 | the_post(); |
| 121 | wc_get_template_part( 'content', 'product' ); |
| 122 | } |
| 123 | |
| 124 | woocommerce_product_loop_end(); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Basic styling when infinite scroll is active only. |
| 129 | */ |
| 130 | function jetpack_woocommerce_infinite_scroll_style() { |
| 131 | $custom_css = ' |
| 132 | .infinite-scroll .woocommerce-pagination { |
| 133 | display: none; |
| 134 | }'; |
| 135 | wp_add_inline_style( 'woocommerce-layout', $custom_css ); |
| 136 | } |
| 137 |