From 3017a09028d3988ad166b5d20da7f6aff0f1629d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Kj=C3=A6r=20Rasmussen?= Date: Wed, 17 Jan 2024 12:00:06 +0100 Subject: [PATCH 1/6] =?UTF-8?q?=F0=9F=90=9B=20Check=20if=20admin=20and=20i?= =?UTF-8?q?f=20function=20exists?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/woocommerce/WC_Gateway_Economic_Invoice.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/woocommerce/WC_Gateway_Economic_Invoice.php b/src/woocommerce/WC_Gateway_Economic_Invoice.php index a0a2bb8..d7459ce 100644 --- a/src/woocommerce/WC_Gateway_Economic_Invoice.php +++ b/src/woocommerce/WC_Gateway_Economic_Invoice.php @@ -279,6 +279,10 @@ public function addEanFieldFisplayAdminOrderMeta($order): void public function isSettingsPage() { + if(! is_admin() || ! function_exists('get_current_screen')){ + return false; + } + $currentScreen = get_current_screen(); return $currentScreen->base === 'woocommerce_page_wc-settings' && From d385a0d031eb005bd7cf89e8c795b7de052b351f Mon Sep 17 00:00:00 2001 From: larasmorningtrain Date: Wed, 17 Jan 2024 11:00:46 +0000 Subject: [PATCH 2/6] Fix styling --- src/woocommerce/WC_Gateway_Economic_Invoice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/woocommerce/WC_Gateway_Economic_Invoice.php b/src/woocommerce/WC_Gateway_Economic_Invoice.php index d7459ce..6fea383 100644 --- a/src/woocommerce/WC_Gateway_Economic_Invoice.php +++ b/src/woocommerce/WC_Gateway_Economic_Invoice.php @@ -279,7 +279,7 @@ public function addEanFieldFisplayAdminOrderMeta($order): void public function isSettingsPage() { - if(! is_admin() || ! function_exists('get_current_screen')){ + if (! is_admin() || ! function_exists('get_current_screen')) { return false; } From 3d8ed0a207d1e1b251072cfa100fae2ba4c15121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Kj=C3=A6r=20Rasmussen?= Date: Mon, 29 Jan 2024 11:54:58 +0100 Subject: [PATCH 3/6] =?UTF-8?q?=F0=9F=90=9B=20Fix=20printing=20on=20wrong?= =?UTF-8?q?=20pages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/WoocommerceEconomic.php | 4 ++-- src/woocommerce/OrderService.php | 4 ++-- src/woocommerce/ProductService.php | 7 +++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/WoocommerceEconomic.php b/src/WoocommerceEconomic.php index 284c6ab..196d053 100755 --- a/src/WoocommerceEconomic.php +++ b/src/WoocommerceEconomic.php @@ -11,7 +11,7 @@ public static function init(): void { add_filter('woocommerce_payment_gateways', [self::class, 'registerGateway'], 10, 1); add_action('init', [self::class, 'requireGateway'], 1); - add_action('woocommerce_product_options_general_product_data', [ProductService::class, 'addEconomicProductField']); + add_action('woocommerce_product_options_general_product_data', [ProductService::class, 'addEconomicProductFieldWithWrapper']); add_action('woocommerce_variation_options', [ProductService::class, 'addEconomicProductField']); add_action('woocommerce_save_product_variation', [ProductService::class, 'saveEconomicProductField'], 10, 2); add_action('woocommerce_process_product_meta', [ProductService::class, 'saveEconomicProductField'], 10, 2); @@ -27,6 +27,6 @@ public static function registerGateway($gateways): array public static function requireGateway(): void { - require_once __DIR__.'/woocommerce/WC_Gateway_Economic_Invoice.php'; + require_once __DIR__ . '/Woocommerce/WC_Gateway_Economic_Invoice.php'; } } diff --git a/src/woocommerce/OrderService.php b/src/woocommerce/OrderService.php index 4d31f57..afbfe4c 100644 --- a/src/woocommerce/OrderService.php +++ b/src/woocommerce/OrderService.php @@ -107,9 +107,9 @@ private static function getRecipient(\WC_Order $order, ?VatZone $vatZone): Recip } return Recipient::new( - name: $order->get_shipping_first_name().' '.$order->get_shipping_last_name(), + name: $order->get_shipping_first_name() . ' ' . $order->get_shipping_last_name(), vatZone: $vatZone, - address: $order->get_shipping_address_1().' '.$order->get_shipping_address_2(), + address: $order->get_shipping_address_1() . ' ' . $order->get_shipping_address_2(), zip: $order->get_shipping_postcode(), city: $order->get_shipping_city(), country: $order->get_shipping_country(), diff --git a/src/woocommerce/ProductService.php b/src/woocommerce/ProductService.php index 6c49724..76bc526 100644 --- a/src/woocommerce/ProductService.php +++ b/src/woocommerce/ProductService.php @@ -4,6 +4,13 @@ class ProductService { + public static function addEconomicProductFieldWithWrapper(): void + { + echo ''; + } + public static function addEconomicProductField(): void { woocommerce_wp_text_input([ From 7df06de3d41c52e52cba7bd8bffe167f7aa94eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Kj=C3=A6r=20Rasmussen?= Date: Mon, 29 Jan 2024 11:55:43 +0100 Subject: [PATCH 4/6] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Do=20not=20check=20cur?= =?UTF-8?q?rentscreen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/woocommerce/WC_Gateway_Economic_Invoice.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/woocommerce/WC_Gateway_Economic_Invoice.php b/src/woocommerce/WC_Gateway_Economic_Invoice.php index 6fea383..19f4a0e 100644 --- a/src/woocommerce/WC_Gateway_Economic_Invoice.php +++ b/src/woocommerce/WC_Gateway_Economic_Invoice.php @@ -24,7 +24,7 @@ public function __construct() $this->description = $this->get_option('description'); // This action hook saves the settings - add_action('woocommerce_update_options_payment_gateways_'.$this->id, [$this, 'process_admin_options']); + add_action('woocommerce_update_options_payment_gateways_' . $this->id, [$this, 'process_admin_options']); add_action('woocommerce_new_order', [$this, 'onNewOrder'], 10, 1); add_action('woocommerce_order_status_completed', [$this, 'onOrderCompleted'], 10, 1); @@ -274,19 +274,17 @@ public function eanFieldUpdateOrderMeta($order_id): void public function addEanFieldFisplayAdminOrderMeta($order): void { - echo '

'.__('EAN nummer', 'woocommerce').': '.get_post_meta($order->get_id(), 'economic_billing_ean', true).'

'; + echo '

' . __('EAN nummer', 'woocommerce') . ': ' . get_post_meta($order->get_id(), 'economic_billing_ean', true) . '

'; } public function isSettingsPage() { - if (! is_admin() || ! function_exists('get_current_screen')) { + if (! is_admin()) { return false; } - $currentScreen = get_current_screen(); - - return $currentScreen->base === 'woocommerce_page_wc-settings' && - isset($_GET['tab']) && $_GET['tab'] === 'checkout' && - isset($_GET['section']) && $_GET['section'] === 'economic_invoice'; + return ! empty($_GET['page']) && $_GET['page'] === 'wc-settings' && + ! empty($_GET['tab']) && $_GET['tab'] === 'checkout' && + ! empty($_GET['section']) && $_GET['section'] === 'economic_invoice'; } } From a6728fa630117463808ba5242aa3c2e577a95448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Kj=C3=A6r=20Rasmussen?= Date: Mon, 29 Jan 2024 11:57:30 +0100 Subject: [PATCH 5/6] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Make=20Woocoomerce=20u?= =?UTF-8?q?ppercase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/{woocommerce => Woocommerce}/OrderService.php | 0 src/{woocommerce => Woocommerce}/ProductService.php | 0 src/{woocommerce => Woocommerce}/WC_Gateway_Economic_Invoice.php | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename src/{woocommerce => Woocommerce}/OrderService.php (100%) rename src/{woocommerce => Woocommerce}/ProductService.php (100%) rename src/{woocommerce => Woocommerce}/WC_Gateway_Economic_Invoice.php (100%) diff --git a/src/woocommerce/OrderService.php b/src/Woocommerce/OrderService.php similarity index 100% rename from src/woocommerce/OrderService.php rename to src/Woocommerce/OrderService.php diff --git a/src/woocommerce/ProductService.php b/src/Woocommerce/ProductService.php similarity index 100% rename from src/woocommerce/ProductService.php rename to src/Woocommerce/ProductService.php diff --git a/src/woocommerce/WC_Gateway_Economic_Invoice.php b/src/Woocommerce/WC_Gateway_Economic_Invoice.php similarity index 100% rename from src/woocommerce/WC_Gateway_Economic_Invoice.php rename to src/Woocommerce/WC_Gateway_Economic_Invoice.php From 24bb1a0dce578755459ee38159751d4a7386fb2f Mon Sep 17 00:00:00 2001 From: larasmorningtrain Date: Mon, 29 Jan 2024 10:58:06 +0000 Subject: [PATCH 6/6] Fix styling --- src/Woocommerce/OrderService.php | 4 ++-- src/Woocommerce/WC_Gateway_Economic_Invoice.php | 4 ++-- src/WoocommerceEconomic.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Woocommerce/OrderService.php b/src/Woocommerce/OrderService.php index afbfe4c..4d31f57 100644 --- a/src/Woocommerce/OrderService.php +++ b/src/Woocommerce/OrderService.php @@ -107,9 +107,9 @@ private static function getRecipient(\WC_Order $order, ?VatZone $vatZone): Recip } return Recipient::new( - name: $order->get_shipping_first_name() . ' ' . $order->get_shipping_last_name(), + name: $order->get_shipping_first_name().' '.$order->get_shipping_last_name(), vatZone: $vatZone, - address: $order->get_shipping_address_1() . ' ' . $order->get_shipping_address_2(), + address: $order->get_shipping_address_1().' '.$order->get_shipping_address_2(), zip: $order->get_shipping_postcode(), city: $order->get_shipping_city(), country: $order->get_shipping_country(), diff --git a/src/Woocommerce/WC_Gateway_Economic_Invoice.php b/src/Woocommerce/WC_Gateway_Economic_Invoice.php index 19f4a0e..6eebba1 100644 --- a/src/Woocommerce/WC_Gateway_Economic_Invoice.php +++ b/src/Woocommerce/WC_Gateway_Economic_Invoice.php @@ -24,7 +24,7 @@ public function __construct() $this->description = $this->get_option('description'); // This action hook saves the settings - add_action('woocommerce_update_options_payment_gateways_' . $this->id, [$this, 'process_admin_options']); + add_action('woocommerce_update_options_payment_gateways_'.$this->id, [$this, 'process_admin_options']); add_action('woocommerce_new_order', [$this, 'onNewOrder'], 10, 1); add_action('woocommerce_order_status_completed', [$this, 'onOrderCompleted'], 10, 1); @@ -274,7 +274,7 @@ public function eanFieldUpdateOrderMeta($order_id): void public function addEanFieldFisplayAdminOrderMeta($order): void { - echo '

' . __('EAN nummer', 'woocommerce') . ': ' . get_post_meta($order->get_id(), 'economic_billing_ean', true) . '

'; + echo '

'.__('EAN nummer', 'woocommerce').': '.get_post_meta($order->get_id(), 'economic_billing_ean', true).'

'; } public function isSettingsPage() diff --git a/src/WoocommerceEconomic.php b/src/WoocommerceEconomic.php index 196d053..8e2d736 100755 --- a/src/WoocommerceEconomic.php +++ b/src/WoocommerceEconomic.php @@ -27,6 +27,6 @@ public static function registerGateway($gateways): array public static function requireGateway(): void { - require_once __DIR__ . '/Woocommerce/WC_Gateway_Economic_Invoice.php'; + require_once __DIR__.'/Woocommerce/WC_Gateway_Economic_Invoice.php'; } }