Title: Help in converting php into shortcode
Last modified: May 25, 2020

---

# Help in converting php into shortcode

 *  [lavbhelloriya](https://wordpress.org/support/users/lavbhelloriya/)
 * (@lavbhelloriya)
 * [6 years ago](https://wordpress.org/support/topic/help-in-converting-php-into-shortcode/)
 * Kindly someone convert this php code into shortocode. I am unable to do this.
   
   Thanks in advance!
 *     ```
           <?php if ( $type == 'credit' ) {
           <p><?php _e( "Thank you for using your nedvil wallet.", 'woo-wallet' ); ?> <?php echo wc_price( $amount, woo_wallet_wc_price_args($user->ID) ); ?> <?php _e( 'has been credited to your wallet.', 'woo-wallet' ); ?> <?php _e( 'Current wallet balance is', 'woo-wallet' ); ?> <?php echo woo_wallet()->wallet->get_wallet_balance( $user->ID ); ?></p>
           <?php } ?>
           <?php if ( $type == 'debit' ) { ?>
               <p><?php _e( "Thank you for using your wallet.", 'woo-wallet' ); ?> <?php echo wc_price( $amount, woo_wallet_wc_price_args($user->ID) ); ?> <?php _e( 'has been debited from your wallet.', 'woo-wallet' ); ?> <?php _e( 'Current wallet balance is', 'woo-wallet' ); ?> <?php echo woo_wallet()->wallet->get_wallet_balance( $user->ID ); ?></p>
           <?php }
           <?php
       ```
   
    -  This topic was modified 6 years ago by [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/).

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Dhimas Kirana](https://wordpress.org/support/users/dhmskrn/)
 * (@dhmskrn)
 * [6 years ago](https://wordpress.org/support/topic/help-in-converting-php-into-shortcode/#post-12890925)
 * 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**
 *  Thread Starter [lavbhelloriya](https://wordpress.org/support/users/lavbhelloriya/)
 * (@lavbhelloriya)
 * [6 years ago](https://wordpress.org/support/topic/help-in-converting-php-into-shortcode/#post-12891022)
 * 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!
 *  [Dhimas Kirana](https://wordpress.org/support/users/dhmskrn/)
 * (@dhmskrn)
 * [6 years ago](https://wordpress.org/support/topic/help-in-converting-php-into-shortcode/#post-12896675)
 * 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.';
       	}
       }
       ```
   
 *  Thread Starter [lavbhelloriya](https://wordpress.org/support/users/lavbhelloriya/)
 * (@lavbhelloriya)
 * [6 years ago](https://wordpress.org/support/topic/help-in-converting-php-into-shortcode/#post-12902734)
 * 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’

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Help in converting php into shortcode’ is closed to new replies.

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 4 replies
 * 2 participants
 * Last reply from: [lavbhelloriya](https://wordpress.org/support/users/lavbhelloriya/)
 * Last activity: [6 years ago](https://wordpress.org/support/topic/help-in-converting-php-into-shortcode/#post-12902734)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
