Skip to main content
View Categories

homerunner_booking_widget_after_discount

5 min read

The homerunner_booking_widget_after_discount hook is a powerful WordPress action that allows developers to inject custom content into booking widgets after the discount section. This hook provides access to a comprehensive configuration array, making it possible to create dynamic, context-aware customization.

Understanding the Hook #

This hook fires at a specific point in the booking widget rendering process and passes a $config array containing valuable information about the current booking context, including property details, pricing information, user preferences, and widget settings.

Example 1: Simple Usage Without Configuration #

For basic implementations where you don’t need access to the booking configuration, you can create a simple hook that displays static content:

add_action('homerunner_booking_widget_after_discount', function() {
    ?>
    <div class="membership-promotion" style="padding: 10px; background-color: #f8f9fa; border-radius: 4px; margin-top: 10px;">
        <div style="display: flex; align-items: center; gap: 8px;">
            <span style="font-size: 18px;">⭐</span>
            <div>
                <strong>Special Offer!</strong><br>
                <small>Join our loyalty program for exclusive discounts.</small>
            </div>
        </div>
    </div>
    <?php
});

This example creates a simple promotional banner that appears consistently across all booking widgets, regardless of the specific property or booking details.

Example 2: Conditional Display Based on User Login Status #

Often, you’ll want to show different content depending on whether a user is logged in. This example demonstrates how to provide personalized messaging:

add_action('homerunner_booking_widget_after_discount', function($config) {
    if (is_user_logged_in()) {
        $current_user = wp_get_current_user();
        ?>
        <div class="member-benefits" style="padding: 12px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border-radius: 8px; margin-top: 10px;">
            <div style="display: flex; align-items: center; gap: 10px;">
                <div style="font-size: 24px;">🎉</div>
                <div>
                    <strong>Welcome back, <?php echo esc_html($current_user->display_name); ?>!</strong><br>
                    <small>Your member discount has been automatically applied.</small>
                </div>
            </div>
        </div>
        <?php
    } else {
        ?>
        <div class="guest-promotion" style="padding: 12px; border: 2px dashed #007cba; border-radius: 8px; margin-top: 10px;">
            <div style="display: flex; align-items: center; gap: 10px;">
                <div style="font-size: 24px;">💎</div>
                <div>
                    <strong>Unlock Member Savings!</strong><br>
                    <small>
                        <a href="/register/" style="color: #007cba; text-decoration: none; font-weight: bold;">
                            Create an account
                        </a> 
                        to save up to 15% on your stays.
                    </small>
                </div>
            </div>
        </div>
        <?php
    }
});

This implementation checks the user’s login status and displays personalized content accordingly, enhancing the user experience with relevant messaging.

Example 3: Property-Specific Customization Using Configuration #

The most powerful use case involves leveraging the $config array to create property-specific customizations. This example shows how to display different promotions based on the property:

