Simdi wordpress'de get-template-part diye bir fonksiyon var. ben Ajax kullanarak kullanici buttona basinca get-template-part fonkiyonunu cagirip sayfayi yenilemeden enjecte etmek.
Ilgili site asagidaki linkte. amacim kullanici Continue booking details button a basinca javascript ile farkli sayfalari render ediyorum. Onun yerine: domain.com/checkout/quote_id/transport-details tarzinda url path eklemek istiyorum. ( Hallettim url path kismini )
Benim site: https://pyroautotransport.com/checko...c-2b6085bbea85
Ornek gibi yapmak istedigim site: https://www.montway.com/checkout/cal...pickup-details
bunu nasil yaparim ?
<?php
$pathParts = explode('/', trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/'));
$quoteId = $pathParts[1] ?? ''; // Assuming the quote ID is the second part of the path
$step = $pathParts[2] ?? ''; // Check if there's a third segment (the step)
// Check if it's an AJAX request
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') {
ob_start(); // Start output buffering
switch ($step) {
case 'transport-details':
get_template_part('./template-parts/checkout-transport-details');
break;
case 'pickup-details':
get_template_part('template-parts/checkout-pickup-details');
break;
case 'delivery-details':
get_template_part('template-parts/checkout-delivery-details');
break;
case 'payment':
get_template_part('template-parts/checkout-payment');
break;
default:
get_template_part('template-parts/checkout-pricing');
break;
}
$output = ob_get_clean(); // Get the contents of the buffer and clean it
echo $output; // Echo the output to send it back as the AJAX response
exit; // Stop further execution, we only want to return the template
}
// If it's not an AJAX request, render the full page with all necessary elements
?>
<div id="checkoutContent">
<?php
switch ($step) {
case 'transport-details':
get_template_part('template-parts/checkout-transport-details');
break;
case 'pickup-details':
get_template_part('template-parts/checkout-pickup-details');
break;
case 'delivery-details':
get_template_part('template-parts/checkout-delivery-details');
break;
case 'payment':
get_template_part('template-parts/checkout-payment');
break;
default:
get_template_part('template-parts/checkout-pricing');
break;
}
?>function loadStepContent(url) {
fetch(url, {
method: 'GET',
headers: {
'X-Requested-With': 'XMLHttpRequest' // Let the server know this is an AJAX request
}
})
.then(response => response.text())
.then(html => {
// Inject the new content into the checkout content container
document.getElementById('checkoutContent').innerHTML = html;
// Hide the loading overlay
hideLoadingOverlay();
})
.catch(error => {
console.error('Error loading content:', error);
hideLoadingOverlay(); // Ensure the overlay is hidden even if there's an error
});
}