. */ if ( ! defined( 'ABSPATH' ) ) { exit; } /** * Required minimums and constants */ define( 'KCO_WC_VERSION', '1.5.2' ); define( 'KCO_WC_MIN_PHP_VER', '5.3.0' ); define( 'KCO_WC_MIN_WC_VER', '2.5.0' ); define( 'KCO_WC_MAIN_FILE', __FILE__ ); define( 'KCO_WC_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); define( 'KCO_WC_PLUGIN_URL', untrailingslashit( plugin_dir_url( __FILE__ ) ) ); define( 'KROKEDIL_LOGGER_GATEWAY', 'kco' ); if ( ! class_exists( 'Klarna_Checkout_For_WooCommerce' ) ) { /** * Class Klarna_Checkout_For_WooCommerce */ class Klarna_Checkout_For_WooCommerce { /** * The reference the *Singleton* instance of this class. * * @var $instance */ protected static $instance; /** * Reference to API class. * * @var $api */ public $api; /** * Reference to merchant URLs class. * * @var $merchant_urls */ public $merchant_urls; /** * Reference to order lines class. * * @var $order_lines */ public $order_lines; /** * Reference to credentials class. * * @var $credentials */ public $credentials; /** * Reference to logging class. * * @var $log */ public $logger; /** * Returns the *Singleton* instance of this class. * * @return self::$instance The *Singleton* instance. */ public static function get_instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } /** * Private clone method to prevent cloning of the instance of the * *Singleton* instance. * * @return void */ private function __clone() { wc_doing_it_wrong( __FUNCTION__, __( 'Nope' ), '1.0' ); } /** * Private unserialize method to prevent unserializing of the *Singleton* * instance. * * @return void */ private function __wakeup() { wc_doing_it_wrong( __FUNCTION__, __( 'Nope' ), '1.0' ); } /** * Notices (array) * * @var array */ public $notices = array(); /** * Protected constructor to prevent creating a new instance of the * *Singleton* via the `new` operator from outside of this class. */ protected function __construct() { add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 ); add_action( 'plugins_loaded', array( $this, 'init' ) ); add_action( 'admin_notices', array( $this, 'order_management_check' ) ); // Add quantity button in woocommerce_order_review() function. add_filter( 'woocommerce_checkout_cart_item_quantity', array( $this, 'add_quantity_field' ), 10, 3 ); $KCO_options = get_option( 'woocommerce_kco_settings' ); if ( 'yes' === $KCO_options['logging'] ) { define( 'KROKEDIL_LOGGER_ON', true ); } } /** * Init the plugin after plugins_loaded so environment variables are set. */ public function init() { // Init the gateway itself. $this->init_gateways(); add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); } /** * Adds plugin action links * * @param array $links Plugin action link before filtering. * * @return array Filtered links. */ public function plugin_action_links( $links ) { $setting_link = $this->get_setting_link(); $plugin_links = array( '' . __( 'Settings', 'klarna-checkout-for-woocommerce' ) . '', '' . __( 'Support', 'klarna-checkout-for-woocommerce' ) . '', ); return array_merge( $plugin_links, $links ); } /** * Get setting link. * * @since 1.0.0 * * @return string Setting link */ public function get_setting_link() { $section_slug = 'kco'; return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug ); } /** * Show admin notice if Order Management plugin is not active. */ public function order_management_check() { /** * Check if file exists * - yes: check if activated * - yes: all good * - no: show activate button * - no: show install button */ $plugin_slug = 'klarna-order-management-for-woocommerce'; // If plugin file exists. if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_slug . '/' . $plugin_slug . '.php' ) ) { // If plugin is not active show Activate button. if ( ! is_plugin_active( $plugin_slug . '/' . $plugin_slug . '.php' ) && current_user_can( 'activate_plugins' ) ) { include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; $plugin = plugins_api( 'plugin_information', array( 'slug' => $plugin_slug, ) ); $plugin = (array) $plugin; $status = install_plugin_install_status( $plugin ); $name = wp_kses( $plugin['name'], array() ); $url = add_query_arg( array( '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $status['file'] ), 'action' => 'activate', 'plugin' => $status['file'], ), network_admin_url( 'plugins.php' ) ); $description = $name . ' is not active. Please activate it so you can capture, cancel, update and refund Klarna orders.'; ?>
$plugin_slug, ) ); $plugin = (array) $plugin; $status = install_plugin_install_status( $plugin ); if ( 'install' === $status['status'] && $status['url'] ) { $name = wp_kses( $plugin['name'], array() ); $url = $status['url']; $description = $name . ' is not installed. Please install and activate it so you can capture, cancel, update and refund Klarna orders.'; ?> notices as $notice_key => $notice ) { echo ""; echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); echo '