/**
  * Populates a subscription from the loaded post data.
  *
  * @param mixed $result
  */
 public function populate($result)
 {
     parent::populate($result);
     if ($this->post->post_parent > 0) {
         $this->order = wc_get_order($this->post->post_parent);
     }
 }
    ?>
</span></th>
				<th class="order-actions">&nbsp;</th>
			</tr>
		</thead>

		<tbody><?php 
    //echo "hiiiiiiii";
    //print_r($order_ids);
    //$user_product_bought=fused_has_user_bought(6,$order_userids);
    //print_r($user_product_bought);
    //$order = new WC_Order();
    //print_r($order_userids);
    foreach ($customer_orders as $customer_order) {
        $order = new WC_Order();
        $order->populate($customer_order);
        $status = get_term_by('slug', $order->status, 'shop_order_status');
        $item_count = $order->get_item_count();
        ?>
<tr class="order">
					<td class="order-number">
						<a href="<?php 
        echo esc_url(add_query_arg('order', $order->id, get_permalink(woocommerce_get_page_id('view_order'))));
        ?>
">
							<?php 
        echo $order->get_order_number();
        ?>
						</a>
					</td>
					<td class="order-date">
Example #3
0
    function shortcode_altereports_func()
    {
        include_once ABSPATH . 'wp-admin/includes/plugin.php';
        include_once ABSPATH . WPINC . '/functions.php';
        global $wpdb, $woocommerce, $WC_Order, $woo_options, $WC_API_Reports, $WC_Admin_Dashboard, $WC_Admin_Reports, $WC_Admin_Report, $WC_Report_Customers, $WC_Report_Stock, $WC_alterinventory;
        $results = $wpdb->get_results('SELECT * FROM wp_options WHERE option_id = 1', OBJECT);
        $out = get_option('<h1 style="color:#F00">alterinventory_error_message</h1>', '<h1 style="color:#F00">Please use your Username and Password to Log In </h1>');
        $options = get_option('alterinventory_options');
        $user = wp_get_current_user();
        if (empty($user->ID)) {
            echo $out;
        }
        if (!is_user_logged_in()) {
            wp_login_form();
        } else {
            ?>
    <?php 
            /**
             * Template for Direct Sells
             */
            if (!defined('ABSPATH')) {
                exit;
            }
            global $wpdb, $Product, $item, $item_meta, $product, $woocommerce, $woo_options, $order_count, $WC_API_Reports, $WC_Admin_Dashboard, $WC_Admin_Reports, $WC_Admin_Report, $WC_Report_Customers, $WC_Report_Stock, $WC_alterinventory;
            $customer_orders = get_posts(apply_filters('woocommerce_my_account_my_orders_query', array('numberposts' => $order_count, 'meta_key' => '_customer_user', 'meta_value' => get_current_user_id(), 'post_type' => 'shop_order', 'post_status' => 'publish', 'posts_per_page' => -1, 'paged' => get_query_var('paged'))));
            if ($customer_orders) {
                ?>
<div align="right" style="margin-bottom:-60px" >
<script type="text/javascript">
 function printPage(){
        var tableData = '<table border="1">'+document.getElementsByTagName('table')[0].innerHTML+'</table>';
        var data = '<button onclick="window.print()"> Print </button>'+tableData;
        myWindow=window.open('','','width=1000,height=800px');
        myWindow.innerWidth = screen.width;
        myWindow.innerHeight = screen.height;
        myWindow.screenX = 0;
        myWindow.screenY = 0;
        myWindow.document.write(data);
        myWindow.focus();
    };
 </script>

 <br />
    <a href="javascript:void(0);" class="button" type="submit"  id="printPage" onclick="printPage();">Print</a>
    |
    <a href="alter-inventory/" class="button" type="submit" >
Aggiorna</a>
    <br />
    
    </div>
   
	
<div style="margin-bottom: 40px;" >
<?php 
                $form = '<form role="search" method="get" id="searchform" action="' . esc_url(home_url('/')) . '">
	<div>
		<label class="screen-reader-text" for="s">' . __('Cerca Vendite:', 'woocommerce') . '</label>
		<input type="text" value="' . get_search_query() . '" name="s" id="s" placeholder="' . __('Vendite..', 'woocommerce') . '" />
		<input class="button" type="submit" id="searchsubmit" value="' . esc_attr__('Search', 'woocommerce') . '" />
		<input type="hidden" name="post_type" value="product" />
	</div>
</form>';
                echo $form;
                ?>
</div>
<h2>VENDITE</h2>
   
	<table class="shop_table my_account_orders">

		<thead>
        
			<tr>
   
				<th class="order-number"><span class="nobr"><?php 
                _e('#ID Vendita', 'woocommerce');
                ?>
</span></th>
				<th class="order-date"><span class="nobr"><?php 
                _e('Data', 'woocommerce');
                ?>
</span></th>
				<th class="order-status"><span class="nobr"><?php 
                _e('Stato', 'woocommerce');
                ?>
</span></th>
				<th class="order-total"><span class="nobr"><?php 
                _e('Totale', 'woocommerce');
                ?>
</span></th>
                <th class="order-actions"><span class="nobr"><?php 
                _e('Prodotti / Attributi / Totale', 'woocommerce');
                ?>
</span></th>
				<th class="order-actions"><span class="nobr"><?php 
                _e('Dettagli', 'woocommerce');
                ?>
</span></th>
                <th class="order-actions"><span class="nobr"><?php 
                _e('Annullare', 'woocommerce');
                ?>
</span></th>
			</tr>
		</thead>

 <style>
								
								.hentry img { height: auto; max-width: 35%;}
								.woocommerce-message { display:none;}
						    </style>
		<tbody><?php 
                foreach ($customer_orders as $customer_order) {
                    $order = new WC_Order();
                    $order->populate($customer_order);
                    $status = get_term_by('slug', $order->status, 'shop_order_status');
                    $item_count = $order->get_item_count();
                    ?>
<tr class="order">
					<td class="order-number">
						<a href="<?php 
                    echo $order->get_view_order_url();
                    ?>
">
							<?php 
                    echo $order->get_order_number();
                    ?>
						</a>
					</td>
					<td class="order-date">
						<time datetime="<?php 
                    echo date('Y-m-d', strtotime($order->order_date));
                    ?>
" title="<?php 
                    echo esc_attr(strtotime($order->order_date));
                    ?>
"><?php 
                    echo date_i18n(get_option('date_format'), strtotime($order->order_date));
                    ?>
</time>
					</td>
					<td class="order-status" style="text-align:left; text-transform:uppercase; white-space:nowrap; color:#0C0"  >
						<?php 
                    echo ucfirst(__($status->name, 'woocommerce'));
                    ?>
					</td>
					<td class="order-total">
						<?php 
                    echo sprintf(_n('<strong>%s</strong> x <strong>%s Prodotto</strong>', '%s for %s items', $item_count, 'woocommerce'), $order->get_formatted_order_total(), $item_count);
                    ?>
					</td>
                   
		
                 <td class="order-actions">
  <table class="shop_table order_details">
	<thead>
		<tr>
			<th class="product-name"><?php 
                    _e('Product', 'woocommerce');
                    ?>
</th>
			<th class="product-total"><?php 
                    _e('Total', 'woocommerce');
                    ?>
</th>
		</tr>
	</thead>
    
	<tfoot>
	
	</tfoot>
	<tbody>
		<?php 
                    if (sizeof($order->get_items()) > 0) {
                        foreach ($order->get_items() as $item) {
                            $_product = apply_filters('woocommerce_order_item_product', $order->get_product_from_item($item), $item);
                            $item_meta = new WC_Order_Item_Meta($item['item_meta'], $_product);
                            ?>
				<tr class="<?php 
                            echo esc_attr(apply_filters('woocommerce_order_item_class', 'order_item', $item, $order));
                            ?>
">
					<td  style="text-transform:uppercase;">
						<?php 
                            if ($_product && !$_product->is_visible()) {
                                echo apply_filters('woocommerce_order_item_name', $item['name'], $item);
                            } else {
                                echo apply_filters('woocommerce_order_item_name', sprintf('<a href="%s">%s</a>', get_permalink($item['product_id']), $item['name']), $item);
                            }
                            echo apply_filters('woocommerce_order_item_quantity_html', ' <strong class="product-quantity">' . sprintf('&times; %s', $item['qty']) . '</strong>', $item);
                            $item_meta->display();
                            if ($_product && $_product->exists() && $_product->is_downloadable() && $order->is_download_permitted()) {
                                $download_files = $order->get_item_downloads($item);
                                $i = 0;
                                $links = array();
                                foreach ($download_files as $download_id => $file) {
                                    $i++;
                                    $links[] = '<small><a href="' . esc_url($file['download_url']) . '">' . sprintf(__('Download file%s', 'woocommerce'), count($download_files) > 1 ? ' ' . $i . ': ' : ': ') . esc_html($file['name']) . '</a></small>';
                                }
                                echo '<br/>' . implode('<br/>', $links);
                            }
                            ?>
					</td>
					<td class="product-total" style="color:#F00">
						<?php 
                            echo $order->get_formatted_line_subtotal($item);
                            ?>
					</td>
				</tr>
				
					<?php 
                        }
                    }
                    ?>
	</tbody>
</table>
<div class="clear"></div>
</td>
<td class="order-actions">
                 
						<?php 
                    $actions = array();
                    if (in_array($order->status, apply_filters('woocommerce_valid_order_statuses_for_payment', array('Incompleta', 'Fallita'), $order))) {
                    }
                    $actions['view'] = array('url' => $order->get_view_order_url(), 'name' => __('Dettagli', 'woocommerce'));
                    $actions = apply_filters('woocommerce_my_account_my_orders_actions', $actions, $order);
                    if ($actions) {
                        foreach ($actions as $key => $action) {
                            echo '<a href="' . esc_url($action['url']) . '" class="button ' . sanitize_html_class($key) . '">' . esc_html($action['name']) . '</a>';
                        }
                    }
                    ?>
  				</td>
                    <td class="order-actions">
                    	<?php 
                    $actions = array();
                    $actions['cancel'] = array('url' => $order->get_cancel_order_url(get_permalink(wc_get_page_id('alter-inventory'))), 'name' => __('Cancel', 'woocommerce'));
                    if ($actions) {
                        foreach ($actions as $key => $action) {
                            echo '<a href="' . esc_url($action['url']) . '" class="button ' . sanitize_html_class($key) . '">' . esc_html($action['name']) . '</a>';
                        }
                    }
                    ?>
					</td>
				</tr><?php 
                }
                ?>
</tbody>

	</table>
<?php 
            }
            ?>

	
	<?php 
        }
    }
    function widget($args, $instance)
    {
        extract($args, EXTR_SKIP);
        global $woocommerce;
        //$logged_out_title = (!empty()) ? $instance['logged_out_title'] : __('Customer Login', 'woocommerce-my-account-widget');
        $logged_out_title = apply_filters('widget_title', empty($instance['logged_out_title']) ? __('Customer Login', 'woocommerce-my-account-widget') : $instance['logged_out_title'], $instance);
        //$logged_in_title = (!empty()) ? $instance['logged_in_title'] : __('Welcome %s', 'woocommerce-my-account-widget');
        $logged_in_title = apply_filters('widget_title', empty($instance['logged_in_title']) ? __('Welcome %s', 'woocommerce-my-account-widget') : $instance['logged_in_title'], $instance);
        echo $before_widget;
        $c = isset($instance['show_cartlink']) && $instance['show_cartlink'] ? '1' : '0';
        $cart_page_id = get_option('woocommerce_cart_page_id');
        //check if user is logged in
        if (is_user_logged_in()) {
            $it = isset($instance['show_items']) && $instance['show_items'] ? '1' : '0';
            $u = isset($instance['show_upload']) && $instance['show_upload'] ? '1' : '0';
            $unew = isset($instance['show_upload_new']) && $instance['show_upload_new'] ? '1' : '0';
            $up = isset($instance['show_unpaid']) && $instance['show_unpaid'] ? '1' : '0';
            $p = isset($instance['show_pending']) && $instance['show_pending'] ? '1' : '0';
            $lo = isset($instance['show_logout_link']) && $instance['show_logout_link'] ? '1' : '0';
            // redirect url after login / logout
            if (is_multisite()) {
                $woo_ma_home = network_home_url();
            } else {
                $woo_ma_home = home_url();
            }
            $user = get_user_by('id', get_current_user_id());
            echo '<div class=login>';
            if ($user->first_name != "") {
                $uname = $user->first_name;
            } else {
                $uname = $user->display_name;
            }
            if ($logged_in_title) {
                echo $before_title . sprintf($logged_in_title, ucwords($uname)) . $after_title;
            }
            if ($c) {
                echo '<p><a class="woo-ma-button cart-link woo-ma-cart-link" href="' . get_permalink(wma_lang_id($cart_page_id)) . '" title="' . __('View your shopping cart', 'woocommerce-my-account-widget') . '">' . __('View your shopping cart', 'woocommerce-my-account-widget') . '</a></p>';
            }
            $notcompleted = 0;
            $uploadfile = 0;
            $uploadfile_new = 0;
            $notpaid = 0;
            $customer_id = get_current_user_id();
            if (version_compare(WOOCOMMERCE_VERSION, "2.2") < 0) {
                $customer_orders = get_posts(array('numberposts' => -1, 'meta_key' => '_customer_user', 'meta_value' => get_current_user_id(), 'post_type' => 'shop_order', 'post_status' => 'publish'));
            } else {
                $customer_orders = get_posts(apply_filters('woocommerce_my_account_my_orders_query', array('numberposts' => -1, 'meta_key' => '_customer_user', 'meta_value' => get_current_user_id(), 'post_type' => wc_get_order_types('view-orders'), 'post_status' => array_keys(wc_get_order_statuses()))));
            }
            if ($customer_orders) {
                foreach ($customer_orders as $customer_order) {
                    $woocommerce1 = 0;
                    if (version_compare(WOOCOMMERCE_VERSION, "2.2") < 0) {
                        $order = new WC_Order();
                        $order->populate($customer_order);
                    } else {
                        $order = wc_get_order($customer_order->ID);
                    }
                    //$status = get_term_by('slug', $order->status, 'shop_order_status');
                    if ($order->status != 'completed' && $order->status != 'cancelled') {
                        $notcompleted++;
                    }
                    /* upload files */
                    if (function_exists('woocommerce_umf_admin_menu')) {
                        if (get_max_upload_count($order) > 0) {
                            $j = 1;
                            foreach ($order->get_items() as $order_item) {
                                $max_upload_count = get_max_upload_count($order, $order_item['product_id']);
                                $i = 1;
                                $upload_count = 0;
                                while ($i <= $max_upload_count) {
                                    if (get_post_meta($order->id, '_woo_umf_uploaded_file_name_' . $j, true) != "") {
                                        $upload_count++;
                                    }
                                    $i++;
                                    $j++;
                                }
                                /* toon aantal nog aan te leveren bestanden */
                                $upload_count = $max_upload_count - $upload_count;
                                $uploadfile += $upload_count;
                            }
                        }
                    }
                    if (class_exists('WPF_Uploads')) {
                        // Uploads needed
                        $uploads_needed = WPF_Uploads::order_needs_upload($order, true);
                        $uploaded_count_new = WPF_Uploads::order_get_upload_count($order->id);
                        $uploads_needed_left = $uploads_needed - $uploaded_count_new;
                        $uploadfile_new = $uploadfile_new + $uploads_needed_left;
                    }
                    if (in_array($order->status, array('on-hold', 'pending', 'failed'))) {
                        $notpaid++;
                    }
                }
            }
            $my_account_id = wma_lang_id(get_option('woocommerce_myaccount_page_id'));
            echo '<ul class="clearfix woo-ma-list">';
            if ($it) {
                //$woocommerce->cart->get_cart_url()
                echo '<li class="woo-ma-link item">
						<a class="cart-contents-new" href="' . get_permalink(wma_lang_id($cart_page_id)) . '" title="' . __('View your shopping cart', 'woocommerce-my-account-widget') . '">
							<span>' . $woocommerce->cart->cart_contents_count . '</span> ' . _n('product in your shopping cart', 'products in your shopping cart', $woocommerce->cart->cart_contents_count, 'woocommerce-my-account-widget') . '
						</a>
					</li>';
            }
            if ($u && function_exists('woocommerce_umf_admin_menu')) {
                echo '<li class="woo-ma-link upload">
						<a href="' . get_permalink($my_account_id) . '" title="' . __('Upload files', 'woocommerce-my-account-widget') . '">
							<span>' . $uploadfile . '</span> ' . _n('file to upload', 'files to upload', $uploadfile, 'woocommerce-my-account-widget') . '
						</a>
					</li>';
            }
            if ($unew && class_exists('WPF_Uploads')) {
                echo '<li class="woo-ma-link upload">
						<a href="' . get_permalink($my_account_id) . '" title="' . __('Upload files', 'woocommerce-my-account-widget') . '">
							<span>' . $uploadfile_new . '</span> ' . _n('file to upload', 'files to upload', $uploadfile_new, 'woocommerce-my-account-widget') . '
						</a>
					</li>';
            }
            if ($up) {
                echo '<li class="woo-ma-link paid">
						<a href="' . get_permalink($my_account_id) . '" title="' . __('Pay orders', 'woocommerce-my-account-widget') . '">
							<span>' . $notpaid . '</span> ' . _n('payment required', 'payments required', $notpaid, 'woocommerce-my-account-widget') . '
						</a>
					</li>';
            }
            if ($p) {
                echo '<li class="woo-ma-link pending">
						<a href="' . get_permalink($my_account_id) . '" title="' . __('View uncompleted orders', 'woocommerce-my-account-widget') . '">
							<span>' . $notcompleted . '</span> ' . _n('order pending', 'orders pending', $notcompleted, 'woocommerce-my-account-widget') . '
						</a>
					</li>';
            }
            echo '</ul>';
            echo '<p><a class="woo-ma-button woo-ma-myaccount-link myaccount-link" href="' . get_permalink($my_account_id) . '" title="' . __('My Account', 'woocommerce-my-account-widget') . '">' . __('My Account', 'woocommerce-my-account-widget') . '</a></p>';
            if ($lo == 1) {
                echo '<p><a class="woo-ma-button woo-ma-logout-link logout-link" href="' . wp_logout_url($woo_ma_home) . '" title="' . __('Log out', 'woocommerce-my-account-widget') . '">' . __('Log out', 'woocommerce-my-account-widget') . '</a></p>';
            }
        } else {
            echo '<div class=logout>';
            // user is not logged in
            if ($logged_out_title) {
                echo $before_title . $logged_out_title . $after_title;
            }
            if (isset($_GET['login']) && $_GET['login'] == 'failed') {
                echo '<p class="woo-ma-login-failed woo-ma-error">';
                _e('Login failed, please try again', 'woocommerce-my-account-widget');
                echo '</p>';
            }
            // login form
            $args = array('echo' => true, 'form_id' => 'wma_login_form', 'label_username' => __('Username', 'woocommerce-my-account-widget'), 'label_password' => __('Password', 'woocommerce-my-account-widget'), 'label_remember' => __('Remember Me', 'woocommerce-my-account-widget'), 'label_log_in' => __('Log In', 'woocommerce-my-account-widget'), 'id_username' => 'user_login', 'id_password' => 'user_pass', 'id_remember' => 'rememberme', 'id_submit' => 'wp-submit', 'remember' => true, 'value_username' => NULL, 'value_remember' => false);
            if (isset($instance['wma_redirect']) && $instance['wma_redirect'] != "") {
                $args['redirect'] = get_permalink(wma_lang_id($instance['wma_redirect']));
            }
            wp_login_form($args);
            echo '<a class="woo-ma-link woo-ma-lost-pass" href="' . wp_lostpassword_url() . '">' . __('Lost password?', 'woocommerce-my-account-widget') . '</a>';
            if (get_option('users_can_register')) {
                echo ' <a class="woo-ma-button woo-ma-register-link register-link" href="' . get_permalink(get_option('woocommerce_myaccount_page_id')) . '" title="' . __('Register', 'woocommerce-my-account-widget') . '">' . __('Register', 'woocommerce-my-account-widget') . '</a>';
            }
            if ($c) {
                echo '<p><a class="woo-ma-button woo-ma-cart-link cart-link" href="' . get_permalink(wma_lang_id($cart_page_id)) . '" title="' . __('View your shopping cart', 'woocommerce-my-account-widget') . '">' . __('View your shopping cart', 'woocommerce-my-account-widget') . '</a></p>';
            }
        }
        echo '</div>';
        echo $after_widget;
    }
Example #5
0
function swr_profile_rewards($user)
{
    global $woocommerce, $swr_settings;
    $rewards = swr_get_user_current_rewards(array('user_id' => $user->ID));
    ?>
	<h3><?php 
    _e('Rewards', 'rewards');
    ?>
</h3>
	<table class="form-table">
		<tr>
			<th>
				<label for="gateways"><?php 
    echo sprintf(__('Current %s earned', 'rewards'), $swr_settings->get_title());
    ?>
</label>
			</th>
			<td>
				<input type="text" name="swr_rewards" id="swr_rewards" value="<?php 
    echo $rewards;
    ?>
" class="regular-text">
			</td>
		</tr>
	</table>
	<?php 
    global $woocommerce, $recent_orders, $swr_settings;
    /* $swr_settings = $woocommerce->rewards->rewards['rewards_settings']; */
    $customer_id = $user->ID;
    $args = array('numberposts' => $recent_orders, 'meta_key' => '_customer_user', 'meta_value' => $customer_id, 'post_type' => 'shop_order', 'post_status' => 'publish');
    $customer_orders = get_posts($args);
    $msg = sprintf(__('Current %s balance: %s', 'rewards'), $swr_settings->get_title(), swr_get_user_current_rewards(array('user_id' => $customer_id, 'formatted' => true)));
    if ($customer_orders) {
        ?>
	<h4><?php 
        _e("Orders", "rewards");
        ?>
</h4>
	<table class="shop_table my_account_orders" style="width:50%;">
	
		<thead>
			<tr>
				<th class="order-number" style="width:35%;"><span class="nobr"><?php 
        _e('Order', 'rewards');
        ?>
</span></th>
				<th class="order-total rewards-earned" style="width:20%;"><span class="nobr"><?php 
        _e('Total earned', 'rewards');
        ?>
</span></th>
				<th class="order-total rewards-used" style="width:20%;"><span class="nobr"><?php 
        _e('Total Used', 'rewards');
        ?>
</span></th>
				<th class="order-total rewards-status" style="width:25%;"><span class="nobr"><?php 
        _e('Status', 'rewards');
        ?>
</span></th>
			</tr>
		</thead>
		
		<tbody><?php 
        foreach ($customer_orders as $customer_order) {
            $order = new WC_Order();
            $order->populate($customer_order);
            $status = get_term_by('slug', $order->status, 'shop_order_status');
            ?>
<tr class="order">
					<td class="order-number" width="1%">
						<a href="<?php 
            echo admin_url('post.php?post=' . $order->id . '&action=edit');
            ?>
"><?php 
            echo $order->get_order_number();
            ?>
</a> &ndash; <time title="<?php 
            echo esc_attr(strtotime($order->order_date));
            ?>
"><?php 
            echo date_i18n(get_option('date_format'), strtotime($order->order_date));
            ?>
</time>
					</td>
					<td class="order-total rewards-earned" width="1%"><?php 
            echo $swr_settings->format_reward($order->rewards_earned);
            ?>
</td>
					<td class="order-total rewards-used" width="1%"><?php 
            echo $swr_settings->format_reward($order->rewards_used);
            ?>
</td>
					<td class="order-total rewards-status" width="1%"><?php 
            _e($status->name, 'woocommerce');
            ?>
</td>
				</tr><?php 
        }
        ?>
</tbody>
	
	</table>
<?php 
    } else {
        ?>
	<p><?php 
        _e('You have no recent orders.', 'rewards');
        ?>
</p>
<?php 
    }
    if ($swr_settings->review_enabled()) {
        $comments = array();
        $tmp_comments = get_comments(array('user_id' => $customer_id));
        if ($tmp_comments && count($tmp_comments) > 0) {
            foreach ($tmp_comments as $tmp_comment) {
                $met = get_comment_meta($tmp_comment->comment_ID, 'rewards_earned', true);
                if ($met) {
                    $comments[] = array('item_id' => $tmp_comment->comment_post_ID, 'date' => $tmp_comment->comment_date, 'reward' => $met, 'status' => wp_get_comment_status($tmp_comment->comment_ID));
                }
            }
        }
        if ($comments && count($comments) > 0) {
            ?>
<h2><?php 
            _e("Reviews", "rewards");
            ?>
</h2>
	<table class="shop_table my_account_orders">
	
		<thead>
			<tr>
				<th class="order-number" style="width:35%;"><span class="nobr"><?php 
            _e('Date', 'rewards');
            ?>
</span></th>
				<th class="order-total rewards-product" style="width:20%;"><span class="nobr"><?php 
            _e('Product', 'rewards');
            ?>
</span></th>
				<th class="order-total rewards-earned" style="width:20%;"><span class="nobr"><?php 
            _e('Total earned', 'rewards');
            ?>
</span></th>
				<th class="order-total rewards-status" style="width:25%;"><span class="nobr"><?php 
            _e('Status', 'rewards');
            ?>
</span></th>
			</tr>
		</thead>
		
		<tbody><?php 
            foreach ($comments as $comment) {
                ?>
<tr class="comment">
					<td class="order-number"><?php 
                echo date_i18n(get_option('date_format'), strtotime($comment['date']));
                ?>
</td>
					<td class="order-total rewards-product"><?php 
                echo get_the_title($comment['item_id']);
                ?>
</td>
					<td class="order-total rewards-earned"><?php 
                echo $comment['reward'];
                ?>
</td>
					<td class="order-total rewards-status"><?php 
                _ex(ucfirst($comment['status']), 'adjective');
                ?>
</td>
				</tr><?php 
            }
            ?>
</tbody>
	
	</table>
<?php 
        } else {
            ?>
	<p><?php 
            _e('You have to review an item first', 'rewards');
            ?>
</p>
<?php 
        }
    }
}
function _woocommercecivicrm_customer_orders($uid)
{
    $customer_orders = get_posts(apply_filters('woocommerce_my_account_my_orders_query', array('meta_key' => '_customer_user', 'meta_value' => $uid, 'post_type' => 'shop_order', 'post_status' => array_keys(wc_get_order_statuses()))));
    $site_url = get_site_url();
    $orders = array();
    foreach ($customer_orders as $customer_order) {
        $order = new WC_Order();
        $order->populate($customer_order);
        $status = get_term_by('slug', $order->status, 'shop_order_status');
        //$items = $order->get_items();
        //print_r ($items);
        $item_count = $order->get_item_count();
        $total = $order->get_total();
        $orders[$customer_order->ID]['order_number'] = $order->get_order_number();
        $orders[$customer_order->ID]['order_date'] = date('Y-m-d', strtotime($order->order_date));
        $orders[$customer_order->ID]['order_billing_name'] = $order->get_formatted_billing_full_name();
        $orders[$customer_order->ID]['order_shipping_name'] = $order->get_formatted_shipping_full_name();
        $orders[$customer_order->ID]['item_count'] = $item_count;
        $orders[$customer_order->ID]['order_total'] = $total;
        $orders[$customer_order->ID]['order_link'] = $site_url . "/wp-admin/post.php?action=edit&post=" . $order->get_order_number();
        //$orders['order_total'] = $order->get_order_number();
    }
    return $orders;
}
        function my_account_orders()
        {
            global $woocommerce;
            $customer_id = get_current_user_id();
            if (version_compare(WC_VERSION, '2.2.0', '<')) {
                $args = array('numberposts' => 50, 'meta_key' => '_customer_user', 'meta_value' => $customer_id, 'post_type' => 'shop_order', 'meta_query' => array(array('key' => '_funds_deposited', 'value' => '1')));
            } else {
                $args = array('numberposts' => 50, 'meta_key' => '_customer_user', 'meta_value' => $customer_id, 'post_type' => 'shop_order', 'post_status' => array('wc-completed', 'wc-processing', 'wc-on-hold'), 'meta_query' => array(array('key' => '_funds_deposited', 'value' => '1')));
            }
            $deposits = get_posts($args);
            ?>
            <h2><?php 
            _e('Recent Deposits', 'wc_account_funds');
            ?>
</h2>
            <?php 
            if ($deposits) {
                ?>
            <table class="shop_table my_account_deposits">

                <thead>
                    <tr>
                        <th class="order-number"><span class="nobr"><?php 
                _e('Order', 'woocommerce');
                ?>
</span></th>
                        <th class="order-date"><span class="nobr"><?php 
                _e('Date', 'woocommerce');
                ?>
</span></th>
                        <th class="order-total"><span class="nobr"><?php 
                _e('Total', 'woocommerce');
                ?>
</span></th>
                        <th class="order-status" colspan="2"><span class="nobr"><?php 
                _e('Status', 'woocommerce');
                ?>
</span></th>
                    </tr>
                </thead>

                <tbody><?php 
                foreach ($deposits as $deposit) {
                    $order = new WC_Order();
                    $order->populate($deposit);
                    $status = get_term_by('slug', $order->status, 'shop_order_status');
                    ?>
<tr class="order">
                            <td class="order-number" width="1%">
                                <a href="<?php 
                    echo esc_url(add_query_arg('order', $order->id, get_permalink(woocommerce_get_page_id('view_order'))));
                    ?>
"><?php 
                    echo $order->get_order_number();
                    ?>
</a>
                            </td>
                            <td class="order-date"><time title="<?php 
                    echo esc_attr(strtotime($order->order_date));
                    ?>
"><?php 
                    echo date_i18n(get_option('date_format'), strtotime($order->order_date));
                    ?>
</time></td>
                            <td class="order-total" width="1%"><?php 
                    echo $order->get_formatted_order_total();
                    ?>
</td>
                            <td class="order-status" style="text-align:left; white-space:nowrap;">
                                <?php 
                    echo ucfirst(__($status->name, 'woocommerce'));
                    ?>
                                <?php 
                    if (in_array($order->status, array('pending', 'failed'))) {
                        ?>
                                    <a href="<?php 
                        echo esc_url($order->get_cancel_order_url());
                        ?>
" class="cancel" title="<?php 
                        _e('Click to cancel this order', 'woocommerce');
                        ?>
">(<?php 
                        _e('Cancel', 'woocommerce');
                        ?>
)</a>
                                <?php 
                    }
                    ?>
                            </td>
                            <td class="order-actions" style="text-align:right; white-space:nowrap;">

                                <?php 
                    if (in_array($order->status, array('pending', 'failed'))) {
                        ?>
                                    <a href="<?php 
                        echo esc_url($order->get_checkout_payment_url());
                        ?>
" class="button pay"><?php 
                        _e('Pay', 'woocommerce');
                        ?>
</a>
                                <?php 
                    }
                    ?>

                                <a href="<?php 
                    echo esc_url(add_query_arg('order', $order->id, get_permalink(woocommerce_get_page_id('view_order'))));
                    ?>
" class="button"><?php 
                    _e('View', 'woocommerce');
                    ?>
</a>


                            </td>
                        </tr><?php 
                }
                ?>
</tbody>

            </table>
            <?php 
            } else {
                ?>
            <p><?php 
                _e('You have no recent deposits.', 'wc_account_funds');
                ?>
</p>
            <?php 
            }
        }
 /**
  * Prepare the list of pre-order items for display
  *
  * @see WP_List_Table::prepare_items()
  * @since 1.0
  */
 public function prepare_items()
 {
     $this->process_actions();
     $per_page = $this->get_items_per_page('wc_pre_orders_edit_pre_orders_per_page');
     // main query args
     $args = array('post_type' => 'shop_order', 'post_status' => array('publish', 'trash'), 'posts_per_page' => $per_page, 'paged' => $this->get_pagenum(), 'orderby' => $this->get_current_orderby(), 'order' => $this->get_current_order(), 'meta_query' => array(array('key' => '_wc_pre_orders_is_pre_order', 'value' => 1)));
     // Pre-order status view
     $args = $this->add_view_args($args);
     // Filter: pre-orders by customer
     $args = $this->add_filter_args($args);
     // handle search
     $args = $this->add_search_args($args);
     $args = apply_filters('wc_pre_orders_edit_pre_orders_request', $args);
     $query = new WP_Query($args);
     $this->items = array();
     foreach ($query->posts as $order_post) {
         $order = new WC_Order();
         $order->populate($order_post);
         $this->items[] = $order;
     }
     $this->set_pagination_args(array('total_items' => $query->found_posts, 'per_page' => $per_page, 'total_pages' => ceil($query->found_posts / $per_page)));
 }
