id !== $orderScreen) { return null; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended $id = absint($_GET['id'] ?? ($_GET['post'] ?? 0)); $order = $id ? wc_get_order($id) : null; return $order instanceof WC_Order && PickupSelect_Plugin::order_uses_pickupselect($order) && self::can_edit($order) ? $order : null; } private static function can_edit(WC_Order $order): bool { return current_user_can('edit_shop_orders') || current_user_can('edit_post', $order->get_id()); } // a pont doboz gombjai (PickupSelect_Order_Display::admin hívja) public static function buttons(WC_Order $order, bool $hasPoint): void { if (!self::can_edit($order)) { return; } ?>

true]); wp_enqueue_script('pickupselect-admin-order', PICKUPSELECT_URL . 'assets/js/pickupselect-admin-order.js', ['pickupselect-widget'], PICKUPSELECT_VERSION, ['in_footer' => true]); wp_enqueue_style('pickupselect-admin', PICKUPSELECT_URL . 'assets/css/pickupselect-admin.css', [], PICKUPSELECT_VERSION); wp_localize_script('pickupselect-admin-order', 'pickupselectAdminOrder', [ 'ajaxUrl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce(self::NONCE), 'orderId' => $order->get_id(), 'apiKey' => (string) get_option('pickupselect_api_key', ''), 'widgetKey' => (string) get_option('pickupselect_widget_key', ''), // a rendelés szállítási módjának szállítói és pont típusai (a kosár korlátai nélkül: az admin dönt); // ha a mód azóta törölve lett, nincs szűrés 'overrides' => PickupSelect_Carriers::instance_settings(PickupSelect_Carriers::order_instance($order)) !== null ? PickupSelect_Carriers::overrides(PickupSelect_Carriers::order_instance($order)) : [], 'pointId' => $point['id'] ?? null, 'country' => $point['country_code'] ?? ($order->get_shipping_country() ?: $order->get_billing_country()), 'postcode' => $point ? '' : ($order->get_shipping_postcode() ?: $order->get_billing_postcode()), 'i18n' => [ 'confirmRemove' => __('Remove the pickup point from this order? If it is the shipping address, the customer\'s own address is put back.', 'pickupselect'), 'error' => __('Something went wrong. Please try again.', 'pickupselect'), ], ]); } public static function modal(): void { if (!self::current_order()) { return; } ?> __('You are not allowed to edit this order.', 'pickupselect')], 403); } return $order; } // választás után: a pont ellenőrzése és összegzése (még nem ment) public static function ajax_quote(): void { $order = self::request_order(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing -- a sanitize() szűri és unslash-eli; nonce: request_order() $point = PickupSelect_Selection::check_for_admin($_POST['point'] ?? null, PickupSelect_Carriers::order_instance($order)); if (is_wp_error($point)) { wp_send_json_error(['message' => $point->get_error_message()]); } wp_send_json_success(['point' => $point, 'message' => self::price_note($order, $point)]); } // a díj a szállítási módé, a pont cseréje nem változtat rajta private static function price_note(WC_Order $order, array $point): string { return html_entity_decode(sprintf( /* translators: 1: point name, 2: carrier */ __('New point: %1$s (%2$s).', 'pickupselect'), $point['name'] ?? '', implode(' – ', array_filter([$point['carrier'], $point['group'] ?? ''])) )); } public static function ajax_save(): void { $order = self::request_order(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing -- a sanitize() szűri és unslash-eli; nonce: request_order() $point = PickupSelect_Selection::check_for_admin($_POST['point'] ?? null, PickupSelect_Carriers::order_instance($order)); if (is_wp_error($point)) { wp_send_json_error(['message' => $point->get_error_message()]); } $old = PickupSelect_Order_Display::point($order); $order->update_meta_data(PickupSelect_Plugin::META_KEY, $point); PickupSelect_Point::apply_as_shipping_address($order, $point); self::update_shipping_item_carrier($order, (string) $point['carrier']); $user = wp_get_current_user(); $order->add_order_note(sprintf( /* translators: 1: old point, 2: new point, 3: admin user name */ __('Pickup point changed from "%1$s" to "%2$s" by %3$s.', 'pickupselect'), $old['name'] ?? '-', $point['name'] ?? '', $user->display_name )); if (!empty($_POST['notify'])) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce: request_order() $order->add_order_note(sprintf( /* translators: 1: point name, 2: point address */ __('Your pickup point has been changed to: %1$s, %2$s', 'pickupselect'), $point['name'] ?? '', PickupSelect_Point::address($point) ), 1, true); } $order->save(); wp_send_json_success(); } // a pont törlése; ha a szállítási cím a pont volt, a vásárló saját címe kerül vissza public static function ajax_remove(): void { $order = self::request_order(); $old = PickupSelect_Order_Display::point($order); $saved = $order->get_meta('_pickupselect_customer_shipping'); if ($order->get_meta('_pickupselect_as_shipping') === 'yes' && is_array($saved)) { foreach ($saved as $field => $value) { $setter = 'set_shipping_' . $field; if (is_callable([$order, $setter])) { $order->{$setter}($value); } } } $order->delete_meta_data(PickupSelect_Plugin::META_KEY); $order->delete_meta_data('_pickupselect_as_shipping'); $order->delete_meta_data('_pickupselect_customer_shipping'); self::update_shipping_item_carrier($order, ''); $order->add_order_note(sprintf( /* translators: 1: removed point, 2: admin user name */ __('Pickup point "%1$s" removed by %2$s.', 'pickupselect'), $old['name'] ?? '-', wp_get_current_user()->display_name )); $order->save(); wp_send_json_success(); } // a szállítási tételen a "Carrier" (a pénztárban a díj mellé került) private static function update_shipping_item_carrier(WC_Order $order, string $carrier): void { $key = __('Carrier', 'pickupselect'); foreach ($order->get_items('shipping') as $item) { if ($item->get_method_id() !== PickupSelect_Plugin::METHOD_ID) { continue; } if ($carrier === '') { $item->delete_meta_data($key); } else { $item->update_meta_data($key, $carrier); } $item->save(); } } }