Example #1
0
 /**
  * 
  * @param int $order_id
  */
 function wc_w_action_after_checkout($order_id)
 {
     if (is_user_logged_in()) {
         $uid = get_current_user_id();
         $onhold = get_user_meta($uid, 'onhold_credits', true);
         $credit = get_user_meta($uid, 'wc_wallet', true);
         if ($onhold != 0) {
             update_user_meta($uid, 'onhold_credits', 0);
             update_user_meta($uid, 'wc_wallet', $credit - $onhold);
             wc_w_add_to_log($uid, $onhold, 0, $order_id);
         }
     }
 }
Example #2
0
 /**
  * 
  * @param int $order_id
  * @todo This function is triggered, when a order is cancelled in woocommerce.
  */
 function wc_m_move_order_money_to_user($order_id, $old_status, $new_status)
 {
     if ($new_status != "cancelled") {
         return;
     }
     if (array_search($order_id, get_the_order_in_log()) === false) {
         $opm = array_search(get_post_meta($order_id, '_payment_method', true), get_wcw_only_methods()) !== false || get_post_meta($order_id, '_payment_method', true) == "" ? true : false;
         if (count(get_wcw_only_methods()) != 0 && $opm && wcw_check_the_order_status($order_id, $old_status)) {
             $order_total = get_post_meta($order_id, '_order_total', true);
             $order = wc_get_order($order_id);
             $ttyl = $order->get_fees();
             foreach ($ttyl as $key => $yl) {
                 if ($yl['name'] == "Credits") {
                     $e = $key;
                 }
             }
             $c = (string) $e;
             if (-1 * $ttyl[$c]['line_total']) {
                 $order_autho = get_post_meta($order_id, '_customer_user', true);
                 $author_wallet = get_user_meta($order_autho, 'wc_wallet', true);
                 update_user_meta($order_autho, 'wc_wallet', $author_wallet + $order_total + -$ttyl[$c]['line_total']);
                 wc_w_add_to_log($order_autho, $order_total + -$ttyl[$c]['line_total'], 1, $order_id);
             } else {
                 $order_autho = get_post_meta($order_id, '_customer_user', true);
                 $author_wallet = get_user_meta($order_autho, 'wc_wallet', true);
                 update_user_meta($order_autho, 'wc_wallet', $author_wallet + $order_total);
                 wc_w_add_to_log($order_autho, $order_total, 1, $order_id);
             }
         }
     }
 }