function display_camp_emails()
{
    $terms = get_terms(array('camp'));
    ?>
    <h1>Get Emails</h1>
    <form action="" method="post">
        <select name="camp" id="camp">
            <option value="">-</option>
            <?php 
    foreach ($terms as $term) {
        ?>
                <?php 
        $selected = isset($_POST['camp']) ? selected($term->slug, $_POST['camp'], false) : '';
        ?>
                <option value="<?php 
        echo $term->slug;
        ?>
" <?php 
        echo $selected;
        ?>
><?php 
        echo $term->name;
        ?>
</option>
            <?php 
    }
    ?>
        </select>
        <input type="submit" value="Get Email List" />
    </form>
    
    <?php 
    if (isset($_POST['camp'])) {
        $results = get_posts(array('post_type' => 'player', 'camp' => $_POST['camp'], 'meta_key' => 'guardian_email', 'posts_per_page' => -1));
        $email_list = array();
        foreach ($results as $player) {
            $email_list[] = get_post_meta($player->ID, 'guardian_email', true);
        }
        $list = implode(', ', array_unique($email_list));
        ?>
        <textarea name="list" id="list" cols="30" rows="10">
        <?php 
        echo $list;
        ?>
        </textarea>
        <?php 
    }
    ?>
    <h1>Orders on-hold</h1>
    <form action="" method="post">
        <input type="submit" value="Get On-hold emails" name="orders-on-hold" />
    </form>
    <?php 
    if (isset($_POST['orders-on-hold'])) {
        $args = array('post_type' => 'shop_order', 'post_status' => 'publish', 'meta_key' => '_customer_user', 'posts_per_page' => -1, 'tax_query' => array(array('taxonomy' => 'shop_order_status', 'field' => 'slug', 'terms' => 'on-hold')));
        $my_query = new WP_Query($args);
        $customer_orders = $my_query->posts;
        $email_list = array();
        foreach ($customer_orders as $customer_order) {
            $order = new WC_Order();
            $order->populate($customer_order);
            $email_list[] = $order->billing_email;
        }
        $list = implode(', ', array_unique($email_list));
        ?>
        <textarea name="on-hold-list" id="on-hold-list" cols="30" rows="10"><?php 
        echo $list;
        ?>
</textarea>
        <?php 
    }
    //end if $_POST
}
 public function update_user_rewards_used()
 {
     $rewards_used = array();
     $orders = get_posts(array('numberposts' => -1, 'post_type' => 'shop_order', 'post_status' => 'publish'));
     if ($orders) {
         foreach ($orders as $corder) {
             $order = new WC_Order();
             $order->populate($corder);
             $status = get_term_by('slug', $order->status, 'shop_order_status');
             if ($order->status == 'completed') {
                 $used = $this->get_reward_used_for_order($order->id);
                 if (!isset($rewards_used[$order->customer_user])) {
                     $rewards_used[$order->customer_user] = 0;
                 }
                 $rewards_used[$order->customer_user] += $used;
             }
         }
     }
     if (!empty($rewards_used)) {
         foreach ($rewards_used as $user_id => $used) {
             update_user_meta($user_id, 'swr_rewards_used', $used);
         }
     }
 }
 /**
  * Gets all pre-orders for the currently logged in user, or the user identified by $user_id
  *
  * @since 1.0
  * @param int $user_id optional user id to return pre-orders for. Defaults to the currently logged in user.
  * @return array of WC_Order objects
  */
 public static function get_users_pre_orders($user_id = null)
 {
     if (is_null($user_id)) {
         $user_id = get_current_user_id();
     }
     $args = array('post_type' => 'shop_order', 'post_status' => 'publish', 'nopaging' => true, 'meta_query' => array(array('key' => '_customer_user', 'value' => $user_id), array('key' => '_wc_pre_orders_is_pre_order', 'value' => 1)));
     $posts = get_posts($args);
     $orders = array();
     foreach ($posts as $order_post) {
         $order = new WC_Order();
         $order->populate($order_post);
         $orders[] = $order;
     }
     return apply_filters('wc_pre_orders_users_pre_orders', $orders, $user_id);
 }