From 88f038913efa830a7b2993994977709b9d8dd4ba Mon Sep 17 00:00:00 2001
From: Stas Demin
Date: Mon, 17 Jun 2024 11:49:58 +0300
Subject: [PATCH] fix: replace order scripts to meta boxes class
---
src/UI/Admin.php | 14 --------------
src/UI/MetaBoxes.php | 19 +++++++++++++------
2 files changed, 13 insertions(+), 20 deletions(-)
diff --git a/src/UI/Admin.php b/src/UI/Admin.php
index 715c837..56f576d 100644
--- a/src/UI/Admin.php
+++ b/src/UI/Admin.php
@@ -63,23 +63,9 @@ public static function registerAdminScripts(): void
]);
}
- public static function registerOrderScripts(): void
- {
- global $plugin_page, $pagenow;
-
- // Not on an Orders page.
- if ('admin.php' !== $pagenow || 0 !== strpos($plugin_page, 'wc-orders')) {
- return;
- }
-
- Helper::enqueueScript('cdek-admin-create-order', 'cdek-create-order', true);
- }
-
public function __invoke(): void
{
add_action('load-woocommerce_page_wc-settings', [__CLASS__, 'registerAdminScripts']);
-
- add_action('admin_enqueue_scripts', [__CLASS__, 'registerOrderScripts']);
}
}
diff --git a/src/UI/MetaBoxes.php b/src/UI/MetaBoxes.php
index 250b595..1648742 100644
--- a/src/UI/MetaBoxes.php
+++ b/src/UI/MetaBoxes.php
@@ -34,6 +34,8 @@ public static function registerMetaBoxes(string $post_type, $post): void
return;
}
+ add_action('admin_enqueue_scripts', [__CLASS__, 'registerOrderScripts']);
+
$cdekMethod = CheckoutHelper::getOrderShippingMethod($order);
$selectedTariff = (int) ($cdekMethod->get_meta(MetaKeys::TARIFF_CODE) ?:
$cdekMethod->get_meta('tariff_code'));
@@ -87,7 +89,7 @@ public static function noAddressMetaBox(): void
str_replace('', '',
sprintf(esc_html__(/* translators: %s: Name of the plugin */ 'Select the correct sending address in the settings plugin named %s',
'cdekdelivery'),
- esc_html($pluginName))).
+ esc_html($pluginName))).
'
';
}
@@ -104,7 +106,7 @@ public static function noOfficeMetaBox(): void
str_replace('', '',
sprintf(esc_html__(/* translators: %s: Name of the plugin */ 'Select the correct sending address in the settings plugin named %s',
'cdekdelivery'),
- esc_html($pluginName))).
+ esc_html($pluginName))).
'
';
}
@@ -121,7 +123,7 @@ public static function noAuthMetaBox(): void
str_replace('', '',
sprintf(esc_html__(/* translators: %s: Name of the plugin */ 'Enter the correct client ID and secret key in the settings plugin named %s',
'cdekdelivery'),
- esc_html($pluginName))).
+ esc_html($pluginName))).
'
';
}
@@ -144,8 +146,8 @@ public static function createOrderMetaBox($post): void
$shipping = CheckoutHelper::getOrderShippingMethod($order);
$hasPackages
- = Helper::getActualShippingMethod($shipping->get_data()['instance_id'])
- ->get_option('has_packages_mode') === 'yes';
+ = Helper::getActualShippingMethod($shipping->get_data()['instance_id'])
+ ->get_option('has_packages_mode') === 'yes';
$orderNumber = $orderData['order_number'] ?? null;
$orderUuid = $orderData['order_uuid'] ?? null;
@@ -180,11 +182,16 @@ public static function notAvailableEditOrderData(): void
echo '
CDEKDelivery: '.
esc_html__('Editing the order is not available due to a change in the order status in the CDEK system',
- 'cdekdelivery').
+ 'cdekdelivery').
'
';
}
+ public static function registerOrderScripts(): void
+ {
+ Helper::enqueueScript('cdek-admin-create-order', 'cdek-create-order', true);
+ }
+
public function __invoke(): void
{
add_action('add_meta_boxes', [__CLASS__, 'registerMetaBoxes'], 100, 2);