Skip to content

Instantly share code, notes, and snippets.

@1bigidea
Created November 30, 2012 00:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1bigidea/4172970 to your computer and use it in GitHub Desktop.
Save 1bigidea/4172970 to your computer and use it in GitHub Desktop.
Fix to Yoast's SEO for WordPress for WP-e-commerce 3.8+
function wpec_transaction_tracking( $push ) {
global $wpdb, $purchlogs, $cart_log_id, $purchase_log;
if ( !isset( $cart_log_id ) || empty( $cart_log_id ) )
return $push;
$city = $wpdb->get_var( "SELECT tf.value
FROM " . WPSC_TABLE_SUBMITED_FORM_DATA . " tf
LEFT JOIN " . WPSC_TABLE_CHECKOUT_FORMS . " cf
ON cf.id = tf.form_id
WHERE cf.unique_name = 'billingcity'
AND log_id = " . $cart_log_id );
$state = $wpdb->get_var( "SELECT tf.value
FROM " . WPSC_TABLE_SUBMITED_FORM_DATA . " tf
LEFT JOIN " . WPSC_TABLE_CHECKOUT_FORMS . " cf
ON cf.id = tf.form_id
WHERE cf.unique_name = 'billingstate'
AND log_id = " . $cart_log_id );
$country = $wpdb->get_var( "SELECT tf.value
FROM " . WPSC_TABLE_SUBMITED_FORM_DATA . " tf
LEFT JOIN " . WPSC_TABLE_CHECKOUT_FORMS . " cf
ON cf.id = tf.form_id
WHERE cf.unique_name = 'billingcountry'
AND log_id = " . $cart_log_id );
$cart_items = $wpdb->get_results( "SELECT * FROM " . WPSC_TABLE_CART_CONTENTS . " WHERE purchaseid = " . $cart_log_id, ARRAY_A );
$total_shipping = $purchlogs->allpurchaselogs[0]->base_shipping;
$total_tax = 0;
foreach ( $cart_items as $item ) {
$total_shipping += $item['pnp'];
$total_tax += $item['tax_charged'];
}
$currency_display_args = array(
'display_currency_symbol' => false,
'display_decimal_point' => true,
'display_currency_code' => false,
'display_as_html' => false,
'isocode' => false,
);
if( version_compare(WPSC_VERSION, '3.7.99') > 0 ){
// running 3.8+
$push[] = "'_addTrans','" . $cart_log_id . "'," // Order ID
. "'" . GA_Filter::ga_str_clean( get_bloginfo( 'name' ) ) . "'," // Store name
. "'" . wpsc_currency_display( $purchase_log['totalprice'], $currency_display_args ) . "'," // Total price
. "'" . wpsc_currency_display( $purchase_log['wpec_taxes_total'], $currency_display_args ) . "'," // Tax
. "'" . wpsc_currency_display( $purchase_log['base_shipping'], $currency_display_args) . "'," // Shipping
. "'" . $city . "'," // Billing City
. "'" . $state . "''," // Billing State
. "'" . $country . "'"; // Billing Country
} else {
// running 3.7 and earlier
$push[] = "'_addTrans','" . $cart_log_id . "'," // Order ID
. "'" . GA_Filter::ga_str_clean( get_bloginfo( 'name' ) ) . "'," // Store name
. "'" . nzshpcrt_currency_display( $purchlogs->allpurchaselogs[0]->totalprice, 1, false, false, true ) . "'," // Total price
. "'" . nzshpcrt_currency_display( $total_tax, 1, false, false, true ) . "'," // Tax
. "'" . nzshpcrt_currency_display( $total_shipping, 1, false, false, true ) . "'," // Shipping
. "'" . $city . "'," // City
. "''," // State
. "'" . $country . "'"; // Country
}
foreach ( $cart_items as $item ) {
if( version_compare(WPSC_VERSION, '3.7.99') > 0) {
// version 3.8+
$item['sku'] = wpsc_product_sku($item['prodid']);
$product_cats = wp_get_product_categories($item['prodid']);
$item['category'] = implode('/', wp_list_pluck($product_cats, 'name'));
} else {
// version 3.7 and earlier
$item['sku'] = $wpdb->get_var( "SELECT meta_value FROM " . WPSC_TABLE_PRODUCTMETA . " WHERE meta_key = 'sku' AND product_id = '" . $item['prodid'] . "' LIMIT 1" );
$item['category'] = $wpdb->get_var( "SELECT pc.name FROM " . WPSC_TABLE_PRODUCT_CATEGORIES . " pc LEFT JOIN " . WPSC_TABLE_ITEM_CATEGORY_ASSOC . " ca ON pc.id = ca.category_id WHERE pc.group_id = '1' AND ca.product_id = '" . $item['prodid'] . "'" );
}
$push[] = "'_addItem',"
. "'" . $cart_log_id . "'," // Order ID
. "'" . $item['sku'] . "'," // Item SKU
. "'" . str_replace( "'", "", $item['name'] ) . "'," // Item Name
. "'" . $item['category'] . "'," // Item Category
. "'" . $item['price'] . "'," // Item Price
. "'" . $item['quantity'] . "'"; // Item Quantity
}
$push[] = "'_trackTrans'";
return $push;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment