| 1 |
<?php if (!isset($date_filter)) { $date_filter = ''; } ?> |
| 2 |
<?php |
| 3 |
// Determine if filters are active |
| 4 |
$filters_active = !empty($status) || !empty($date_filter) || !empty($search); |
| 5 |
$months = []; |
| 6 |
for ($i = 0; $i < 12; $i++) { |
| 7 |
$month = strtotime("-$i month"); |
| 8 |
$months[date('Y-m', $month)] = date('F Y', $month); |
| 9 |
} |
| 10 |
?> |
| 11 |
<div class="wp-subscription-admin-content list-page"> |
| 12 |
<div class="wp-subscription-list-title"><h1 class="wp-heading-inline">Subscriptions</h1></div> |
| 13 |
<div class="wp-subscription-list-header"> |
| 14 |
<form method="get"> |
| 15 |
<input type="hidden" name="page" value="wp-subscription" /> |
| 16 |
<select name="subscrpt_status" value="<?php echo esc_attr($status); ?>"> |
| 17 |
<option value=""><?php esc_html_e('All Status', 'wp_subscription'); ?></option> |
| 18 |
<option value="active" <?php selected($status, 'active'); ?>><?php esc_html_e('Active', 'wp_subscription'); ?></option> |
| 19 |
<option value="cancelled" <?php selected($status, 'cancelled'); ?>><?php esc_html_e('Cancelled', 'wp_subscription'); ?></option> |
| 20 |
<option value="draft" <?php selected($status, 'draft'); ?>><?php esc_html_e('Draft', 'wp_subscription'); ?></option> |
| 21 |
</select> |
| 22 |
<select name="date_filter" value="<?php echo esc_attr($date_filter); ?>"> |
| 23 |
<option value=""><?php esc_html_e('All Dates', 'wp_subscription'); ?></option> |
| 24 |
<?php foreach ($months as $val => $label): ?> |
| 25 |
<option value="<?php echo esc_attr($val); ?>" <?php selected($date_filter, $val); ?>><?php echo esc_html($label); ?></option> |
| 26 |
<?php endforeach; ?> |
| 27 |
</select> |
| 28 |
<input type="search" name="s" value="<?php echo esc_attr($search); ?>" placeholder="<?php esc_attr_e('Search by subscription ID...', 'wp_subscription'); ?>" /> |
| 29 |
<select name="per_page"> |
| 30 |
<?php foreach ([10, 20, 50, 100] as $n): ?> |
| 31 |
<option value="<?php echo $n; ?>" <?php selected(isset($_GET['per_page']) ? intval($_GET['per_page']) : 20, $n); ?>><?php echo $n; ?> per page</option> |
| 32 |
<?php endforeach; ?> |
| 33 |
</select> |
| 34 |
<button type="submit" class="button">Search</button> |
| 35 |
<?php if ($filters_active): ?> |
| 36 |
<a href="<?php echo esc_url(remove_query_arg(['subscrpt_status','date_filter','s','title','paged'])); ?>" class="button">Reset</a> |
| 37 |
<?php endif; ?> |
| 38 |
<?php if ($filters_active): ?> |
| 39 |
<span>Filters applied</span> |
| 40 |
<?php endif; ?> |
| 41 |
</form> |
| 42 |
</div> |
| 43 |
<h2 class="screen-reader-text">Subscriptions list</h2> |
| 44 |
<table class="wp-list-table widefat fixed striped wp-subscription-modern-table"> |
| 45 |
<thead> |
| 46 |
<tr> |
| 47 |
<th style="width:200px;">ID</th> |
| 48 |
<th style="min-width:320px;">Title</th> |
| 49 |
<th style="width:200px;">Customer</th> |
| 50 |
<th style="width:100px;">Start Date</th> |
| 51 |
<th style="width:100px;">Renewal Date</th> |
| 52 |
<th style="width:80px;">Status</th> |
| 53 |
<th style="width:80px;">Actions</th> |
| 54 |
</tr> |
| 55 |
</thead> |
| 56 |
<tbody> |
| 57 |
<?php if (!empty($subscriptions)) : ?> |
| 58 |
<?php foreach ($subscriptions as $subscription) : |
| 59 |
$order_id = get_post_meta($subscription->ID, '_subscrpt_order_id', true); |
| 60 |
$order = wc_get_order($order_id); |
| 61 |
$order_item_id = get_post_meta($subscription->ID, '_subscrpt_order_item_id', true); |
| 62 |
$order_item = $order ? $order->get_item($order_item_id) : null; |
| 63 |
$product_name = $order_item ? $order_item->get_name() : '-'; |
| 64 |
$customer = $order ? $order->get_formatted_billing_full_name() : '-'; |
| 65 |
$customer_id = $order ? $order->get_customer_id() : 0; |
| 66 |
$customer_url = $customer_id ? admin_url('user-edit.php?user_id=' . $customer_id) : ''; |
| 67 |
$customer_email = $order ? $order->get_billing_email() : ''; |
| 68 |
$start_date = get_post_meta($subscription->ID, '_subscrpt_start_date', true); |
| 69 |
$renewal_date = get_post_meta($subscription->ID, '_subscrpt_next_date', true); |
| 70 |
$status_obj = get_post_status_object(get_post_status($subscription->ID)); |
| 71 |
?> |
| 72 |
<tr> |
| 73 |
<td> |
| 74 |
<a href="<?php echo esc_url(get_edit_post_link($subscription->ID)); ?>" class="subscrpt-id-link"> |
| 75 |
#<?php echo esc_html(get_the_title($subscription->ID)); ?> |
| 76 |
</a> |
| 77 |
</td> |
| 78 |
<td style="min-width:320px;"> |
| 79 |
<div class="wp-subscription-title-wrap"> |
| 80 |
<span><?php echo esc_html($product_name); ?></span> |
| 81 |
<div class="wp-subscription-row-actions"> |
| 82 |
<a href="<?php echo esc_url(get_edit_post_link($subscription->ID)); ?>">View</a> |
| 83 |
<a href="<?php echo esc_url(admin_url('admin.php?page=wp-subscription&action=duplicate&sub_id=' . $subscription->ID)); ?>">Duplicate</a> |
| 84 |
<a href="<?php echo esc_url(get_delete_post_link($subscription->ID)); ?>">Delete</a> |
| 85 |
</div> |
| 86 |
</div> |
| 87 |
</td> |
| 88 |
<td> |
| 89 |
<?php if ($customer_url): ?> |
| 90 |
<a href="<?php echo esc_url($customer_url); ?>" target="_blank"><?php echo esc_html($customer); ?></a> |
| 91 |
<?php else: ?> |
| 92 |
<?php echo esc_html($customer); ?> |
| 93 |
<?php endif; ?> |
| 94 |
<?php if ($customer_email): ?> |
| 95 |
<div class="wp-subscription-customer-email"><?php echo esc_html($customer_email); ?></div> |
| 96 |
<?php endif; ?> |
| 97 |
</td> |
| 98 |
<td><?php echo $start_date ? esc_html(gmdate('F d, Y', $start_date)) : '-'; ?></td> |
| 99 |
<td><?php echo $renewal_date ? esc_html(gmdate('F d, Y', $renewal_date)) : '-'; ?></td> |
| 100 |
<td> |
| 101 |
<span class="subscrpt-status-badge subscrpt-status-<?php echo esc_attr($status_obj->name); ?>"> |
| 102 |
<?php echo esc_html($status_obj->label); ?> |
| 103 |
</span> |
| 104 |
</td> |
| 105 |
<td> |
| 106 |
<a href="<?php echo esc_url(get_edit_post_link($subscription->ID)); ?>" class="button button-small"><?php esc_html_e('Edit', 'wp_subscription'); ?></a> |
| 107 |
</td> |
| 108 |
</tr> |
| 109 |
<?php endforeach; ?> |
| 110 |
<?php else : ?> |
| 111 |
<tr> |
| 112 |
<td colspan="7" class="wp-subscription-list-empty"> |
| 113 |
<?php esc_html_e('No subscriptions found.', 'wp_subscription'); ?> |
| 114 |
</td> |
| 115 |
</tr> |
| 116 |
<?php endif; ?> |
| 117 |
</tbody> |
| 118 |
</table> |
| 119 |
<?php if ($max_num_pages > 1): ?> |
| 120 |
<div class="wp-subscription-pagination"> |
| 121 |
<span class="total">Total <?php echo intval($total); ?></span> |
| 122 |
<?php |
| 123 |
$base_url = remove_query_arg('paged'); |
| 124 |
$show_pages = $max_num_pages > 1 || $max_num_pages == 1; |
| 125 |
for ($i = 1; $i <= $max_num_pages; $i++): |
| 126 |
$url = add_query_arg(['paged' => $i, 'per_page' => $per_page], $base_url); |
| 127 |
$is_current = $i == $paged; |
| 128 |
?> |
| 129 |
<a href="<?php echo esc_url($url); ?>" class="button<?php if ($is_current) echo ' button-primary'; ?>" <?php if ($is_current) echo 'disabled'; ?>><?php echo $i; ?></a> |
| 130 |
<?php endfor; ?> |
| 131 |
<span class="goto-label">Go to</span> |
| 132 |
<form method="get"> |
| 133 |
<input type="hidden" name="page" value="wp-subscription" /> |
| 134 |
<input type="number" name="paged" min="1" max="<?php echo $max_num_pages; ?>" value="<?php echo $paged; ?>" /> |
| 135 |
<input type="hidden" name="per_page" value="<?php echo $per_page; ?>" /> |
| 136 |
<button type="submit" class="button">OK</button> |
| 137 |
</form> |
| 138 |
</div> |
| 139 |
<?php endif; ?> |
| 140 |
</div> |
| 141 |
|