maybe_show_ga_pro_notices(); } ); /** * WooCommerce Google Analytics Integration main class. */ class WC_Google_Analytics_Integration { /** @var WC_Google_Analytics_Integration $instance Instance of this class. */ protected static $instance = null; /** * Initialize the plugin. */ public function __construct() { if ( ! class_exists( 'WooCommerce' ) ) { add_action( 'admin_notices', [ $this, 'woocommerce_missing_notice' ] ); return; } // Load plugin text domain add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); // Track completed orders and determine whether the GA Pro notice should be displayed. add_action( 'woocommerce_order_status_completed', array( $this, 'maybe_show_ga_pro_notices' ) ); // Checks which WooCommerce is installed. if ( class_exists( 'WC_Integration' ) && defined( 'WOOCOMMERCE_VERSION' ) && version_compare( WOOCOMMERCE_VERSION, '3.2', '>=' ) ) { include_once 'includes/class-wc-google-analytics.php'; // Register the integration. add_filter( 'woocommerce_integrations', array( $this, 'add_integration' ) ); } else { add_action( 'admin_notices', array( $this, 'woocommerce_missing_notice' ) ); } add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_links' ) ); } /** * Add links on the plugins page (Settings & Support) * * @param array $links Default links * @return array Default + added links */ public function plugin_links( $links ) { $settings_url = add_query_arg( array( 'page' => 'wc-settings', 'tab' => 'integration', 'section' => 'google_analytics', ), admin_url( 'admin.php' ) ); $plugin_links = array( '' . __( 'Settings', 'woocommerce-google-analytics-integration' ) . '', '' . __( 'Support', 'woocommerce-google-analytics-integration' ) . '', ); return array_merge( $plugin_links, $links ); } /** * Return an instance of this class. * * @return WC_Google_Analytics_Integration A single instance of this class. */ public static function get_instance() { // If the single instance hasn't been set, set it now. if ( null == self::$instance ) { self::$instance = new self; } return self::$instance; } /** * Load the plugin text domain for translation. */ public function load_plugin_textdomain() { $locale = apply_filters( 'plugin_locale', get_locale(), 'woocommerce-google-analytics-integration' ); load_textdomain( 'woocommerce-google-analytics-integration', trailingslashit( WP_LANG_DIR ) . 'woocommerce-google-analytics-integration/woocommerce-google-analytics-integration-' . $locale . '.mo' ); load_plugin_textdomain( 'woocommerce-google-analytics-integration', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); } /** * WooCommerce fallback notice. */ public function woocommerce_missing_notice() { echo '
' . sprintf( __( 'WooCommerce Google Analytics depends on the last version of %s to work!', 'woocommerce-google-analytics-integration' ), '' . __( 'WooCommerce', 'woocommerce-google-analytics-integration' ) . '' ) . '