payment_gateways()->get_available_payment_gateways(); if ( locate_template( 'woocommerce/klarna-checkout.php' ) ) { $klarna_checkout_template = locate_template( 'woocommerce/klarna-checkout.php' ); } else { $klarna_checkout_template = KCO_WC_PLUGIN_PATH . '/templates/klarna-checkout.php'; } // Klarna checkout page. if ( array_key_exists( 'kco', $available_gateways ) ) { // If chosen payment method exists. if ( 'kco' === WC()->session->get( 'chosen_payment_method' ) ) { if ( ! isset( $_GET['confirm'] ) ) { $template = $klarna_checkout_template; } } // If chosen payment method does not exist and KCO is the first gateway. if ( null === WC()->session->get( 'chosen_payment_method' ) || '' === WC()->session->get( 'chosen_payment_method' ) ) { reset( $available_gateways ); if ( 'kco' === key( $available_gateways ) ) { if ( ! isset( $_GET['confirm'] ) ) { $template = $klarna_checkout_template; } } } // If another gateway is saved in session, but has since become unavailable. if ( WC()->session->get( 'chosen_payment_method' ) ) { if ( ! array_key_exists( WC()->session->get( 'chosen_payment_method' ), $available_gateways ) ) { reset( $available_gateways ); if ( 'kco' === key( $available_gateways ) ) { if ( ! isset( $_GET['confirm'] ) ) { $template = $klarna_checkout_template; } } } } } } } // Fallback Klarna Order Received, used when WooCommerce checkout form submission fails. if ( 'checkout/thankyou.php' === $template_name ) { if ( isset( $_GET['kco_wc'] ) && 'true' === $_GET['kco_wc'] ) { $template = KCO_WC_PLUGIN_PATH . '/templates/klarna-checkout-order-received.php'; } } return $template; } } Klarna_Checkout_For_WooCommerce_Templates::get_instance();