'; // Close wrap div
return;
}
// Build the pagination base URL
$base_url = admin_url('admin.php?page=advanced-wallet-for-woocommerce&tab=pisol_aww_transactions');
if ($user_id > 0) {
$base_url .= '&user_id=' . $user_id;
}
?>
$transaction['currency']));
if($transaction['used_amount'] > 0) {
$amount .= ' (' . wc_price($transaction['amount'], array('currency' => $transaction['currency'])) . ' ' . esc_html__('total', 'advanced-wallet-for-woocommerce') . ')';
}
} else {
$amount = wc_price($transaction['amount'], array('currency' => $transaction['currency']));
}
// Format the description
$description = $transaction['note'] ?: '—';
// Format the source
$source = $transaction['source'] ?: '—';
// Reference links for orders
if($transaction['type'] === 'debit' && $transaction['source'] === 'order' && !empty($transaction['note'])) {
if(preg_match('/\#(\d+)/', $transaction['note'], $matches)) {
$order_id = $matches[1];
$source = '';
$source .= esc_html__('Order', 'advanced-wallet-for-woocommerce') . ' #' . esc_html($order_id);
$source .= '';
}
}
// Special format for cashback credits
if($transaction['type'] === 'credit' && $transaction['source'] === 'cashback') {
$source = esc_html__('Cashback', 'advanced-wallet-for-woocommerce');
}
// Get and format expiry date (only for credits)
$expiry_html = '—';
if($transaction['type'] === 'credit' && !empty($transaction['expiry_date'])) {
$today = current_time('Y-m-d');
$expiry_date = $transaction['expiry_date'];
// Format the date for display
$formatted_expiry = date_i18n(get_option('date_format'), strtotime($expiry_date));
// Show different formatting based on expiry status
if($expiry_date < $today) {
// Expired
$expiry_html = '' . $formatted_expiry . ' (' . esc_html__('Expired', 'advanced-wallet-for-woocommerce') . ')';
} elseif($expiry_date === $today) {
// Expires today
$expiry_html = '' . $formatted_expiry . ' (' . esc_html__('Today', 'advanced-wallet-for-woocommerce') . ')';
} else {
// Future expiry
$days_left = (int)((strtotime($expiry_date) - strtotime($today)) / DAY_IN_SECONDS);
if($days_left <= 7) {
// Highlight if expiring within 7 days
$expiry_html = '' . $formatted_expiry . ' (' . sprintf(
/* translators: %d: number of days */
_n('%d day left', '%d days left', $days_left, 'advanced-wallet-for-woocommerce'),
$days_left) . ')';
} else {
$expiry_html = $formatted_expiry;
}
}
}
// Status
$status_html = ($transaction['is_deleted'] == 1)
? '' . esc_html__('Deleted', 'advanced-wallet-for-woocommerce') . ''
: '' . esc_html__('Active', 'advanced-wallet-for-woocommerce') . '';
// Get user info if showing all users
$user_html = '';
if(!$user_id && isset($transaction['user_id'])) {
$user_data = get_userdata($transaction['user_id']);
if($user_data) {
$user_html = '';
$user_html .= esc_html($user_data->display_name);
$user_html .= '';
} else {
$user_html = esc_html__('Unknown User', 'advanced-wallet-for-woocommerce') . ' (ID: ' . esc_html($transaction['user_id']) . ')';
}
}
?>
-
1): ?>
esc_like($term) . '%';
// For multisite: join with usermeta to ensure we only get users from current blog
$join_statement = '';
$where_statement = '';
if (is_multisite()) {
$cap_meta_key = $wpdb->prefix . 'capabilities';
$join_statement = $wpdb->prepare(
" INNER JOIN {$wpdb->usermeta} AS um
ON u.ID = um.user_id
AND um.meta_key = %s
AND um.meta_value != ''", // Ensure user has some role
$cap_meta_key
);
}
// SQL query to find users by email, login or display name
// Run the query
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $join_statement is already prepared
$users = $wpdb->get_results($wpdb->prepare(
"SELECT DISTINCT u.ID, u.user_email, u.display_name
FROM {$wpdb->users} AS u
{$join_statement}
WHERE (
u.user_email LIKE %s
OR u.user_login LIKE %s
OR u.display_name LIKE %s
)
ORDER BY
CASE
WHEN u.user_email LIKE %s THEN 1
WHEN u.user_login LIKE %s THEN 2
ELSE 3
END,
u.display_name ASC
LIMIT 20",
$like_term,
$like_term,
$like_term,
$like_term,
$like_term
));
// Format the results
$results = array();
foreach ($users as $user) {
$results[] = array(
'id' => $user->ID,
'text' => sprintf('%s (%s)', $user->display_name, $user->user_email),
);
}
wp_send_json($results);
}
/**
* Handle AJAX request to soft delete or restore a transaction
*/
public function ajax_soft_delete_transaction() {
// Verify nonce for security
check_ajax_referer('pisol_aww_soft_delete_transaction', 'security');
// Check user capability
if (!current_user_can('manage_options')) {
wp_send_json_error(array(
'message' => __('You do not have permission to perform this action.', 'advanced-wallet-for-woocommerce')
));
return;
}
// Get transaction details and properly unslash before sanitizing
$transaction_id = isset($_POST['transaction_id']) ? absint($_POST['transaction_id']) : 0;
$transaction_type = isset($_POST['transaction_type']) ? sanitize_text_field(wp_unslash($_POST['transaction_type'])) : '';
$action = isset($_POST['action_type']) ? sanitize_text_field(wp_unslash($_POST['action_type'])) : 'delete'; // 'delete' or 'undelete'
if (!$transaction_id || empty($transaction_type)) {
wp_send_json_error(array(
'message' => __('Invalid transaction details.', 'advanced-wallet-for-woocommerce')
));
return;
}
// Get wallet manager
$wallet_manager = \PISOL\AWW\CLASSES\Wallet_Manager::get_instance();
$success = false;
if ($action === 'delete') {
// Soft delete based on type
if ($transaction_type === 'credit') {
$success = $wallet_manager->soft_delete_credit($transaction_id);
} elseif ($transaction_type === 'debit') {
$success = $wallet_manager->soft_delete_debit($transaction_id);
}
$message = $success
? __('Transaction has been soft deleted successfully.', 'advanced-wallet-for-woocommerce')
: __('Failed to delete the transaction. It may be in use or already deleted.', 'advanced-wallet-for-woocommerce');
} else {
// Restore based on type
if ($transaction_type === 'credit') {
$success = $wallet_manager->restore_credit($transaction_id);
} elseif ($transaction_type === 'debit') {
$success = $wallet_manager->restore_debit($transaction_id);
}
$message = $success
? __('Transaction has been restored successfully.', 'advanced-wallet-for-woocommerce')
: __('Failed to restore the transaction.', 'advanced-wallet-for-woocommerce');
}
if ($success) {
wp_send_json_success(array(
'message' => $message
));
} else {
wp_send_json_error(array(
'message' => $message
));
}
}
}