Just a simple code. You can modified with your code.
add_shortcode( 'your_shortcode', 'your_shortcode_function' );
function your_shortcode_function() {
if (isset($_GET['type']) && $_GET['type'] == 'credit') {
return 'Thank you for using your nedvil wallet.';
}
if (isset($_GET['type']) && $_GET['type'] == 'debit') {
return 'Thank you for using your wallet.';
}
}
place [your_shortcode] on your page.
access with get. example:
yourwebsite.com/your-page/?type=credit
yourwebsite.com/your-page/?type=debit
Hi Dhimas,
Thank you for you response.
This shortcode is not working. Actually this is for TeraWallet Plugin and its author has giving no response that’s why I am asking here.
I am trying to add this shortcode in my email notification but your code gives no response on my emails.
For your reference I am posting one shortcode which works so maybe by that way you can construct a code to which the plugin can give response.
function woo_mini_wallet_callback() {
if (!function_exists('woo_wallet') || !is_user_logged_in()) {
return '';
}
ob_start();
$title = __('Current wallet balance', 'woo-wallet');
$mini_wallet = '<a class="woo-wallet-menu-contents" href="' . esc_url(wc_get_account_endpoint_url(get_option('woocommerce_woo_wallet_endpoint', 'woo-wallet'))) . '" title="' . $title . '">';
$mini_wallet .= woo_wallet()->wallet->get_wallet_balance(get_current_user_id());
$mini_wallet .= '</a>';
echo $mini_wallet;
return ob_get_clean();
}
add_shortcode('woo-mini-wallet', 'woo_mini_wallet_callback');
This shortcode only gives wallet balance in emails but I also want to insert credit or debit messages.
Please help.
Thanks!
I guess the shortcode will be placed on the page with GET request.
Ok, so maybe the code is like this. I don’t know where the $type array data came from, so make sure the $type array data passes to the function correctly.
add_shortcode( 'your_shortcode', 'your_shortcode_function' );
function your_shortcode_function() {
if ($type == 'credit') {
return 'Thank you for using your nedvil wallet.';
}
if ($type == 'debit') {
return 'Thank you for using your wallet.';
}
}
Its still not working. I have found a filter which I think does the same thing. Please tell me how to convert it in to shortcode.
add_filter('woo_wallet_current_balance', 'woo_wallet_current_balance', 10, 2);
if(!function_exists('woo_wallet_current_balance')){
function woo_wallet_current_balance($balance, $user_id){
$credit_amount = array_sum(wp_list_pluck(get_wallet_transactions(array('user_id' => $user_id, 'where' => array(array('key' => 'type', 'value' => 'credit')), 'nocache' => true)), 'amount'));
$debit_amount = array_sum(wp_list_pluck(get_wallet_transactions(array('user_id' => $user_id, 'where' => array(array('key' => 'type', 'value' => 'debit')), 'nocache' => true)), 'amount'));
$balance = $credit_amount - $debit_amount;
return $balance;
}
}
Also guide me where do I put the additional messages like ‘your wallet has been credited or debited according to condition’