VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: tsimpouri on November 19, 2015, 13:29:15 PM

Title: echo comma separated list of all the product skus that is on cart
Post by: tsimpouri on November 19, 2015, 13:29:15 PM
Hello,

i want to add this code on cart page for facebook pixel track.I want to have all the skus that is on the cart in one line

fbq('track', 'Purchase', {
  content_ids: ['sku1', 'sku2' ], 
});

when i am adding the following   content_ids: ['<?php echo $prow->product_sku ?>' ],   i can have only the one sku that is on the cart but i want all the sku's in one line...

is there something i can do?

Thanks
Title: Re: echo comma separated list of all the product skus that is on cart
Post by: Studio 42 on November 19, 2015, 14:52:21 PM
YOu need to do a foreach in PHP
something so :

<?php $skus = array();
foreach (
$this->cart->products as $pkey => $prow) {
 
$skus[] =  $prow->product_sku;
}
?>

// javascript part
fbq('track', 'Purchase', {
  content_ids: ['<?php echo implode("','",$skus?>' ],
});
Title: Re: echo comma separated list of all the product skus that is on cart
Post by: tsimpouri on November 19, 2015, 15:35:33 PM
thank you very much
Title: Re: echo comma separated list of all the product skus that is on cart
Post by: mhuebler on November 15, 2016, 13:52:17 PM
very good ! thx