ecommerce track Closes #1361.

This commit is contained in:
Mike Jolley 2012-08-10 16:56:13 +01:00
parent d351240e6a
commit 10a39244bd
4 changed files with 84 additions and 84 deletions

View File

@ -260,21 +260,21 @@ class WC_Order {
/** Gets shipping and product tax */
function get_total_tax() {
return apply_filters( 'woocommerce_order_amount_total_tax', $this->order_tax + $this->order_shipping_tax );
return apply_filters( 'woocommerce_order_amount_total_tax', number_format( $this->order_tax + $this->order_shipping_tax, 2, '.', '' ) );
}
/**
* gets the total (product) discount amount - these are applied before tax
*/
function get_cart_discount() {
return apply_filters( 'woocommerce_order_amount_cart_discount', $this->cart_discount );
return apply_filters( 'woocommerce_order_amount_cart_discount', number_format( $this->cart_discount, 2, '.', '' ) );
}
/**
* gets the total (product) discount amount - these are applied before tax
*/
function get_order_discount() {
return apply_filters( 'woocommerce_order_amount_order_discount', $this->order_discount );
return apply_filters( 'woocommerce_order_amount_order_discount', number_format( $this->order_discount, 2, '.', '' ) );
}
/**
@ -282,18 +282,18 @@ class WC_Order {
*/
function get_total_discount() {
if ($this->order_discount || $this->cart_discount) :
return apply_filters( 'woocommerce_order_amount_total_discount', $this->order_discount + $this->cart_discount );
return apply_filters( 'woocommerce_order_amount_total_discount', number_format( $this->order_discount + $this->cart_discount, 2, '.', '' ) );
endif;
}
/** Gets shipping */
function get_shipping() {
return apply_filters( 'woocommerce_order_amount_shipping', $this->order_shipping );
return apply_filters( 'woocommerce_order_amount_shipping', number_format( $this->order_shipping, 2, '.', '' ) );
}
/** Gets shipping tax amount */
function get_shipping_tax() {
return apply_filters( 'woocommerce_order_amount_shipping_tax', $this->order_shipping_tax );
return apply_filters( 'woocommerce_order_amount_shipping_tax', number_format( $this->order_shipping_tax, 2, '.', '' ) );
}
/** Gets shipping method title */
@ -303,7 +303,7 @@ class WC_Order {
/** Gets order total */
function get_total() {
return apply_filters( 'woocommerce_order_amount_total', $this->order_total );
return apply_filters( 'woocommerce_order_amount_total', number_format( $this->order_total, 2, '.', '' ) );
}
/** Get item subtotal - this is the cost before discount */
@ -359,7 +359,7 @@ class WC_Order {
/** Deprecated functions */
function get_order_total() {
return apply_filters( 'woocommerce_order_amount_total', $this->order_total );
return $this->get_total();
}
function get_item_cost( $item, $inc_tax = false ) {

View File

@ -1239,8 +1239,6 @@ class WC_Product {
function variable_product_sync() {
global $woocommerce;
if (!$this->is_type('variable')) return;
$children = get_posts( array(
'post_parent' => $this->id,
'posts_per_page'=> -1,
@ -1280,8 +1278,7 @@ class WC_Product {
$this->price = $this->min_variation_price;
if ( $this->min_variation_price !== '' )
$woocommerce->clear_product_transients( $this->id );
$woocommerce->clear_product_transients( $this->id );
}
}

View File

@ -97,7 +97,7 @@ class WC_Google_Analytics extends WC_Integration {
$username = __('Guest', 'woocommerce');
}
$woocommerce->add_inline_js("
echo "<script type='text/javascript'>
var _gaq = _gaq || [];
_gaq.push(
@ -114,7 +114,7 @@ class WC_Google_Analytics extends WC_Integration {
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
");
</script>";
}
/**
@ -123,20 +123,22 @@ class WC_Google_Analytics extends WC_Integration {
function ecommerce_tracking_code( $order_id ) {
global $woocommerce;
if ( is_admin() || current_user_can('manage_options') || $this->ga_ecommerce_tracking_enabled == "no" ) return;
if ( $this->ga_ecommerce_tracking_enabled == "no" || current_user_can('manage_options') )
return;
$tracking_id = $this->ga_id;
if ( ! $tracking_id ) return;
// Doing eCommerce tracking so unhook standard tracking from the footer
remove_action('wp_footer', array( &$this, 'google_tracking_code' ) );
remove_action( 'wp_footer', array( &$this, 'google_tracking_code' ) );
// Get the order and output tracking code
$order = new WC_Order($order_id);
$order = new WC_Order( $order_id );
$loggedin = (is_user_logged_in()) ? 'yes' : 'no';
if (is_user_logged_in()) {
$loggedin = is_user_logged_in() ? 'yes' : 'no';
if ( is_user_logged_in() ) {
$user_id = get_current_user_id();
$current_user = get_user_by('id', $user_id);
$username = $current_user->user_login;
@ -159,7 +161,7 @@ class WC_Google_Analytics extends WC_Integration {
_gaq.push(['_addTrans',
'" . $order_id . "', // order ID - required
'" . get_bloginfo( 'name' ) . "', // affiliation or store name
'" . $order->order_total . "', // total - required
'" . $order->get_total() . "', // total - required
'" . $order->get_total_tax() . "', // tax
'" . $order->get_shipping() . "', // shipping
'" . $order->billing_city . "', // city
@ -175,7 +177,7 @@ class WC_Google_Analytics extends WC_Integration {
$code .= "_gaq.push(['_addItem',";
$code .= "'" . $order_id . "',";
$code .= "'" . ( ( ! empty( $_product->sku ) ) ? __('SKU:', 'woocommerce') . ' ' . $_product->sku : $_product->id ) . "',";
$code .= "'" . ( $_product->get_sku() ? __('SKU:', 'woocommerce') . ' ' . $_product->get_sku() : $_product->id ) . "',";
$code .= "'" . $item['name'] . "',";
if ( isset( $_product->variation_data ) ) {
@ -193,7 +195,7 @@ class WC_Google_Analytics extends WC_Integration {
$code .= "'" . join( "/", $out) . "',";
}
$code .= "'" . ( $item['line_total'] / $item['qty'] ) . "',";
$code .= "'" . $order->get_item_total( $item ) . "',";
$code .= "'" . $item['qty'] . "'";
$code .= "]);";
}
@ -209,7 +211,7 @@ class WC_Google_Analytics extends WC_Integration {
})();
";
$woocommerce->add_inline_js( $code );
echo '<script type="text/javascript">' . $code . '</script>';
}
/**

View File

@ -160,7 +160,8 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
* Tweak - Order page styling
* Fix - has_file() handling for variations
* Fix - Hide if cart is empty option
* FIx - Hide individual variations from frontend
* Fix - Hide individual variations from frontend
* Fix - Google Analytics ecommerce tracking
= 1.6.2 - 09/08/2012 =
* Feature - Added google analytics event tracking for add to cart buttons (thanks to Max Rice)