add_action('homerunner_booking_widget_after_discount', function($config) {
    // Define property-specific promotions
    $property_promotions = [
        20365 => [
            'title' => 'Mountain Retreat Special',
            'description' => 'Book 5+ nights and get a complimentary hiking guide!',
            'icon' => '🏔️',
            'color' => '#2d5a27'
        ],
        12345 => [
            'title' => 'Beach House Bonus',
            'description' => 'Free beach equipment rental with weekly stays.',
            'icon' => '🏖️',
            'color' => '#1e88e5'
        ],
        67890 => [
            'title' => 'City Loft Perks',
            'description' => 'Complimentary metro passes for stays over 3 nights.',
            'icon' => '🏙️',
            'color' => '#8e24aa'
        ]
    ];
    
    $property_id = $config['property_id'] ?? 0;
    $min_stay = $config['min_stay'] ?? 1;
    $currency = $config['currency'] ?? 'USD';
    
    // Check if we have a specific promotion for this property
    if (isset($property_promotions[$property_id])) {
        $promotion = $property_promotions[$property_id];
        ?>
        <div class="property-promotion" style="padding: 15px; background-color: <?php echo esc_attr($promotion['color']); ?>; color: white; border-radius: 10px; margin-top: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">
            <div style="display: flex; align-items: center; gap: 12px;">
                <div style="font-size: 28px;"><?php echo $promotion['icon']; ?></div>
                <div style="flex: 1;">
                    <div style="font-size: 16px; font-weight: bold; margin-bottom: 4px;">
                        <?php echo esc_html($promotion['title']); ?>
                    </div>
                    <div style="font-size: 13px; opacity: 0.9;">
                        <?php echo esc_html($promotion['description']); ?>
                    </div>
                    <?php if ($min_stay > 1): ?>
                        <div style="font-size: 11px; margin-top: 6px; opacity: 0.8;">
                            Minimum stay: <?php echo $min_stay; ?> nights
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
        <?php
    } else {
        // Default promotion for properties without specific offers
        ?>
        <div class="default-promotion" style="padding: 12px; background: linear-gradient(45deg, #ff6b6b, #ee5a24); color: white; border-radius: 8px; margin-top: 10px;">
            <div style="display: flex; align-items: center; gap: 10px;">
                <div style="font-size: 24px;">🌟</div>
                <div>
                    <strong>Exclusive Guest Benefits</strong><br>
                    <small>Contact us for special rates and local recommendations!</small>
                    <?php if ($min_stay > 1): ?>
                        <br><small style="opacity: 0.8;">Minimum stay: <?php echo $min_stay; ?> nights</small>
                    <?php endif; ?>
                </div>
            </div>
        </div>
        <?php
    }
});

Advanced Configuration Usage #

The $config array contains numerous useful properties that can enhance your customizations:

  • Property Information: property_id, central_property_id, bedrooms_count
  • Booking Details: guests, min_stay, max_stay, checkin, checkout
  • Pricing: avg_rent, base_rent, lowest_rent, currency
  • Features: show_coupon, show_datepicker, price_modal
  • Localization: timezone, date_format, checkin_time

Here’s an example that uses multiple configuration values:

add_action('homerunner_booking_widget_after_discount', function($config) {
    $property_id = $config['property_id'] ?? 0;
    $max_guests = $config['max_guests'] ?? 1;
    $currency = $config['currency'] ?? 'USD';
    $min_stay = $config['min_stay'] ?? 1;
    $timezone = $config['timezone'] ?? 'UTC';
    
    // Create dynamic messaging based on property capacity and policies
    $message = "Perfect for groups up to {$max_guests} guests";
    if ($min_stay > 3) {
        $message .= " • Extended stay property";
    }
    if ($currency !== 'USD') {
        $message .= " • Local currency: {$currency}";
    }
    ?>
    <div class="dynamic-info" style="padding: 8px 12px; background-color: #e3f2fd; border-left: 4px solid #2196f3; margin-top: 8px;">
        <div style="font-size: 14px; color: #1976d2;">
            <strong>Property #<?php echo $property_id; ?></strong><br>
            <small><?php echo esc_html($message); ?></small>
        </div>
    </div>
    <?php
});

Best Practices #

When working with the homerunner_booking_widget_after_discount hook, consider these best practices:

  1. Always escape output using functions like esc_html(), esc_attr(), and esc_url()
  2. Check for array key existence using isset() or the null coalescing operator ??
  3. Keep styling inline or minimal to avoid conflicts with theme styles
  4. Test with different property configurations to ensure consistent behavior
  5. Consider mobile responsiveness in your custom HTML and CSS
  6. Use semantic HTML for better accessibility

Conclusion #

The homerunner_booking_widget_after_discount hook provides excellent flexibility for customizing booking widgets. Whether you need simple static content, user-specific messaging, or complex property-based customizations, this hook can accommodate your needs. By leveraging the rich configuration data provided, you can create highly targeted and relevant user experiences that enhance the booking process.