From 8e3382eaa0bc5277f4d6b0dab7fd61a5a3dd44d0 Mon Sep 17 00:00:00 2001 From: Oliver Juhas Date: Fri, 10 Mar 2017 09:08:46 +0100 Subject: [PATCH] Adding WooCommerce 2.7 compatibility Fixes issue #39 --- includes/class-cart-tab-frontend.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/includes/class-cart-tab-frontend.php b/includes/class-cart-tab-frontend.php index cb0d56a..edce8ab 100644 --- a/includes/class-cart-tab-frontend.php +++ b/includes/class-cart-tab-frontend.php @@ -24,10 +24,15 @@ class WooCommerce_Cart_Tab_Frontend { * @since 1.0.0 */ public function __construct() { - add_action( 'wp_enqueue_scripts', array( $this, 'setup_styles' ), 999 ); - add_filter( 'add_to_cart_fragments', array( $this, 'woocommerce_cart_tab_add_to_cart_fragment' ) ); + add_action( 'wp_enqueue_scripts', array( $this, 'setup_styles' ), 999 ); + + if ( version_compare( WC_VERSION, '2.7', '<' ) ) { + add_filter( 'add_to_cart_fragments', array( $this, 'woocommerce_cart_tab_add_to_cart_fragment' ) ); + } else { + add_filter( 'woocommerce_add_to_cart_fragments', array( $this, 'woocommerce_cart_tab_add_to_cart_fragment' ) ); + } - add_action( 'wp_footer', 'woocommerce_cart_tab' ); + add_action( 'wp_footer', 'woocommerce_cart_tab' ); } /** @@ -63,4 +68,7 @@ function woocommerce_cart_tab_add_to_cart_fragment( $fragments ) { endif; -return new WooCommerce_Cart_Tab_Frontend(); +function woocommerce_cart_tab_frontend() { + return new WooCommerce_Cart_Tab_Frontend(); +} +add_action( 'init', 'woocommerce_cart_tab_frontend' );