Changeset 2007643
- Timestamp:
- 01/07/2019 10:51:45 AM (7 years ago)
- Location:
- tealium/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (3 diffs)
-
tealium.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tealium/trunk/readme.txt
r1961829 r2007643 5 5 Requires at least: 3.0.1 6 6 Tested up to: 5.0 7 Stable tag: 2.1.1 27 Stable tag: 2.1.13 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 106 106 == Changelog == 107 107 108 = 2.1.13 = 109 * WooCommerce product data updates. 110 108 111 = 2.1.12 = 109 112 * Add post ID to data layer. … … 191 194 == Upgrade Notice == 192 195 196 = 2.1.13 = 197 WooCommerce product data updates. 198 Be aware that some data WooCommerce source/variable names have changed. Product data is now prefixed with product_, cart with cart_ and order with order_. 199 193 200 = 2.1.12 = 194 201 Add post ID to data layer. -
tealium/trunk/tealium.php
r1961829 r2007643 4 4 Plugin URI: http://tealium.com 5 5 Description: Adds the Tealium tag and creates a data layer for your WordPress site. 6 Version: 2.1.1 26 Version: 2.1.13 7 7 Author: Ian Hampton - Tealium EMEA 8 8 Author URI: http://tealium.com … … 191 191 add_filter( 'tealium_convertCamelCase', 'tealiumConvertCamelCase' ); 192 192 193 194 193 /* 195 194 * Adds WooCommerce data to data layer … … 206 205 // Get cart product IDs, SKUs, Titles etc. 207 206 foreach ( $woocart['cart_contents'] as $cartItem ) { 208 $productMeta = new WC_Product( $cartItem['product_id'] ); 209 $productData['product_id'][] = $cartItem['product_id']; 210 $productData['product_sku'][] = $productMeta->post->sku; 211 $productData['product_name'][] = $productMeta->post->post_title; 212 $productData['product_quantity'][] = $cartItem['quantity']; 213 $productData['product_regular_price'][] = get_post_meta( $cartItem['product_id'], '_regular_price', true ); 214 $productData['product_sale_price'][] = get_post_meta( $cartItem['product_id'], '_sale_price', true ); 215 $productData['product_type'][] = $productMeta->post->product_type; 207 $productMeta = wc_get_product( $cartItem['product_id'] ); 208 $productData['cart_product_id'][] = $cartItem['product_id']; 209 $productData['cart_product_sku'][] = $productMeta->get_sku(); 210 $productData['cart_product_name'][] = $productMeta->get_title(); 211 $productData['cart_product_quantity'][] = $cartItem['quantity']; 212 $productData['cart_product_regular_price'][] = $productMeta->get_regular_price(); 213 $productData['cart_product_sale_price'][] = $productMeta->get_sale_price(); 214 $productData['cart_product_price'][] = $productMeta->get_price(); 215 $productData['cart_product_type'][] = $productMeta->get_type(); 216 $productData['cart_product_stock_status'][] = $productMeta->get_stock_status(); 217 $productData['cart_product_slug'][] = $productMeta->get_slug(); 218 $productData['cart_product_category_id'][] = implode( "," , $productMeta->get_category_ids() ); 219 220 $categoryData = array(); 221 foreach ($productMeta->get_category_ids() as $category) { 222 $term = get_term_by('id', $category, 'product_cat', 'ARRAY_A'); 223 $categoryData[] = $term['slug']; 224 } 225 $productData['cart_product_category_slug'][] = implode( "," , $categoryData ); 216 226 } 217 227 } … … 228 238 if ( is_order_received_page() ) { 229 239 $orderId = apply_filters( 'woocommerce_thankyou_order_id', empty( $_GET['order'] ) ? ( $GLOBALS["wp"]->query_vars["order-received"] ? $GLOBALS["wp"]->query_vars["order-received"] : 0 ) : absint( $_GET['order'] ) ); 230 $orderKey = apply_filters( 'woocommerce_thankyou_order_key', empty( $_GET['key'] ) ? '' : w oocommerce_clean( $_GET['key'] ) );240 $orderKey = apply_filters( 'woocommerce_thankyou_order_key', empty( $_GET['key'] ) ? '' : wc_clean( $_GET['key'] ) ); 231 241 $orderData = array(); 232 242 233 243 if ( $orderId > 0 ) { 234 244 $order = new WC_Order( $orderId ); 235 if ( $order-> order_key!= $orderKey ) {245 if ( $order->get_order_key() != $orderKey ) { 236 246 unset( $order ); 237 247 } … … 243 253 $orderData["order_shipping"] = $order->get_total_shipping(); 244 254 $orderData["order_tax"] = $order->get_total_tax(); 245 $orderData["order_payment_type"] = $order-> payment_method_title;255 $orderData["order_payment_type"] = $order->get_payment_method_title(); 246 256 $orderData["order_shipping_type"] = $order->get_shipping_method(); 247 257 $orderData["order_coupon_code"] = implode( ", ", $order->get_used_coupons() ); 248 258 } 259 260 $orderProducts = $order->get_items(); 261 foreach( $orderProducts as $product ) { 262 $orderData['order_product_name'][] = $product['name']; 263 $orderData['order_product_quantity'][] = $product['quantity']; 264 } 249 265 250 266 $utagdata = array_merge( $utagdata, $orderData ); 251 267 } 252 268 269 // If single product page 270 if ( is_product() ) { 271 $productMeta = wc_get_product( get_the_ID() ); 272 $utagdata['product_id'] = $productMeta->get_id(); 273 $utagdata['product_sku'] = $productMeta->get_sku(); 274 $utagdata['product_name'] = $productMeta->get_title(); 275 $utagdata['product_regular_price'] = $productMeta->get_regular_price(); 276 $utagdata['product_sale_price'] = $productMeta->get_sale_price(); 277 $utagdata['product_price'] = $productMeta->get_price(); 278 $utagdata['product_type'] = $productMeta->get_type(); 279 $utagdata['product_stock_status'] = $productMeta->get_stock_status(); 280 $utagdata['product_slug'] = $productMeta->get_slug(); 281 $utagdata['product_category_id'] = $productMeta->get_category_ids(); 282 283 $categoryData = array(); 284 foreach ($productMeta->get_category_ids() as $category) { 285 $term = get_term_by('id', $category, 'product_cat', 'ARRAY_A'); 286 $categoryData[] = $term['slug']; 287 } 288 $utagdata['product_category_slug'] = $categoryData; 289 } 253 290 254 291 // Merge shop and cart details into utagdata … … 383 420 $tealiumNamespace = get_option( 'tealiumNamespace' , 'utag_data' ); 384 421 $tealiumNamespace = ( empty( $tealiumNamespace ) ? 'utag_data' : $tealiumNamespace ); 385 422 $jsondata = str_replace("\u0000*\u0000", "", $jsondata); 386 423 $utag_data = "<script type=\"text/javascript\">\nvar {$tealiumNamespace} = {$jsondata};\n</script>\n"; 387 424 if ( !$return ) {
Note: See TracChangeset
for help on using the changeset viewer.