Please log in.
'; if ( get_option( 'vv_enable_chat' ) !== 'yes' ) return ''; $uid = get_current_user_id(); $conv_id = (int) ( $_GET['conv'] ?? 0 ); global $wpdb; // Get all conversations $convs = $wpdb->get_results( $wpdb->prepare( "SELECT m.conversation_id, CASE WHEN m.sender_id=%d THEN m.receiver_id ELSE m.sender_id END AS other_id, MAX(m.created_at) AS last_msg, SUM(CASE WHEN m.receiver_id=%d AND m.is_read=0 THEN 1 ELSE 0 END) AS unread, (SELECT message FROM {$wpdb->prefix}vv_messages WHERE conversation_id=m.conversation_id ORDER BY id DESC LIMIT 1) AS preview FROM {$wpdb->prefix}vv_messages m WHERE m.sender_id=%d OR m.receiver_id=%d GROUP BY m.conversation_id, other_id ORDER BY last_msg DESC LIMIT 50", $uid, $uid, $uid, $uid ) ); // Load messages for active conversation $messages = []; $other_id = 0; $last_id = 0; if ( $conv_id ) { $messages = $wpdb->get_results( $wpdb->prepare( "SELECT m.*, u.display_name FROM {$wpdb->prefix}vv_messages m LEFT JOIN {$wpdb->prefix}users u ON m.sender_id=u.ID WHERE m.conversation_id=%d ORDER BY m.created_at ASC LIMIT 100", $conv_id ) ); $wpdb->update( "{$wpdb->prefix}vv_messages", ['is_read'=>1], ['conversation_id'=>$conv_id,'receiver_id'=>$uid] ); foreach ( $messages as $m ) { if ( $m->sender_id != $uid ) $other_id = $m->sender_id; elseif ( $m->receiver_id != $uid ) $other_id = $m->receiver_id; $last_id = max( $last_id, (int) $m->id ); } if ( ! $other_id && $messages ) { $first = reset( $messages ); $other_id = $first->sender_id == $uid ? $first->receiver_id : $first->sender_id; } } $other_user = $other_id ? get_user_by( 'id', $other_id ) : null; ob_start(); ?>
Messages
No conversations yet.
other_id ); if ( ! $other ) continue; $active = $conv_id == $c->conversation_id ? 'active' : ''; $initials = strtoupper( substr( $other->display_name, 0, 1 ) ); $url = add_query_arg( 'conv', $c->conversation_id ); ?>
display_name ); ?>
preview ?? '', 0, 30, '…' ) ); ?>
unread > 0 ) : ?> unread ); ?>
display_name, 0, 1 ) ) ); ?>
display_name ); ?>
Active
sender_id === $uid; ?>
message ); ?>
created_at ) ) ); ?>

Select a conversation to start chatting

You can also contact vendors from their store page