Untitled

 avatar
unknown
plain_text
a year ago
1.3 kB
4
Indexable

function user_last_login( ) {
    update_user_meta( get_current_user_id(), 'last_login', time() );
}
add_action( 'init', 'user_last_login', 10, 2 );

  
function wpb_lastlogin($user_id) { 
    $last_login = get_user_meta($user_id, 'last_login', true);
    if (!empty($last_login)){
    	$the_login_date = human_time_diff($last_login).' ago';
    } else {
    	$the_login_date = 'Not available';
    }
    return $the_login_date; 
}
add_action('salesking_customers_custom_columns_header', function(){
	?>
	<th class="nk-tb-col tb-col-md"><span class="sub-text"><?php esc_html_e('Last Login','salesking'); ?></span></th>
	<th class="nk-tb-col tb-col-md"><span class="sub-text"><?php esc_html_e('Last Order','salesking'); ?></span></th>
	<?php
});
add_action('salesking_customers_custom_columns_content', function($customer){
	?>
	<td class="nk-tb-col tb-col-md" data-order="<?php echo esc_attr($customer->get_total_spent());?>">
	    <div>
	        <span class="tb-amount"><?php echo wpb_lastlogin($customer->get_id());?></span>
	    </div>
	</td>
	<td class="nk-tb-col tb-col-md">
	    <div>
	        <span class="tb-amount"><?php 

	        $order = $customer->get_last_order();
	        if ($order){
	        	$date = $order->get_date_created();
	        	echo $date->date_i18n();
	        }

	    	?></span>
	    </div>
	</td>
	<?php
}, 10, 1);
Leave a Comment