Conflict between 2 function using ajax in wordpress

I have written this code here

  add_action('wp_head','pageType');
function pageType(){
  
    if (is_product()) {
            global $post;
            $product = wc_get_product( $post->ID );
            $tipo    = $product->get_type();
            echo $product->get_name();
            echo $product->get_price();
            echo $product->get_regular_price();
            return $product->get_name();
        }else{    
          return "NOTHING";
        }
    }

add_action( 'wp_ajax_my_action', 'my_action_callback' );
function my_action_callback() {
  check_ajax_referer( 'my-special-string', 'security' );
  $whatever = intval( $_POST['whatever'] );


 $dataOfProduct = pageType();

  $whatever += 10000;
  echo $whatever . '=>>' . $dataOfProduct .' . ' . '<==== d';
  die(); 
}

The code is working fine

Example when pageType is being added to wp_head with add_action(wp_head,'pageType') the is_product is working fine so it is printing

        echo $product->get_name();
        echo $product->get_price();

But in the second method i have an ajax function because i am trying to send data to a tracking script

add_action( 'wp_ajax_my_action', 'my_action_callback' );
function my_action_callback() {

Inside this method when i am calling

 $dataOfProduct = pageType();

It is returning “NOTHING”

What can be the problem why its working is_product() function not working on my_action_callback()

What can be the problem

Here $dataOfProduct = pageType(); i want pageType to return the name of the product

THank you