/**
  * Template function to render the template
  *
  * @since 1.0
  */
 function woocommerce_points_rewards_my_points()
 {
     global $wc_points_rewards;
     $points_balance = WC_Points_Rewards_Manager::get_users_points(get_current_user_id());
     $points_label = $wc_points_rewards->get_points_label($points_balance);
     $count = apply_filters('wc_points_rewards_my_account_points_events', 5, get_current_user_id());
     // get a set of points events, ordered newest to oldest
     $args = array('orderby' => array('field' => 'date', 'order' => 'DESC'), 'per_page' => $count, 'paged' => 0, 'user' => get_current_user_id());
     $events = WC_Points_Rewards_Points_Log::get_points_log_entries($args);
     // load the template
     woocommerce_get_template('myaccount/my-points.php', array('points_balance' => $points_balance, 'points_label' => $points_label, 'events' => $events), '', $wc_points_rewards->get_plugin_path() . '/templates/');
 }
 /**
  * Process a payment
  */
 public function process_payment($order_id)
 {
     $order = wc_get_order($order_id);
     if (!is_user_logged_in()) {
         wc_add_notice(__('Payment error:', 'custom-points-product') . ' ' . __('You must be logged in to use this payment method', 'custom-points-product'), 'error');
         return;
     }
     $user_id = $order->get_user_id();
     $available_points = WC_Points_Rewards_Manager::get_users_points($user_id);
     $total_points = Custom_Points_Order::get_order_points_cost_total($order);
     if ($available_points < $total_points) {
         wc_add_notice(__('Payment error:', 'custom-points-product') . ' ' . __('Insufficient points in your account.', 'custom-points-product'), 'error');
         return;
     }
     // deduct points from account
     WC_Points_Rewards_Manager::decrease_points($user_id, $total_points, 'custom-points-gateway');
     $order->set_total(0);
     // Payment complete
     $order->payment_complete();
     // Remove cart
     WC()->cart->empty_cart();
     // Return thankyou redirect
     return array('result' => 'success', 'redirect' => $this->get_return_url($order));
 }
 /**
  * Refreshes the user points balance.  This is called on user
  * create, as well as on user update giving the admin an (albeit simple)
  * means to refresh a users points balance if, for instance a user
  * was created while after the points & rewards plugin was installed, but
  * during a time when it was disabled, or the points balance got out of
  * whack somehow or other.
  *
  * @since 1.0
  * @param int $user_id user identifier
  */
 public function refresh_user_points_balance($user_id)
 {
     // do nothing if the identified user is not a customer
     if (!user_can($user_id, 'customer')) {
         return;
     }
     // refresh the points balance user meta
     update_user_meta($user_id, 'wc_points_balance', WC_Points_Rewards_Manager::get_users_points($user_id));
 }