Files
homeproz/wp-content/themes/homeproz/page-mortgage-calculator.php
T
Hanson.xyz Dev cf0debb970 Add currency and percentage input plugins to mortgage calculator
- Currency inputs auto-format with thousand separators on input
- Only allows numeric characters (strips letters, symbols, etc.)
- .val() returns raw integer for calculations
- Percentage inputs allow only numbers and one decimal point
- Select all on focus for easy replacement
- Maintains cursor position while typing
- Real-time sync between down payment dollar and percent fields

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-01 00:37:22 -06:00

179 lines
9.7 KiB
PHP

<?php
/**
* Template Name: Mortgage Calculator
* Template for the Mortgage Calculator resource page
*
* @package HomeProz
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
get_header();
// Get hero content from ACF or defaults
$hero_title = get_field('hero_title') ?: 'Mortgage Calculator';
$hero_subtitle = get_field('hero_subtitle') ?: 'Estimate your monthly payment and see what you can afford';
$hero_bg = get_field('hero_background');
$has_bg_class = $hero_bg ? 'has-background' : '';
$bg_style = $hero_bg ? 'style="background-image: url(' . esc_url($hero_bg) . ');"' : '';
?>
<main id="primary" class="site-main mortgage-calculator-main">
<!-- Archive Hero -->
<section class="archive-hero <?php echo esc_attr($has_bg_class); ?>" <?php echo $bg_style; ?>>
<?php if ($hero_bg) : ?>
<div class="archive-hero-overlay"></div>
<?php endif; ?>
<div class="container">
<h1 class="archive-hero-title"><?php echo esc_html($hero_title); ?></h1>
<?php if ($hero_subtitle) : ?>
<p class="archive-hero-subtitle"><?php echo esc_html($hero_subtitle); ?></p>
<?php endif; ?>
</div>
</section>
<div class="container">
<div class="mortgage-calculator-layout">
<!-- Main Content -->
<div class="mortgage-calculator-content">
<!-- Calculator Widget -->
<div class="calculator-widget">
<form class="calculator-form" id="mortgage-calculator-form">
<div class="calculator-inputs">
<div class="input-group">
<label for="home-price">Home Price</label>
<div class="input-wrapper input-currency">
<span class="input-prefix">$</span>
<input type="text" id="home-price" name="home-price" value="250000" inputmode="numeric">
</div>
</div>
<div class="input-group">
<label for="down-payment">Down Payment</label>
<div class="input-row">
<div class="input-wrapper input-currency">
<span class="input-prefix">$</span>
<input type="text" id="down-payment" name="down-payment" value="50000" inputmode="numeric">
</div>
<div class="input-wrapper input-percent">
<input type="text" id="down-payment-percent" name="down-payment-percent" value="20" inputmode="decimal">
<span class="input-suffix">%</span>
</div>
</div>
</div>
<div class="input-group">
<label for="loan-term">Loan Term</label>
<div class="input-wrapper">
<select id="loan-term" name="loan-term">
<option value="30">30 years</option>
<option value="20">20 years</option>
<option value="15">15 years</option>
<option value="10">10 years</option>
</select>
</div>
</div>
<div class="input-group">
<label for="interest-rate">Interest Rate</label>
<div class="input-wrapper input-percent">
<input type="text" id="interest-rate" name="interest-rate" value="6.5" inputmode="decimal">
<span class="input-suffix">%</span>
</div>
</div>
</div>
<div class="calculator-results">
<div class="result-main">
<span class="result-label">Estimated Monthly Payment</span>
<span class="result-value" id="monthly-payment">$1,264</span>
</div>
<div class="result-breakdown">
<div class="breakdown-item">
<span class="breakdown-label">Principal & Interest</span>
<span class="breakdown-value" id="principal-interest">$1,264</span>
</div>
<div class="breakdown-item">
<span class="breakdown-label">Loan Amount</span>
<span class="breakdown-value" id="loan-amount">$200,000</span>
</div>
<div class="breakdown-item">
<span class="breakdown-label">Total Interest Paid</span>
<span class="breakdown-value" id="total-interest">$255,089</span>
</div>
</div>
</div>
</form>
</div>
<!-- How to Use Section -->
<section class="calculator-guide">
<h2 class="section-title">How to Use This Calculator</h2>
<div class="guide-content">
<p>This calculator gives you a quick estimate of what your monthly mortgage payment might look like. Here's what each field means:</p>
<ul class="guide-list">
<li><strong>Home Price</strong> - The purchase price of the home you're considering.</li>
<li><strong>Down Payment</strong> - The amount you'll pay upfront. A larger down payment means a smaller loan and lower monthly payments. Most conventional loans require at least 3-5% down, though 20% helps you avoid private mortgage insurance (PMI).</li>
<li><strong>Loan Term</strong> - How long you'll take to repay the loan. A 30-year term has lower monthly payments but more total interest. A 15-year term has higher payments but saves significantly on interest.</li>
<li><strong>Interest Rate</strong> - The annual rate charged by your lender. Rates vary based on your credit score, down payment, and market conditions. Check with local lenders for current rates.</li>
</ul>
</div>
</section>
<!-- Important Notes -->
<section class="calculator-notes">
<h2 class="section-title">Keep in Mind</h2>
<div class="notes-content">
<p>This calculator shows principal and interest only. Your actual monthly payment will likely include:</p>
<ul class="notes-list">
<li>Property taxes (varies by location)</li>
<li>Homeowner's insurance</li>
<li>Private mortgage insurance (PMI) if your down payment is less than 20%</li>
<li>HOA fees if applicable</li>
</ul>
<p>For a complete picture of what you can afford, we recommend talking with a mortgage lender who can provide a detailed estimate based on your specific situation.</p>
</div>
</section>
</div>
<!-- Sidebar -->
<aside class="mortgage-calculator-sidebar">
<!-- Quick Tips Widget -->
<div class="sidebar-widget tips-widget">
<h3 class="widget-title">Quick Tips</h3>
<ul class="tips-list">
<li>Aim for a monthly payment that's no more than 28% of your gross monthly income.</li>
<li>A higher credit score typically means a lower interest rate.</li>
<li>Get pre-approved before house hunting to know your budget.</li>
<li>Compare rates from multiple lenders to find the best deal.</li>
</ul>
</div>
<!-- Need Help Widget -->
<div class="sidebar-widget help-widget">
<h3 class="widget-title">Need Help?</h3>
<p class="help-text">Figuring out financing can feel overwhelming. We're happy to connect you with trusted local lenders or answer any questions about the home buying process.</p>
<a href="<?php echo esc_url(home_url('/contact/')); ?>" class="btn btn-primary btn-block">Get in Touch</a>
</div>
<!-- Resources Widget -->
<div class="sidebar-widget resources-widget">
<h3 class="widget-title">More Resources</h3>
<ul class="resource-links">
<li><a href="<?php echo esc_url(home_url('/resources/buyers-guide/')); ?>">Buyer's Guide</a></li>
<li><a href="<?php echo esc_url(home_url('/resources/moving-checklist/')); ?>">Moving Checklist</a></li>
<li><a href="<?php echo esc_url(home_url('/resources/faq/')); ?>">FAQ</a></li>
</ul>
</div>
</aside>
</div>
</div>
</main>
<?php
get_footer();