Fix piwik tracking. Closes #2845.

This commit is contained in:
Mike Jolley 2013-04-08 20:33:42 +01:00
parent b183fb2fb7
commit 6ef24149ac
2 changed files with 34 additions and 25 deletions

View File

@ -183,6 +183,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
* Fix - Fix IE Download via SSL bug and fix http file over SSL.
* Fix - Show non-existing product line items.
* Fix - Conflicts with W3 Total Cache DB Cache
* Fix - piwik tracking.
* Tweak - Added a check to parent theme for comments_template before loading plugin template.
* Tweak - Remove hard coded max from random products widget.
* Tweak - Add filter hook to the place order button for easy 3rd party manipulation.
@ -194,7 +195,9 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
* Tweak - woocommerce_show_page_title filter
* Tweak - wrapper / css tweaks for TwentyThirteen compatibility
* Tweak - Added filters for controlling cross-sell display
* Tweak - Made hierarchy code in breadcrumbs more reliable.
* Localisation - NZ States
* Other minor fixes and localisation updates.
= 2.0.5 - 26/03/2013 =
* Tweak - Made no shipping available messages filterable via woocommerce_cart_no_shipping_available_html and woocommerce_no_shipping_available_html.

View File

@ -1208,47 +1208,53 @@ function woocommerce_readfile_chunked( $file, $retbytes = true ) {
function woocommerce_ecommerce_tracking_piwik( $order_id ) {
global $woocommerce;
if (is_admin()) return; // Don't track admin
// Don't track admin
if ( current_user_can('manage_options') )
return;
// Call the Piwik ecommerce function if WP-Piwik is configured to add tracking codes to the page
$wp_piwik_global_settings = get_option('wp-piwik_global-settings');
$wp_piwik_global_settings = get_option( 'wp-piwik_global-settings' );
// Return if Piwik settings are not here, or if global is not set
if ( ! isset( $wp_piwik_global_settings['add_tracking_code'] ) || ! $wp_piwik_global_settings['add_tracking_code'] ) return;
if ( ! isset( $GLOBALS['wp_piwik'] ) ) return;
if ( ! isset( $wp_piwik_global_settings['add_tracking_code'] ) || ! $wp_piwik_global_settings['add_tracking_code'] )
return;
if ( ! isset( $GLOBALS['wp_piwik'] ) )
return;
// Remove WP-Piwik from wp_footer and run it here instead, to get Piwik
// loaded *before* we do our ecommerce tracking calls
remove_action('wp_footer', array($GLOBALS['wp_piwik'],'footer'));
$GLOBALS['wp_piwik']->footer();
// Get the order and output tracking code
$order = new WC_Order($order_id);
// Get the order and get tracking code
$order = new WC_Order( $order_id );
ob_start();
?>
<script type="text/javascript">
try {
// Add order items
<?php if ($order->get_items()) foreach($order->get_items() as $item) : $_product = $order->get_product_from_item( $item ); ?>
<?php if ( $order->get_items() ) foreach( $order->get_items() as $item ) : $_product = $order->get_product_from_item( $item ); ?>
piwikTracker.addEcommerceItem(
"<?php echo esc_js( $_product->sku ); ?>", // (required) SKU: Product unique identifier
"<?php echo esc_js( $item['name'] ); ?>", // (optional) Product name
"<?php if (isset($_product->variation_data)) echo esc_js( woocommerce_get_formatted_variation( $_product->variation_data, true ) ); ?>", // (optional) Product category. You can also specify an array of up to 5 categories eg. ["Books", "New releases", "Biography"]
<?php echo esc_js( $order->get_item_total( $item ) ); ?>, // (recommended) Product price
<?php echo esc_js( $item['qty'] ); ?> // (optional, default to 1) Product quantity
"<?php echo esc_js( $_product->get_sku() ); ?>", // (required) SKU: Product unique identifier
"<?php echo esc_js( $item['name'] ); ?>", // (optional) Product name
"<?php
if ( isset( $_product->variation_data ) )
echo esc_js( woocommerce_get_formatted_variation( $_product->variation_data, true ) );
?>", // (optional) Product category. You can also specify an array of up to 5 categories eg. ["Books", "New releases", "Biography"]
<?php echo esc_js( $order->get_item_total( $item ) ); ?>, // (recommended) Product price
<?php echo esc_js( $item['qty'] ); ?> // (optional, default to 1) Product quantity
);
<?php endforeach; ?>
// Track order
piwikTracker.trackEcommerceOrder(
"<?php echo esc_js( $order_id ); ?>", // (required) Unique Order ID
<?php echo esc_js( $order->order_total ); ?>, // (required) Order Revenue grand total (includes tax, shipping, and subtracted discount)
false, // (optional) Order sub total (excludes shipping)
<?php echo esc_js( $order->get_total_tax() ); ?>, // (optional) Tax amount
<?php echo esc_js( $order->get_shipping() ); ?>, // (optional) Shipping amount
false // (optional) Discount offered (set to false for unspecified parameter)
"<?php echo esc_js( $order->get_order_number() ); ?>", // (required) Unique Order ID
<?php echo esc_js( $order->get_total() ); ?>, // (required) Order Revenue grand total (includes tax, shipping, and subtracted discount)
false, // (optional) Order sub total (excludes shipping)
<?php echo esc_js( $order->get_total_tax() ); ?>, // (optional) Tax amount
<?php echo esc_js( $order->get_shipping() ); ?>, // (optional) Shipping amount
false // (optional) Discount offered (set to false for unspecified parameter)
);
} catch( err ) {}
</script>
<?php
$code = ob_get_clean();
$woocommerce->add_inline_js( $code );
}