/**
  * Calculate Discount From User Points
  * 
  * Handles to calculate value from user points
  * 
  * @package Easy Digital Downloads - Points and Rewards
  * @since 1.0.0
  **/
 public function edd_points_get_userpoints_value()
 {
     global $edd_options;
     //get user total points
     $userpoints = edd_points_get_user_points();
     // Get redemption points from settings page
     $points = intval($edd_options['edd_points_redeem_conversion']['points']);
     // Get redemption ration from settings page
     $rate = intval($edd_options['edd_points_redeem_conversion']['rate']);
     if (empty($points) || empty($rate)) {
         return 0;
     }
     return $userpoints * ($rate / $points);
 }
Пример #2
0
function test_vendd_menu_bar($menu)
{
    $tot_points = edd_points_get_user_points(get_current_user_id());
    $menu_items = '<li class="geek-cred-nav-balance-wrap"><a href="/account/"><img class="geek-cred-coin-small" src="' . get_stylesheet_directory_uri() . '/images/coin.png" />&nbsp;' . $tot_points . ' Geek Creds</a></li>';
    return $menu_items . $menu;
}
/**
 * Minus / Decrease Points from user account
 * 
 * Handles to minus / decrease points from user account
 * 
 * @package Easy Digital Downloads - Points and Rewards
 * @since 1.0.0
 **/
function edd_points_minus_points_from_user($points = 0, $userid = '')
{
    global $current_user;
    //check userid is empty then use current user id
    if (empty($userid)) {
        $userid = $current_user->ID;
    }
    //check points should not empty
    if (!empty($points)) {
        //get user current points
        $user_points = edd_points_get_user_points($userid);
        //update users points for signup
        update_user_meta($userid, '_edd_userpoints', $user_points - $points);
    }
    // end if to check points should not empty
}
 /**
  * AJAX Call for adjust user points
  *
  * Handles to adjust user points using ajax
  *
  * @package Easy Digital Downloads - Points and Rewards
  * @since 1.0.0
  */
 public function edd_points_adjust_user_points()
 {
     if (isset($_POST['userid']) && !empty($_POST['userid']) && isset($_POST['points']) && !empty($_POST['points'])) {
         // Check user id and points are not empty
         $user_id = $_POST['userid'];
         $current_points = $_POST['points'];
         //check number contains minus sign or not
         if (strpos($current_points, '-') !== false) {
             $operation = 'minus';
             $current_points = str_replace('-', '', $current_points);
             // Update user points to user account
             edd_points_minus_points_from_user($current_points, $user_id);
         } else {
             $operation = 'add';
             $current_points = str_replace('+', '', $current_points);
             // Update user points to user account
             edd_points_add_points_to_user($current_points, $user_id);
         }
         // Get user points from user meta
         $ubalance = edd_points_get_user_points($user_id);
         if (isset($_POST['log']) && !empty($_POST['log']) && trim($_POST['log'], ' ') != '') {
             // Check log is not empty
             $post_data = array('post_title' => $_POST['log'], 'post_content' => $_POST['log'], 'post_author' => $user_id);
             $log_meta = array('userpoint' => abs($current_points), 'events' => 'manual', 'operation' => $operation);
             $this->logs->edd_points_insert_logs($post_data, $log_meta);
         }
         echo $ubalance;
     } else {
         echo 'error';
     }
     exit;
 }
 /**
  * Adjust the Tool Bar
  * 
  * @package Easy Digital Downloads - Points and Rewards
  * @since 1.0.0
  */
 function edd_points_tool_bar($wp_admin_bar)
 {
     global $current_user;
     $wp_admin_bar->add_group(array('parent' => 'my-account', 'id' => 'edd-points-actions'));
     //get total users points
     $tot_points = edd_points_get_user_points();
     $wp_admin_bar->add_menu(array('parent' => 'edd-points-actions', 'id' => 'user-balance', 'title' => __('My Balance:', 'eddpoints') . ' ' . $tot_points, 'href' => admin_url('profile.php')));
 }
    /**
     * Add custom fields.
     *
     * Handles to add custom fields in user profile page
     * 
     * @package Easy Digital Downloads - Points and Rewards
     * @since 1.0.0
     **/
    public function edd_points_add_custom_user_profile_fields($user)
    {
        //get user points
        $userpoints = edd_points_get_user_points($user->ID);
        ?>
			<table class="form-table edd-points-user-profile-balance">
				<tr>
					<th>
						<label for="edd_userpoints"><?php 
        _e('My current balance', 'eddpoints');
        ?>
</label>
					</th>
					<td>
						<h2><?php 
        echo $userpoints;
        ?>
</h2>
					</td>
				</tr>
			</table>
		<?php 
    }