Search code examples
javascriptwordpresswoocommercewordpress-rest-api

woocommerce sku value passing onto javascript


I am new to wordpress coding, I will have to get sku value of product and pass it into custom javascript which will then pull the data from hp cdn network. In the below code ccs_cc_args.push(['pn', '7YL27EA']); - 7YL27EA is sku value of a product, I will have to pass this value as dynamic value in the argument code so that all the hp products will retrieve the specifications data from cdn network.

<div id="ccs-explore-product"></div>
<div id="ccs-inline-content"></div>

<script type='text/javascript'>
   var ccs_cc_args = ccs_cc_args || [];     
   // Product Page
   ccs_cc_args.push(['cpn', 'CPN']);
   ccs_cc_args.push(['mf', 'HP']);
   ccs_cc_args.push(['pn', '7YL27EA']);
   ccs_cc_args.push(['lang', 'EN']);
   ccs_cc_args.push(['market', 'ZA']);     
   (function () {
      var o = ccs_cc_args; o.push(['_SKey', 'ZZZZZZZ']); o.push(['_ZoneId', 'ZZZZZZZ']);
      var sc = document.createElement('script'); sc.type = 'text/javascript'; sc.async = true;
      sc.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'cdn.cnetcontent.com/jsc/h.js';
      var n = document.getElementsByTagName('script')[0]; n.parentNode.insertBefore(sc, n);
   })();
</script>

I tried passing the meta data value but since I am new, I think I am making mistakes. Please help me


Solution

  • I managed to find the solution, instead of adding add_action it was supposed to be add_shortcode since I was using the code under the shortcode box. Thanks