diff options
author | Anthony G. Basile <blueness@gentoo.org> | 2018-04-10 22:00:23 -0400 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2018-04-10 22:00:23 -0400 |
commit | a9f67089ebcadba2c7392e91d77c1b32a5515c1a (patch) | |
tree | 46d486f0aabbaa08f2ed083e1e65cf05dfcecdb8 /plugins/jetpack/3rd-party/woocommerce.php | |
parent | Update wordpress-mobile-pack 3.3 (diff) | |
download | blogs-gentoo-a9f67089ebcadba2c7392e91d77c1b32a5515c1a.tar.gz blogs-gentoo-a9f67089ebcadba2c7392e91d77c1b32a5515c1a.tar.bz2 blogs-gentoo-a9f67089ebcadba2c7392e91d77c1b32a5515c1a.zip |
Update jetpack 6.0
Diffstat (limited to 'plugins/jetpack/3rd-party/woocommerce.php')
-rw-r--r-- | plugins/jetpack/3rd-party/woocommerce.php | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/plugins/jetpack/3rd-party/woocommerce.php b/plugins/jetpack/3rd-party/woocommerce.php index 44c44489..3ecdb2ab 100644 --- a/plugins/jetpack/3rd-party/woocommerce.php +++ b/plugins/jetpack/3rd-party/woocommerce.php @@ -1,6 +1,27 @@ <?php +/** + * This file contains compatibility functions for WooCommerce to improve Jetpack feature support. + */ +add_action( 'woocommerce_init', 'jetpack_woocommerce_integration' ); + +function jetpack_woocommerce_integration() { + /** + * Double check WooCommerce exists - unlikely to fail due to the hook being used but better safe than sorry. + */ + if ( ! class_exists( 'WooCommerce' ) ) { + return; + } -add_action( 'woocommerce_share', 'jetpack_woocommerce_social_share_icons', 10 ); + add_action( 'woocommerce_share', 'jetpack_woocommerce_social_share_icons', 10 ); + + /** + * Wrap in function exists check since this requires WooCommerce 3.3+. + */ + if ( function_exists( 'wc_get_default_products_per_row' ) ) { + add_filter( 'infinite_scroll_render_callbacks', 'jetpack_woocommerce_infinite_scroll_render_callback', 10 ); + add_action( 'wp_enqueue_scripts', 'jetpack_woocommerce_infinite_scroll_style', 10 ); + } +} /* * Make sure the social sharing icons show up under the product's short description @@ -12,3 +33,43 @@ function jetpack_woocommerce_social_share_icons() { echo sharing_display(); } } + +/** + * Add a callback for WooCommerce product rendering in infinite scroll. + * + * @param array $callbacks + * @return array + */ +function jetpack_woocommerce_infinite_scroll_render_callback( $callbacks ) { + $callbacks[] = 'jetpack_woocommerce_infinite_scroll_render'; + return $callbacks; +} + +/** + * Add a default renderer for WooCommerce products within infinite scroll. + */ +function jetpack_woocommerce_infinite_scroll_render() { + if ( ! is_shop() && ! is_product_taxonomy() && ! is_product_category() && ! is_product_tag() ) { + return; + } + + woocommerce_product_loop_start(); + + while ( have_posts() ) { + the_post(); + wc_get_template_part( 'content', 'product' ); + } + + woocommerce_product_loop_end(); +} + +/** + * Basic styling when infinite scroll is active only. + */ +function jetpack_woocommerce_infinite_scroll_style() { + $custom_css = " + .infinite-scroll .woocommerce-pagination { + display: none; + }"; + wp_add_inline_style( 'woocommerce-layout', $custom_css ); +} |