Site icon Hip-Hop Website Design and Development

Creating a brand attribute as a variable

I have a script below where I dynamically need to replace two values and I can’t get it to work.

The values can be found as Wooccomerce product attribute values on the product page.

For instance, see the below.

Brand| "Ashley"

MPN| "234gty"

I intend to pull the values of each attribute, "Ashley" and "234gty" and use them as variables to fill in the script below.


       var ccs_cc_args = ccs_cc_args || [];
       
       // Main Product Page
       ccs_cc_args.push(['cpn', '']);
       ccs_cc_args.push(['mf', '$brand']);
       ccs_cc_args.push(['pn', '$mpn']);
       ccs_cc_args.push(['upcean', 'UPC_EAN_CODE']);
       ccs_cc_args.push(['ccid', 'CATALOG_CODE']);
       ccs_cc_args.push(['lang', 'LANGUAGE']);
       ccs_cc_args.push(['market', 'MARKET']);
       
       (function () {
          var o = ccs_cc_args; o.push(['_SKey', '3f1b897a']); o.push(['_ZoneId', '6ce9a32538']);
          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);
       })();
       

I’ve tried adding the following to the footer.php and functions.php and echo to the product page with no luck.

global $product;

$mpn = array_shift( wc_get_product_terms( $product->id, 'pa_mpn', array( 'fields' => 'names' ) ) );

$brand = array_shift( wc_get_product_terms( $product->id, 'pa_brand', array( 'fields' => 'names' ) ) );