i'm trying to make custom ajax handler in wordpress because the admin-ajax.php is taking to long to handle ajax requests from 7s to 10s so i google it and mange to do some custom ajax-handler.php like this
<?php
if (is_ajax_request()) {
if (isset($_POST["action"]) && !empty($_POST["action"])) { //Checks if action value exists
$action = $_POST["action"];
switch($action) { //Switch case for value of action
case "test": test_function(); break;
}
}
}
//Function to check if the request is an AJAX request
function is_ajax_request() {
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
}
function test_function()
{
$response = wc_get_product(1463);
header('Content-Type: application/json');
echo json_encode($response);
die();
}
and i send first the response as text $response = "test"
and the ajax call was taking 300ms but when trying to call function from another file like $response = wc_get_product(1463);
it throws an error in the response Fatal error: Call to undefined function wc_get_product() in C:\wamp\www\....
and i tried to make custom wordpress ajax handel using this ajaxflow plugin but it the seams thing so please please how can i call the functions from another files and many thanks in advance for any help.