Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace order scripts to meta boxes class #10

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions src/UI/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}

Expand Down
19 changes: 13 additions & 6 deletions src/UI/MetaBoxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -87,7 +89,7 @@ public static function noAddressMetaBox(): void
str_replace('<a>', '<a href="'.esc_url($settings_page_url).'">',
sprintf(esc_html__(/* translators: %s: Name of the plugin */ 'Select the correct sending address in <a>the settings</a> plugin named %s',
'cdekdelivery'),
esc_html($pluginName))).
esc_html($pluginName))).
'</p>
</div>';
}
Expand All @@ -104,7 +106,7 @@ public static function noOfficeMetaBox(): void
str_replace('<a>', '<a href="'.esc_url($settings_page_url).'">',
sprintf(esc_html__(/* translators: %s: Name of the plugin */ 'Select the correct sending address in <a>the settings</a> plugin named %s',
'cdekdelivery'),
esc_html($pluginName))).
esc_html($pluginName))).
'</p>
</div>';
}
Expand All @@ -121,7 +123,7 @@ public static function noAuthMetaBox(): void
str_replace('<a>', '<a href="'.esc_url($settings_page_url).'">',
sprintf(esc_html__(/* translators: %s: Name of the plugin */ 'Enter the correct client ID and secret key in <a>the settings</a> plugin named %s',
'cdekdelivery'),
esc_html($pluginName))).
esc_html($pluginName))).
'</p>
</div>';
}
Expand All @@ -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;

Expand Down Expand Up @@ -180,11 +182,16 @@ public static function notAvailableEditOrderData(): void
echo '<div class="notice notice-warning"><p>
<strong>CDEKDelivery:</strong> '.
esc_html__('Editing the order is not available due to a change in the order status in the CDEK system',
'cdekdelivery').
'cdekdelivery').
'
</p></div>';
}

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);
Expand Down
Loading