$.post still returning undefined [duplicate]

I have a function that gets the price of a product from server-side using the $.post() method and with a callback returns its value. However it returns undefined but the values actually get logged to console using the console.log()

Function to get price with callback

//callback function

function returnData(parameter) {
   //console.log(parameter); values get logged correctly, e.g 50,100,etc
   return parameter; 

// fetch price 

function getPrice(product_id,callback) {
  $.post("processor.php", {product_id:product_id}, function(price) {

Function to calculate total price

function getTotalPrice () {
  var products = getAllProducts(), total = 0; // does it's job
  $.each(products, function(index, value) {
     let price  = getPrice(value.id,returnData); //call my get price function
     //console.log(price); returns undefined
     total +=value.quantity * price;
    return total;

I have tried a couple of responses on the platform but same undefined. Have also tried returning from the .done() from the post response but still no luck.

%d bloggers like this: