,expires:int}> */ function jio_get_wait_pay_float_orders(int $user_id): array { if ($user_id <= 0 || !class_exists('\Jio\Payment\OrderRepository') || !class_exists('\Jio\Payment\UserOrders')) { return []; } $rows = \Jio\Payment\OrderRepository::get_instance()->get_user_orders($user_id, [ 'status' => \Jio\Payment\Order::STATUS_PENDING, 'limit' => 5, ]); $min_expires = time() + 3 * MINUTE_IN_SECONDS; $views = \Jio\Payment\UserOrders::get_instance(); $orders = []; foreach ($rows as $row) { $expires_at = trim((string) ($row['expires_at'] ?? '')); $expires = $expires_at !== '' ? strtotime($expires_at . ' UTC') : false; if (!$expires || $expires < $min_expires) { continue; } $orders[] = ['view' => $views->decorate_order_view($row, false), 'expires' => (int) $expires]; } return $orders; } endif; if (!function_exists('jio_get_wait_pay_order_thumb')) : /** * 订单缩略图:商品图优先,否则按订单类型回退彩色图标。 * * @param array $view */ function jio_get_wait_pay_order_thumb(array $view): string { $image = (string) ($view['image'] ?? ''); if ($image !== '') { $img = '' . esc_attr((string) ($view['product_name'] ?? 'product-image')) . ''; } else { $icons = [ 'vip' => ['vip_1', 'muted-box fit-cover'], 'recharge' => ['money-color-2', 'muted-box fit-cover c-blue-2'], 'points' => ['points-color', 'muted-box fit-cover c-yellow-2'], ]; [$icon, $class] = $icons[(string) ($view['product_type'] ?? '')] ?? ['order-color', 'fit-cover muted-box']; $img = ''; } return '
' . $img . '
'; } endif; if (!function_exists('jio_get_wait_pay_float_html')) : function jio_get_wait_pay_float_html(): string { $orders = jio_get_wait_pay_float_orders(get_current_user_id()); if (!$orders) { return ''; } $pay_url = function_exists('jio_get_user_center_url') ? jio_get_user_center_url('orders') : home_url('/'); $lists = ''; $countdown = ''; foreach ($orders as $order) { $view = $order['view']; $countdown = gmdate('c', $order['expires']); $amount = (string) ($view['amount'] ?? '0'); $price = !empty($view['is_points']) ? (string) (int) $amount : (string) (float) round((float) $amount, 2); $lists .= '' . jio_get_wait_pay_order_thumb($view) . '
' . '
' . '
' . esc_html((string) ($view['product_name'] ?? '')) . '
' . '
' . esc_html((string) ($view['currency_symbol'] ?? '¥')) . '' . esc_html($price) . '
' . '
' . '
' . ':' . '' . esc_html__('立即支付', 'jio') . '' . '
' . '
' . '
'; } // 按钮倒计时取最后一条订单(与参考主题循环后的 $time_remaining 一致)。 return '
' . '' . '' . '' . esc_html__('待支付', 'jio') . '' . ':' . '' . '
'; } endif; if (!function_exists('jio_wait_pay_float_window')) : function jio_wait_pay_float_window(): void { if (!is_user_logged_in() || !class_exists('\Jio\Settings\Settings')) { return; } $order_settings = \Jio\Settings\Settings::get_order_settings(); if (empty($order_settings['wait_float'])) { return; } echo jio_get_wait_pay_float_html(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- 各片段已转义 } add_action('wp_footer', 'jio_wait_pay_float_window'); endif;