Skip to content

Instantly share code, notes, and snippets.

@malsubrata
Created November 8, 2019 05:49
Show Gist options
  • Save malsubrata/abf7b92f4c5ecca5c9fde4209bd9c185 to your computer and use it in GitHub Desktop.
Save malsubrata/abf7b92f4c5ecca5c9fde4209bd9c185 to your computer and use it in GitHub Desktop.
if (!function_exists('points_to_wallet_balance_convertion_shortcode_func')) {
function points_to_wallet_balance_convertion_shortcode_func($atts) {
$atts = shortcode_atts(
array(
'convertion_rate' => 1
), $atts, 'convert_points_to_wallet_balance' );
if(!is_user_logged_in()){
return __('Please login');
}
$user = wp_get_current_user();
$convertion_rate = $atts['convertion_rate'];
$mycred_balance = mycred_get_users_balance($user->ID);
$mycred_point = 0;
if (isset($_POST['convert_mycred_to_woo_wallet']) && wp_verify_nonce($_POST['convert_mycred_to_woo_wallet'], 'convert_mycred_to_woo_wallet')) {
if (isset($_POST['mycred-point'])) {
$mycred_point = $_POST['mycred-point'];
}
if ($mycred_point && ($mycred_balance >= $mycred_point)) {
mycred_subtract('convert to wallet balance', $user->ID, -$mycred_point);
$amount = ( $mycred_point / $convertion_rate );
$description = 'Wallet credited from myCred points';
$transaction_id = woo_wallet()->wallet->credit($user->ID, $amount, $description);
if ($transaction_id) {
echo __('Amount convert successfully!', 'woo-wallet');
} else {
echo __('An error occurred please try again', 'woo-wallet');
}
} else {
echo __('You don\'t have sufficient points');
}
}
ob_start();
?>
<form action="" method="post">
<span>Number of Points:</span>
<input type="text" name="mycred-point" value="">
<br><br>
<?php wp_nonce_field('convert_mycred_to_woo_wallet', 'convert_mycred_to_woo_wallet') ?>
<input type="submit" class="button" name="submit" value="Submit">
</form>
<?php
return ob_get_clean();
}
}
add_shortcode('convert_points_to_wallet_balance', 'points_to_wallet_balance_convertion_shortcode_func');
@evoxteam
Copy link

Hello, i want to do something different, i want to award all users with wallet balance based on their coins without deducting any of these coins, like mycred coins X rate = amount added to wallet as earnings without deducting any of these coins, could you please help me with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment