diff --git a/includes/class-wc-gateway-komoju-block.php b/includes/class-wc-gateway-komoju-block.php index 572755e..7e61541 100644 --- a/includes/class-wc-gateway-komoju-block.php +++ b/includes/class-wc-gateway-komoju-block.php @@ -45,6 +45,10 @@ public function get_payment_method_script_handles() public function get_payment_method_data() { + if (!is_admin() && (is_null(WC()->cart) || WC()->cart->is_empty())) { + return; + } + // We lazily fetch one session to be shared by all payment methods with dynamic fields. static $checkout_session; if (is_null($checkout_session)) { diff --git a/includes/class-wc-gateway-komoju-single-slug.php b/includes/class-wc-gateway-komoju-single-slug.php index 0950919..dbd79ce 100644 --- a/includes/class-wc-gateway-komoju-single-slug.php +++ b/includes/class-wc-gateway-komoju-single-slug.php @@ -131,8 +131,14 @@ public function create_session_for_fields() { $komoju_api = $this->komoju_api; $currency = get_woocommerce_currency(); + $order_total = 0; + + if (WC()->cart) { + $order_total = $this->get_order_total(); + } + $session_params = [ - 'amount' => self::to_cents($this->get_order_total(), $currency), + 'amount' => self::to_cents($order_total, $currency), 'currency' => $currency, 'default_locale' => self::get_locale_or_fallback(), 'metadata' => [ @@ -140,7 +146,7 @@ public function create_session_for_fields() ], ]; - if ($this->get_order_total() == 0) { + if ($order_total == 0) { return null; } diff --git a/index.php b/index.php index ca7f291..01c00f5 100755 --- a/index.php +++ b/index.php @@ -1,4 +1,7 @@ payment_gateways()->payment_gateways(); if ($gateways) { @@ -140,6 +143,7 @@ function ($payment_method_registry) { } } } - }); + } + ); } } diff --git a/uninstall.php b/uninstall.php index 5c98486..97a6734 100755 --- a/uninstall.php +++ b/uninstall.php @@ -1,4 +1,5 @@