get_user_balance($user->ID);
// Get currency symbol
$currency_symbol = get_woocommerce_currency_symbol();
// Create nonce for security
wp_nonce_field('pisol_aww_wallet_action', 'pisol_aww_wallet_nonce');
?>
get_user_transactions($user->ID, null, 1, array('limit' => 5));
if (!empty($transactions)) : ?>
|
|
|
|
|
|
|
|
' . esc_html($prefix . ' ' . $currency_symbol . number_format($transaction['amount'], 2)) . '';
?>
|
|
|
|
ID);
?>
ID);
?>
user_login
);
}
// Get expiry date if set
$credit_params = array(
'user_id' => $user_id,
'amount' => $amount,
'source' => 'admin',
'note' => $note,
);
// Add expiry date if set
if (isset($_POST['wallet_expiry_date']) && !empty($_POST['wallet_expiry_date'])) {
$expiry_date = sanitize_text_field(wp_unslash($_POST['wallet_expiry_date']));
// Validate date format (YYYY-MM-DD)
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $expiry_date)) {
// Make sure expiry date is in the future
if (strtotime($expiry_date) > time()) {
$credit_params['expiry_date'] = $expiry_date;
// Append expiry information to note
$formatted_date = date_i18n(get_option('date_format'), strtotime($expiry_date));
/* translators: %s: Formatted expiry date */
$credit_params['note'] .= ' | ' . sprintf(__('Expires on %s', 'advanced-wallet-for-woocommerce'), $formatted_date);
}
}
}
// Get wallet manager instance
$wallet_manager = Wallet_Manager::get_instance();
// Add credit to user wallet
$result = $wallet_manager->add_credit($credit_params);
// Add admin notice for success or failure
if ($result) {
add_action('admin_notices', function() use ($amount, $credit_params) {
$currency_symbol = get_woocommerce_currency_symbol();
/* translators: %s: Amount with currency symbol */
$message = sprintf(__('Wallet funds added successfully: %s', 'advanced-wallet-for-woocommerce'), $currency_symbol . number_format($amount, 2));
// Add expiry message if applicable
if (!empty($credit_params['expiry_date'])) {
$formatted_date = date_i18n(get_option('date_format'), strtotime($credit_params['expiry_date']));
/* translators: %s: Formatted expiry date */
$message .= ' ' . sprintf(__('(Expires on: %s)', 'advanced-wallet-for-woocommerce'), $formatted_date);
}
?>