Tareq Hasan on "[Plugin: WooCommerce Conversion Tracking] Thank you page is not default"

ساخت وبلاگ

Because of the marketing campaign company i use, a javascript tracking code needed to be placed on the order confirmation page. This is the thank you page of woocommerce.

The fields in the javascript code needed to be generated programatically, this means just pasting the code into the thank you page would not work. So I had a programmer write a php program that fills in the needed data automatically for each product.

They also extended the woocommerce thank you page template by adding a new one to

/wp-content/themes/kleo/checkout/thankyou.php

here is the full code of the thank you page

<?php

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

if ( $order ) : ?>

//my own code starts here

<?php

$dp = ( isset( $filter['dp'] ) ? intval( $filter['dp'] ) : 2 );

//$order_id = trim(str_replace('#', '', $order->get_order_number()));

$order_id = $order->get_order_number();

$subtotal=wc_format_decimal( $order->get_subtotal(), $dp );

$tax=wc_format_decimal( $order->get_total_tax(), $dp );

$shipping=wc_format_decimal( $order->get_total_shipping(), $dp );
$total=wc_format_decimal( $order->get_total(), $dp );
$discount=wc_format_decimal( $order->get_total_discount(), $dp );

?>

<script type="text/javascript">
var sidecar = sidecar || {};
sidecar.transactions = {
add: true,
data: {
order_id: '<?php echo $order_id; ?>',
subtotal: '<?php echo $subtotal; ?>',
tax: '<?php echo $tax; ?>',
shipping: '<?php echo $shipping; ?>',

total: '<?php echo $total; ?>'
},

items: [

<?php

$items = $order->get_items();

foreach ( $items as $item ) {
$product_id = $item['product_id'];

$price = $item['line_total'];
$quantity = $item['qty'];

echo "
{
product_id: '".$product_id."',
unit_price: '".$price ."',
quantity:' ".$quantity ."'
}";

$numItems = count($items);
$i = 0;

if(++$i === $numItems) {
echo " ";
}

else

{
echo ',';

}

}

?>

]

};
</script>

//sidecar integration code ends here read the code above

<?php if ( $order->has_status( 'failed' ) ) : ?>

<p class="woocommerce-thankyou-order-failed"><?php _e( 'Unfortunately your order cannot be processed as the originating bank/merchant has declined your transaction. Please attempt your purchase again.', 'woocommerce' ); ?></p>

<p class="woocommerce-thankyou-order-failed-actions">
get_checkout_payment_url() ); ?>" class="button pay"><?php _e( 'Pay', 'woocommerce' ) ?>
<?php if ( is_user_logged_in() ) : ?>
" class="button pay"><?php _e( 'My Account', 'woocommerce' ); ?>
<?php endif; ?>
</p>

<?php else : ?>

<p class="woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), $order ); ?></p>

<ul class="woocommerce-thankyou-order-details order_details">
<li class="order">
<?php _e( 'Order Number:', 'woocommerce' ); ?>
<?php echo $order->get_order_number(); ?>

<li class="date">
<?php _e( 'Date:', 'woocommerce' ); ?>
<?php echo date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) ); ?>

<li class="total">
<?php _e( 'Total:', 'woocommerce' ); ?>
<?php echo $order->get_formatted_order_total(); ?>

<?php if ( $order->payment_method_title ) : ?>
<li class="method">
<?php _e( 'Payment Method:', 'woocommerce' ); ?>
<?php echo $order->payment_method_title; ?>

<?php endif; ?>

<div class="clear"></div>

<?php endif; ?>

<?php do_action( 'woocommerce_thankyou_' . $order->payment_method, $order->id ); ?>
<?php do_action( 'woocommerce_thankyou', $order->id ); ?>

<?php else : ?>

<p class="woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), null ); ?></p>

<?php endif; ?>

However now my tracking for google conversion pixel is not working any more. The conversion value defaults to the value of $5 and does not give the actual order total value.

Here is the google tracking pixel.

<!-- Google Code for purchase .us Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 954290262;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "xDIJCPCq6VkQ1qCFxwM";
var google_conversion_value = 5.00;
var google_conversion_currency = "USD";
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="//www.googleadservices.com/pagead/conversion/954290262/?value=5.00¤cy_code=USD&label=xDIJCPCq6VkQ1qCFxwM&guid=ON&script=0"/>
</div>
</noscript>

WordPress ...
ما را در سایت WordPress دنبال می کنید

برچسب : نویسنده : استخدام کار wpss بازدید : 191 تاريخ : دوشنبه 24 خرداد 1395 ساعت: 13:56