• Resolved duncanh

    (@duncanh)


    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)
  • Plugin Author alekv

    (@alekv)

    Hi duncanh

    Thank you for your valuable input!

    At first my plugin was designed to work with the product feed plugins which were around at that time. All of them used the post ID as product ID. I’m getting more requests to include the SKU as product ID recently, so I will move that up in the development roadmap.

    Could you send me the link to your product feed and also the link to the plugin you use to generate the product feed?

    You can send me this information to [email protected].

    It will help me to integrate an option to use the SKU as the product identifier.

    Also I can’t see the reason why you changed the logic for identifying the cart page. I use
    elseif (is_cart()){
    You use
    elseif (is_page( wc_get_page_id( 'cart' ) ) || defined( 'WOOCOMMERCE_CART' )){
    Did my logical expression not work for you?

    Thanks
    Aleks

Viewing 1 replies (of 1 total)
  • The topic ‘Using SKU instead of Product ID in remarketing plugin.’ is closed to new replies.