title: Why i can't get WP custom fields value or post ID via Ajax?
body: <p>I wrote a code that generate a link based on the visitor location and it worked perfectly but i discovered that the generated code get cached since i'm using a full page caching so i though to solve that issue i can use ajax to load that link. I used the below code which worked perfectly in getting some variables that i need such as location variable and link domain variable etc.. however i'm unable to get the WooCommerce custom field data or even the product id it just return blank.</p>
  
  <p>I'm using this code to get the custom field which worked perfectly when used directly in function however can't get it to work in ajax</p>
  
  <pre><code>$uk_asin = get_post_meta(get_post()-&gt;ID, "wccaf_uk_asin", true );
  </code></pre>
  
  <p>I used that code in functions.php</p>
  
  <pre><code>add_action( 'woocommerce_before_add_to_cart_button', 'affiliate_link_ajax', 11);
  function affiliate_link_ajax() {    
  ?&gt;
  &lt;script&gt;
  jQuery(document).ready(function(){
  
               jQuery.ajax({
                  url: "&lt;?php echo admin_url('admin-ajax.php'); ?&gt;",
                  type: 'POST',
                  data: {
                  action: 'getmyfunctionform1'
                  },
                  dataType: 'html',
                  success: function(response) {
  
                  jQuery("#myResultsform1").html(response);
  
                  }
  
          }); 
      });
  &lt;/script&gt; 
  &lt;!-- end Ajax call to getmyfunctionform1 smc 11-22-2013 --&gt;
  
  &lt;div id="myResultsform1"&gt;&lt;/div&gt;
  &lt;?php
  }
  </code></pre>
  
  <p>and this code in funnctions.php as well</p>
  
  <pre><code>// Ajax Function to Load PHP Function myfunctionform1 smc 11/22/2013
  
  add_action('wp_ajax_getmyfunctionform1', 'myfunctionform1');
  add_action('wp_ajax_nopriv_getmyfunctionform1', 'myfunctionform1');
  
  function myfunctionform1() { 
      $uk_asin = get_post_meta(get_post()-&gt;ID, "wccaf_uk_asin", true );
  echo $uk_asin;
  // Whatever php and or html you want outputed by the ajax call in template file
  
  die(); } // important must use
  
  // end Ajax Function to Load PHP Function myfunctionform1 smc 11/22/2013
  </code></pre>
  
  <p>I would really appreciate if the answer was simple since i'm still very new to coding</p>