<?php
//if (is_woocommerce() || is_cart() || is_checkout() || $_SERVER['REQUEST_URI'] == '/' ) :
$cate = get_queried_object();
$cateID = $cate->term_id;
$argsH = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => '-1',
'meta_query' => array(
array(
'key' => '_visibility',
'value' => array('catalog', 'visible'),
'compare' => 'IN'
)
)
);
$argsC = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => '-1',
'meta_query' => array(
array(
'key' => '_visibility',
'value' => array('catalog', 'visible'),
'compare' => 'IN'
)
),
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id', //This is optional, as it defaults to 'term_id'
'terms' => $cateID,
'operator' => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'.
)
)
);
$argsT = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => '-1',
'meta_query' => array(
array(
'key' => '_visibility',
'value' => array('catalog', 'visible'),
'compare' => 'IN'
)
),
'tax_query' => array(
array(
'taxonomy' => 'product_tag',
'field' => 'term_id', //This is optional, as it defaults to 'term_id'
'terms' => $cateID,
'operator' => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'.
)
)
);
if (is_product_category() ) {
$qloop = new WP_Query($argsC);
while ( $qloop->have_posts() ) : $qloop->the_post(); global $product;
$prod_idz[] = $qloop->post->ID;
$rezultz = implode( $prod_idz, ', ');
endwhile;
wp_reset_query();
//echo $rezultz;
$prod_id = 'ecomm_prodid:['.$rezultz.'],';
$pagetype = 'category';
//analytics retails code
$prod_id_anl = $rezultz;
} else
if ( is_product_tag() ) {
$qloop = new WP_Query($argsT);
while ( $qloop->have_posts() ) : $qloop->the_post(); global $product;
$prod_idz[] = $qloop->post->ID;
$rezultz = implode( $prod_idz, ', ');
endwhile;
wp_reset_query();
//echo $rezultz;
$prod_id = 'ecomm_prodid:['.$rezultz.'],';
$pagetype = 'category';
//analytics retails code
$prod_id_anl = $rezultz;
} else
if (is_product()) {
global $product;
// $custom_price_string = get_post_meta( $product->id, '_custom_composite_price_html', true );
// $custom_price_string = str_replace('$','',$custom_price_string);
$_productz = wc_get_product( $product->id );
$prod_id = 'ecomm_prodid:'.get_the_ID().',';
// if ($custom_price_string !=='') {
// $prod_price = 'ecomm_totalvalue: '.$custom_price_string;
// } else {
$prod_price = 'ecomm_totalvalue:'.$_productz->get_price();
// }
$pagetype = 'product';
//analytics retails code
$prod_id_anl = get_the_ID();
$prod_price_anl = $_productz->get_price();
} else
if (is_shop() || $_SERVER['REQUEST_URI'] == '/') {
$qloop = new WP_Query($argsH);
while ( $qloop->have_posts() ) : $qloop->the_post(); global $product;
$prod_idz[] = $qloop->post->ID;
$rezultz = implode( $prod_idz, ', ');
endwhile;
wp_reset_query();
$prod_id = 'ecomm_prodid:['.$rezultz.'],';
$pagetype = 'home';
//analytics retails code
$prod_id_anl = $rezultz;
} else
if (is_wc_endpoint_url( 'order-received' )) {
global $totalValue;
$order_id = $wp->query_vars['order-received'];
$order = new WC_Order($order_id );
$items = $order->get_items();
foreach ( $items as $item ) {
$product_id = $item['product_id'];
$products[] = $product_id;
$rezultz = implode( $products, ', ');
}
$prod_id = 'ecomm_prodid:['.$rezultz.'],';
$pagetype = 'purchase';
//$prod_price = $totalValue;
$prod_price = 'ecomm_totalvalue:'.$totalValue;
//analytics retails code
$prod_id_anl = $rezultz;
$prod_price_anl = $totalValue;
} else
if (is_cart() || is_checkout() ) {
global $woocommerce;
$items = $woocommerce->cart->get_cart();
foreach($items as $item => $values) {
$_product = $values['data']->post;
$ordlist[] = $_product->ID;
$rezultz = implode( $ordlist, ', ');
}
global $subTotal;
$prod_id = 'ecomm_prodid:['.$rezultz.'],';
$pagetype = 'cart';
$prod_price = 'ecomm_totalvalue:'.$subTotal;
//analytics retails code
$prod_id_anl = $rezultz;
$prod_price_anl = $subTotal;
} else{
$qloop = new WP_Query($argsH);
while ( $qloop->have_posts() ) : $qloop->the_post(); global $product;
$prod_idz[] = $qloop->post->ID;
$rezultz = implode( $prod_idz, ', ');
endwhile;
wp_reset_query();
$prod_id = 'ecomm_prodid:['.$rezultz.'],';
$pagetype = 'other';
//analytics retails code
$prod_id_anl = $rezultz;
}
?>
<script type="text/javascript">
var google_tag_params = {
<?php
echo $prod_id.PHP_EOL;
echo 'ecomm_pagetype:\''.$pagetype.'\','.PHP_EOL;
echo $prod_price.PHP_EOL;
?>
};
</script>
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = INSERT_TRACKING_ID;
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
var google_conversion_format = 3;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;"> <img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/INSERT_TRACKING_ID/?guid=ON&script=0"/> </div>
</noscript>
<?php //endif; ?>
<?php
if (is_wc_endpoint_url( 'order-received' ) ) :
global $totalValue;
?>
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = INSERT_TRACKING_ID;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "INSERT_TRACKING_ID";
var google_conversion_currency = "USD";
var google_conversion_value = <?php echo $totalValue; ?>;
var google_remarketing_only = false;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;"> <img height="1" width="1" style="border-style:none;" alt="" src="https://www.googleadservices.com/pagead/conversion/INSERT_TRACKING_ID/?value=<?php echo $totalValue ?>&currency_code=USD&label=INSERT_TRACKING_ID&guid=ON&script=0"/> </div>
</noscript>
<?php endif; ?>