Skip to content

Commit

Permalink
🚧 Only make requests on settings tab
Browse files Browse the repository at this point in the history
  • Loading branch information
larasmorningtrain committed Jan 17, 2024
1 parent 6dbc7cf commit 35adeba
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/woocommerce/WC_Gateway_Economic_Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -194,27 +194,43 @@ public function onOrderCompleted(int $orderId): void

private function getLayouts(): array
{
if(! $this->isSettingsPage()){
return [];
}

return Layout::all()->mapWithKeys(function ($layout) {
return [$layout->layoutNumber => $layout->name];
})->toArray();
}

private function getPaymentTerms()
{
if(! $this->isSettingsPage()){
return [];
}

return PaymentTerm::all()->mapWithKeys(function ($paymentTerm) {
return [$paymentTerm->paymentTermsNumber => $paymentTerm->name];
})->toArray();
}

private function getVatZones()
{
if(! $this->isSettingsPage()){
return [];
}

return VatZone::all()->mapWithKeys(function ($vatZone) {
return [$vatZone->vatZoneNumber => $vatZone->name];
})->toArray();
}

private function getCustomerGroup()
{
if(! $this->isSettingsPage()){
return [];
}

return CustomerGroup::all()->mapWithKeys(function ($customerGroup) {
return [$customerGroup->customerGroupNumber => $customerGroup->name];
})->toArray();
Expand Down Expand Up @@ -258,6 +274,16 @@ public function eanFieldUpdateOrderMeta($order_id): void

public function addEanFieldFisplayAdminOrderMeta($order): void
{
echo '<p><strong>'.__('EAN nummer', 'woocommerce').':</strong> '.get_post_meta($order->get_id(), 'economic_billing_ean', true).'</p>';
echo '<p><strong>' . __('EAN nummer', 'woocommerce') . ':</strong> ' . get_post_meta($order->get_id(), 'economic_billing_ean', true) . '</p>';
}

function isSettingsPage() {
$currentScreen = get_current_screen();

return $currentScreen->base === 'woocommerce_page_wc-settings' &&
isset($_GET['tab']) && $_GET['tab'] === 'checkout' &&
isset($_GET['section']) && $_GET['section'] === 'economic_invoice';
}


}

0 comments on commit 35adeba

Please sign in to comment.