@@ 131-144 (lines=14) @@ | ||
128 | ||
129 | // Order items |
|
130 | if ( $order->get_items() ) { |
|
131 | foreach ( $order->get_items() as $item ) { |
|
132 | $product = $order->get_product_from_item( $item ); |
|
133 | $product_sku_or_id = Jetpack_Google_Analytics_Utils::get_product_sku_or_id( $product ); |
|
134 | ||
135 | $item_details = array( |
|
136 | 'id' => $product_sku_or_id, |
|
137 | 'name' => $item['name'], |
|
138 | 'category' => Jetpack_Google_Analytics_Utils::get_product_categories_concatenated( $product ), |
|
139 | 'price' => $order->get_item_total( $item ), |
|
140 | 'quantity' => $item['qty'], |
|
141 | ); |
|
142 | $command = "ga( 'ec:addProduct', " . wp_json_encode( $item_details ) . " );"; |
|
143 | array_push( $command_array, $command ); |
|
144 | } |
|
145 | } |
|
146 | ||
147 | // Order summary |
|
@@ 374-387 (lines=14) @@ | ||
371 | $universal_commands = array(); |
|
372 | $cart = WC()->cart->get_cart(); |
|
373 | ||
374 | foreach ( $cart as $cart_item_key => $cart_item ) { |
|
375 | /** |
|
376 | * This filter is already documented in woocommerce/templates/cart/cart.php |
|
377 | */ |
|
378 | $product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
379 | $product_sku_or_id = Jetpack_Google_Analytics_Utils::get_product_sku_or_id( $product ); |
|
380 | ||
381 | $item_details = array( |
|
382 | 'id' => $product_sku_or_id, |
|
383 | 'name' => $product->get_title(), |
|
384 | 'category' => Jetpack_Google_Analytics_Utils::get_product_categories_concatenated( $product ), |
|
385 | 'price' => $product->get_price(), |
|
386 | 'quantity' => $cart_item[ 'quantity' ] |
|
387 | ); |
|
388 | ||
389 | array_push( $universal_commands, "ga( 'ec:addProduct', " . wp_json_encode( $item_details ) . " );" ); |
|
390 | } |