Plugin Directory

Changeset 3302894


Ignore:
Timestamp:
05/29/2025 10:57:09 AM (10 months ago)
Author:
tsimaboy
Message:

auto update esim dataplan list

Location:
sell-esim/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sell-esim/trunk/src/ApiClient.php

    r3118903 r3302894  
    2727    public function register()
    2828    {
    29         add_action("update_option_sellesim_settings", array($this, 'updatePlan'));
     29        add_action("sellesim_update_plan", array($this, 'updatePlan'));
    3030        add_action('woocommerce_payment_complete', array($this, 'orderHandle'));
    3131    }
     
    9292        $client = new self();
    9393        $dataplan_list = $client->esim_dataplan_list();
    94         update_option('sellesim_dataplan_list', $dataplan_list);
     94        if ($dataplan_list) {
     95            update_option('sellesim_dataplan_list', $dataplan_list);
     96        }
    9597    }
    9698
  • sell-esim/trunk/templates/esim-dataplan-list.php

    r2832142 r3302894  
    33    <?php
    44        settings_errors();
     5        $last_run_time = get_option('sellesim_update_plan_last_run_time', 0);
     6        $current_time = time();
     7        // 若最近15分钟没执行过
     8        if ($current_time - $last_run_time >= 900) {
     9            // 更新套餐
     10            do_action('sellesim_update_plan');
     11            // 更新最后执行时间
     12            update_option('sellesim_update_plan_last_run_time', $current_time);
     13            echo '<p>Updated: ' . date('Y-m-d H:i:s', $current_time) . '</p>';
     14        } else {
     15            echo '<p>Last update time: ' . date('Y-m-d H:i:s', $last_run_time) . '</p>';
     16        }
    517        $dataplan_list = get_option('sellesim_dataplan_list');
    618    ?>
     
    921        <thead>
    1022            <tr>
     23                <th><?php echo esc_html('ID'); ?></th>
    1124                <th><?php echo esc_html('SKU'); ?></th>
    1225                <th><?php echo esc_html('eSIM Dataplan name'); ?></th>
     
    1932        <?php
    2033            if($dataplan_list){
    21                 foreach ($dataplan_list as $dataplan) {
     34                foreach ($dataplan_list as $key => $dataplan) {
    2235                    echo '
    2336                    <tr>
     37                        <td>' . esc_html($key+1) . '</td>
    2438                        <td>' . esc_html($dataplan['channel_dataplan_id']) . '</td>
    2539                        <td>' . esc_html($dataplan['channel_dataplan_name']) . '</td>
Note: See TracChangeset for help on using the changeset viewer.