FILE ) { throw new Exception( 'FILE needs to be initialized' ); } $this->register_autoloader(); register_activation_hook( $this->FILE, [ $this, 'on_activate', ] ); if ( !self::$logger ) { self::$logger = new Advertikon_Library_Log(); } Advertikon_Library_Renderer_Admin::init(); } protected function register_autoloader() { spl_autoload_register( [ $this, 'autoload', ] ); } protected function autoload( $name ) { if ( !$this->class_prefix ) { throw new Exception( 'Class prefix needs to be defined' ); } if ( 0 === strpos( $name, $this->class_prefix ) ) { $classes_dir = realpath( plugin_dir_path( $this->FILE ) ); $class_file = strtolower( str_replace( '_', DIRECTORY_SEPARATOR, substr( $name, strlen( $this->class_prefix ) ) ) . '.php' ); if ( !is_file( $classes_dir . $class_file ) ) { return false; } require_once $classes_dir . $class_file; } if ( 0 === strpos( $name, 'Advertikon_Library' ) ) { $classes_dir = realpath( plugin_dir_path( $this->FILE ) ); $class_file = strtolower( str_replace( '_', DIRECTORY_SEPARATOR, substr( $name, 10 ) ) . '.php' ); if ( !is_file( $classes_dir . $class_file ) ) { return false; } require_once $classes_dir . $class_file; } } public function on_activate() { if( !is_plugin_active( 'woocommerce/woocommerce.php' ) ) { throw new Exception( sprintf( __( 'Plugin "%s" requires "WooCommerce" to be installed', $this->ln ), $this->name ) ); } } public static function log( $message, $severity = Advertikon_Library_Log::LEVEL_NORMAL ) { self::$logger->log( $message, '', $severity ); } public static function error( $message ) { self::log( $message, Advertikon_Library_Log::LEVEL_ERROR ); } public static function get_logger() { if ( !self::$logger ) { self::$logger = new Advertikon_Library_Log(); } return self::$logger; } /** * Returns free shipping objects for current car * * @return WC_Shipping_Free_Shipping[] */ public function get_free_shipping() { $ret = array(); if( WC()->cart ) { foreach( WC()->cart->get_shipping_packages() as $package ) { $shipping_zone = WC_Shipping_Zones::get_zone_matching_package( $package ); $shipping_methods = $shipping_zone->get_shipping_methods( true ); foreach( $shipping_methods as $method ) { if ( 'free_shipping' === $method->id ) { $ret[] = $method; } } } } return $ret; } } if ( !function_exists( 'ADK' ) ) { /** * Returns plugin main instance * @param string $code Plaugin code * @return Advertikon */ function ADK( $code = null ) { if ( is_null( $code ) || !isset( Advertikon::$instances[ $code ] ) ) { return Advertikon::$instances['default']; } return Advertikon::$instances[ $code ]; } }