Advanced Shipment Tracking for WooCommerce
First, look at the article.
1. Add GREEN (not gray) meta keys “tracking_provider” , “tracking_number” or “shipping_date”
2. Put this code in section “Misc Settings”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
//prepare title for providers , once global $woe_ast_provider_title; global $wpdb; $woe_ast_provider_title = array(); $woo_shippment_table_name = $wpdb->prefix . 'woo_shippment_provider'; $providers = $wpdb->get_results( "SELECT ts_slug,provider_name FROM {$woo_shippment_table_name} WHERE provider_name IS NOT NULL", ARRAY_A ); $woe_ast_provider_title = wp_list_pluck($providers,"provider_name","ts_slug"); //fill product tracking information add_filter( 'woe_fetch_order_product', function($row, $order, $item, $product, $item_meta ){ global $woe_ast_provider_title; if( class_exists("WC_Advanced_Shipment_Tracking_Actions") ) $st = WC_Advanced_Shipment_Tracking_Actions::get_instance(); elseif( class_exists("AST_Pro_Actions") ) $st = AST_Pro_Actions::get_instance(); else return $row; $tracking_items = $st->get_tracking_items( $order->get_id() ); if( !$tracking_items ) return $row; //we have tracking information for this order $tracking_numbers = array(); $tracking_providers = array(); $shipping_dates = array(); foreach($tracking_items as $tracking_item) { //free version have only global information if( !isset($tracking_item["products_list"]) OR empty($tracking_item["products_list"]) ) { $tracking_numbers[] = $tracking_item['tracking_number']; $tracking_providers[] = isset($woe_ast_provider_title[$tracking_item['tracking_provider']]) ? $woe_ast_provider_title[$tracking_item['tracking_provider']] : $tracking_item['tracking_provider']; $shipping_dates[] = date_i18n( wc_date_format(), $tracking_item['date_shipped']); continue; } // Paid addon "Tracking per items" is active! foreach($tracking_item["products_list"] as $tracked_product) { if($tracked_product->item_id == $item->get_id() ) { $tracking_numbers[] = $tracking_item['tracking_number']; $tracking_providers[] = isset($woe_ast_provider_title[$tracking_item['tracking_provider']]) ? $woe_ast_provider_title[$tracking_item['tracking_provider']] : $tracking_item['tracking_provider']; $shipping_dates[] = date_i18n( wc_date_format(), $tracking_item['date_shipped']); } } } //only set exported columns if( isset($row['tracking_number'])) $row['tracking_number'] = join(",", $tracking_numbers); if( isset($row['tracking_provider'])) $row['tracking_provider'] = join(",", $tracking_providers); if( isset($row['shipping_date'])) $row['shipping_date'] = join(",", $shipping_dates); return $row; },10,5); |