Using SKU instead of Product ID in remarketing plugin.
-
I realised that I use the SKU in adwords instead the Product ID so had to edit your plugin to make it work for me.
I have written a small bit of code to get the Cart page and Product page working. Im not sure if you wanted to share this with users of the plugin.
This is for the cart:
<?php } elseif (is_page( wc_get_page_id( 'cart' ) ) || defined( 'WOOCOMMERCE_CART' )){ ?> <script type="text/javascript"> var google_tag_params = { ecomm_prodid: [<?php $cartprods = $woocommerce->cart->get_cart(); $sku = array(); foreach($cartprods as $entry){ global $product; $product_id = $entry['product_id']; $prod = new WC_Product($product_id); $sku[] = $prod->get_sku(); } echo "'" . implode("','", $sku) . "'"; ?>], ecomm_pagetype: 'cart', ecomm_totalvalue: <?php echo $woocommerce->cart->cart_contents_total; ?> }; </script>
This is for the product:
<?php } elseif (is_product()){ ?> <script type="text/javascript"> var google_tag_params = { ecomm_prodid: '<?php $product = get_product( get_the_ID() ); echo $product->get_sku(); ?>', ecomm_category: <?php echo "["; $prod_cats = get_the_terms( get_the_ID(), 'product_cat' ); $prod_cats_output = array(); foreach ($prod_cats as $k1 ){ array_push($prod_cats_output, "'" . $k1->name . "'"); } echo implode(', ', $prod_cats_output); echo "],\n"; ?> ecomm_pagetype: 'product', ecomm_totalvalue: <?php $product = get_product( get_the_ID() ); echo $product->get_price(); ?> }; </script>
https://www.ads-software.com/plugins/woocommerce-google-dynamic-retargeting-tag/
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Using SKU instead of Product ID in remarketing plugin.’ is closed to new replies.