I am very new to coding and to wordpress development and was trying to create a simple plugin that allows admin to award users that has Mycred points some woowallet credit
Points X admin value = amount added to wallet
so i searched and tried for a few days and came up with this code that doesn’t work … Please help
function process_coins_earning_to_wallet()
{
if (isset($_POST['AddCredit'])) {
if (!current_user_can('administrator')) {
return __('Please login as admin');
}
$mycred_balance = array();
$rate = get_option('evox_earnings_rate_per_coin');
$users = get_users(array('fields' => array('ID')));
foreach ($users as $user) {
$mycred_balance[] = get_user_meta($user->ID, 'mycred_default');
foreach ($mycred_balance as $user_balance) {
$amount[] = $user_balance * $rate;
// $amount = $rate * intval($mycred_balance);
$description = 'Wallet credited from tecssapp points';
$transaction_id = woo_wallet()->wallet->credit($user->ID, $amount, $description);
if ($transaction_id) {
echo "<pre>";
echo __('Amount convert successfully!', 'woo-wallet');
echo "</pre>";
} else {
echo __('An error occurred please try again', 'woo-wallet');
}
}
}
}
}
add_action('init', 'process_coins_earning_to_wallet');