Add agent selection to properties with contact integration
- Changed listing_agent ACF field from user type to post_object (Agent CPT) - Assigned random agents to all existing properties - Updated property-agent.php template to: - Pull agent data from Agent CPT (photo, phone, email, title) - Link agent name to their profile page - Show generic contact card when no agent assigned - Always show "Request Information" widget linking to contact page - Added property inquiry flow: - Contact links include ?property=PropertyName GET parameter - Contact page pre-fills message with property inquiry text - JS handles CF7 textarea pre-fill if plugin is active - Added styles for new property-inquiry-card and generic-contact-card widgets 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
+1
-1
File diff suppressed because one or more lines are too long
@@ -278,12 +278,13 @@ function homeproz_register_acf_fields() {
|
|||||||
'key' => 'field_property_listing_agent',
|
'key' => 'field_property_listing_agent',
|
||||||
'label' => 'Listing Agent',
|
'label' => 'Listing Agent',
|
||||||
'name' => 'listing_agent',
|
'name' => 'listing_agent',
|
||||||
'type' => 'user',
|
'type' => 'post_object',
|
||||||
'instructions' => 'Select the listing agent for this property',
|
'instructions' => 'Select the listing agent for this property. Leave empty to show generic contact information.',
|
||||||
'role' => '',
|
'post_type' => array('agent'),
|
||||||
'allow_null' => 1,
|
'allow_null' => 1,
|
||||||
'multiple' => 0,
|
'multiple' => 0,
|
||||||
'return_format' => 'array',
|
'return_format' => 'id',
|
||||||
|
'ui' => 1,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'location' => array(
|
'location' => array(
|
||||||
|
|||||||
@@ -17,6 +17,13 @@ get_header();
|
|||||||
$phone = homeproz_get_option('phone', '507-516-4870');
|
$phone = homeproz_get_option('phone', '507-516-4870');
|
||||||
$email = homeproz_get_option('email', 'info@homeprozrealestate.com');
|
$email = homeproz_get_option('email', 'info@homeprozrealestate.com');
|
||||||
$address = homeproz_get_option('address', '111 E Clark St, Albert Lea, MN 56007');
|
$address = homeproz_get_option('address', '111 E Clark St, Albert Lea, MN 56007');
|
||||||
|
|
||||||
|
// Check for property inquiry parameter
|
||||||
|
$property_inquiry = isset($_GET['property']) ? sanitize_text_field(urldecode($_GET['property'])) : '';
|
||||||
|
$prefilled_message = '';
|
||||||
|
if ($property_inquiry) {
|
||||||
|
$prefilled_message = 'I would like to get more information on property: ' . $property_inquiry;
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<main id="primary" class="site-main contact-page-main">
|
<main id="primary" class="site-main contact-page-main">
|
||||||
@@ -65,7 +72,7 @@ $address = homeproz_get_option('address', '111 E Clark St, Albert Lea, MN 56007'
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="contact-message">Message <span class="required">*</span></label>
|
<label for="contact-message">Message <span class="required">*</span></label>
|
||||||
<textarea id="contact-message" name="message" rows="5" required></textarea>
|
<textarea id="contact-message" name="message" rows="5" required><?php echo esc_textarea($prefilled_message); ?></textarea>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-primary">Send Message</button>
|
<button type="submit" class="btn btn-primary">Send Message</button>
|
||||||
</form>
|
</form>
|
||||||
@@ -89,7 +96,7 @@ $address = homeproz_get_option('address', '111 E Clark St, Albert Lea, MN 56007'
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="contact-message">Message <span class="required">*</span></label>
|
<label for="contact-message">Message <span class="required">*</span></label>
|
||||||
<textarea id="contact-message" name="message" rows="5" required></textarea>
|
<textarea id="contact-message" name="message" rows="5" required><?php echo esc_textarea($prefilled_message); ?></textarea>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-primary">Send Message</button>
|
<button type="submit" class="btn btn-primary">Send Message</button>
|
||||||
</form>
|
</form>
|
||||||
@@ -207,5 +214,24 @@ $address = homeproz_get_option('address', '111 E Clark St, Albert Lea, MN 56007'
|
|||||||
|
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
|
<?php if ($prefilled_message) : ?>
|
||||||
|
<script>
|
||||||
|
(function($) {
|
||||||
|
if (!$('.Contact_Page').length) return;
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
var prefilledMessage = <?php echo json_encode($prefilled_message); ?>;
|
||||||
|
|
||||||
|
// Try to find textarea in Contact Form 7 or fallback form
|
||||||
|
var $textarea = $('textarea[name="your-message"], textarea[name="message"], textarea#contact-message').first();
|
||||||
|
|
||||||
|
if ($textarea.length && !$textarea.val()) {
|
||||||
|
$textarea.val(prefilledMessage);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})(jQuery);
|
||||||
|
</script>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
get_footer();
|
get_footer();
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
/**
|
/**
|
||||||
* Property Agent Card Template Part
|
* Property Agent Card Template Part
|
||||||
*
|
*
|
||||||
|
* Displays either the assigned agent (from Agent CPT) or a generic contact card
|
||||||
|
*
|
||||||
* @package HomeProz
|
* @package HomeProz
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -10,36 +12,49 @@ if (!defined('ABSPATH')) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$agent = isset($args['agent']) ? $args['agent'] : null;
|
$agent_id = isset($args['agent']) ? $args['agent'] : null;
|
||||||
$property_id = isset($args['property_id']) ? $args['property_id'] : get_the_ID();
|
$property_id = isset($args['property_id']) ? $args['property_id'] : get_the_ID();
|
||||||
|
$property_title = get_the_title($property_id);
|
||||||
|
|
||||||
// Get company contact as fallback
|
// Build contact page URL with property parameter
|
||||||
$phone = homeproz_get_option('phone');
|
$contact_url = add_query_arg('property', urlencode($property_title), home_url('/contact/'));
|
||||||
$email = homeproz_get_option('email');
|
|
||||||
|
|
||||||
// If we have an agent user
|
// Get company contact info as fallback
|
||||||
if ($agent && is_array($agent)) {
|
$company_phone = homeproz_get_option('phone');
|
||||||
$agent_name = $agent['display_name'];
|
$company_email = homeproz_get_option('email');
|
||||||
$agent_email = $agent['user_email'];
|
|
||||||
// Try to get agent phone from user meta
|
// Check if we have a valid agent from Agent CPT
|
||||||
$agent_phone = get_user_meta($agent['ID'], 'phone', true) ?: $phone;
|
$has_agent = false;
|
||||||
} else {
|
$agent_name = '';
|
||||||
$agent_name = 'HomeProz Real Estate';
|
$agent_phone = '';
|
||||||
$agent_email = $email;
|
$agent_email = '';
|
||||||
$agent_phone = $phone;
|
$agent_title = '';
|
||||||
|
$agent_photo_url = '';
|
||||||
|
|
||||||
|
if ($agent_id && get_post_type($agent_id) === 'agent') {
|
||||||
|
$has_agent = true;
|
||||||
|
$agent_name = get_the_title($agent_id);
|
||||||
|
$agent_phone = get_field('agent_phone', $agent_id);
|
||||||
|
$agent_email = get_field('agent_email', $agent_id);
|
||||||
|
$agent_title = get_field('agent_title', $agent_id);
|
||||||
|
|
||||||
|
// Get agent featured image
|
||||||
|
$agent_photo_id = get_post_thumbnail_id($agent_id);
|
||||||
|
if ($agent_photo_id) {
|
||||||
|
$agent_photo_url = wp_get_attachment_image_url($agent_photo_id, 'thumbnail');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="agent-card card">
|
<?php if ($has_agent) : ?>
|
||||||
<div class="agent-card-header">
|
<!-- Agent Card -->
|
||||||
<h3 class="agent-card-title">Contact Agent</h3>
|
<div class="sidebar-widget agent-card">
|
||||||
</div>
|
<h3 class="widget-title">Listing Agent</h3>
|
||||||
|
|
||||||
<div class="agent-card-content">
|
|
||||||
<div class="agent-info">
|
<div class="agent-info">
|
||||||
<div class="agent-avatar">
|
<div class="agent-avatar">
|
||||||
<?php if ($agent && is_array($agent)) : ?>
|
<?php if ($agent_photo_url) : ?>
|
||||||
<?php echo get_avatar($agent['ID'], 80); ?>
|
<img src="<?php echo esc_url($agent_photo_url); ?>" alt="<?php echo esc_attr($agent_name); ?>">
|
||||||
<?php else : ?>
|
<?php else : ?>
|
||||||
<div class="agent-avatar-placeholder">
|
<div class="agent-avatar-placeholder">
|
||||||
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
|
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
|
||||||
@@ -50,14 +65,16 @@ if ($agent && is_array($agent)) {
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
<div class="agent-details">
|
<div class="agent-details">
|
||||||
<p class="agent-name"><?php echo esc_html($agent_name); ?></p>
|
<p class="agent-name">
|
||||||
<p class="agent-role">Listing Agent</p>
|
<a href="<?php echo esc_url(get_permalink($agent_id)); ?>"><?php echo esc_html($agent_name); ?></a>
|
||||||
|
</p>
|
||||||
|
<p class="agent-role"><?php echo esc_html($agent_title ?: 'Real Estate Agent'); ?></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="agent-contact">
|
<div class="agent-contact">
|
||||||
<?php if ($agent_phone) : ?>
|
<?php if ($agent_phone) : ?>
|
||||||
<a href="tel:<?php echo esc_attr(preg_replace('/[^0-9]/', '', $agent_phone)); ?>" class="btn btn-primary agent-phone-btn">
|
<a href="tel:<?php echo esc_attr(preg_replace('/[^0-9]/', '', $agent_phone)); ?>" class="btn btn-primary">
|
||||||
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
|
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
|
||||||
<path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"/>
|
<path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"/>
|
||||||
</svg>
|
</svg>
|
||||||
@@ -66,19 +83,51 @@ if ($agent && is_array($agent)) {
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php if ($agent_email) : ?>
|
<?php if ($agent_email) : ?>
|
||||||
<a href="mailto:<?php echo esc_attr($agent_email); ?>?subject=<?php echo esc_attr('Inquiry about ' . get_the_title($property_id)); ?>" class="btn btn-secondary agent-email-btn">
|
<a href="mailto:<?php echo esc_attr($agent_email); ?>?subject=<?php echo esc_attr('Inquiry about ' . $property_title); ?>" class="btn btn-secondary">
|
||||||
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
|
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
|
||||||
<path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"/>
|
<path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"/>
|
||||||
<polyline points="22,6 12,13 2,6"/>
|
<polyline points="22,6 12,13 2,6"/>
|
||||||
</svg>
|
</svg>
|
||||||
Send Email
|
Email Agent
|
||||||
</a>
|
</a>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Quick Inquiry Form (optional - can be expanded) -->
|
<!-- Property Inquiry Card (always shown) -->
|
||||||
<div class="agent-card-footer">
|
<div class="sidebar-widget property-inquiry-card">
|
||||||
<p class="agent-card-note">Interested in this property? Contact us today for a showing.</p>
|
<h3 class="widget-title">Request Information</h3>
|
||||||
|
<p class="inquiry-note">Have questions about this property? We're here to help.</p>
|
||||||
|
<a href="<?php echo esc_url($contact_url); ?>" class="btn btn-secondary btn-block">
|
||||||
|
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
|
||||||
|
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/>
|
||||||
|
</svg>
|
||||||
|
Contact Us About This Property
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
<?php else : ?>
|
||||||
|
<!-- Generic Contact Card (no agent assigned) -->
|
||||||
|
<div class="sidebar-widget generic-contact-card">
|
||||||
|
<h3 class="widget-title">Interested in This Property?</h3>
|
||||||
|
<p class="contact-note">Contact us for more information on this listing. Our team is ready to answer your questions and schedule a showing.</p>
|
||||||
|
|
||||||
|
<div class="generic-contact-actions">
|
||||||
|
<?php if ($company_phone) : ?>
|
||||||
|
<a href="tel:<?php echo esc_attr(preg_replace('/[^0-9]/', '', $company_phone)); ?>" class="btn btn-primary btn-block">
|
||||||
|
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
|
||||||
|
<path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"/>
|
||||||
|
</svg>
|
||||||
|
Call <?php echo esc_html($company_phone); ?>
|
||||||
|
</a>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<a href="<?php echo esc_url($contact_url); ?>" class="btn btn-secondary btn-block">
|
||||||
|
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
|
||||||
|
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/>
|
||||||
|
</svg>
|
||||||
|
Send Us a Message
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|||||||
@@ -405,6 +405,46 @@
|
|||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Property Inquiry Card
|
||||||
|
.property-inquiry-card {
|
||||||
|
.inquiry-note {
|
||||||
|
font-size: 0.9375rem;
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-block {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generic Contact Card (no agent)
|
||||||
|
.generic-contact-card {
|
||||||
|
.contact-note {
|
||||||
|
font-size: 0.9375rem;
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
margin-bottom: 1.25rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.generic-contact-actions {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-block {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Body class for lightbox
|
// Body class for lightbox
|
||||||
body.lightbox-open {
|
body.lightbox-open {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|||||||
Reference in New Issue
Block a user