コード例 #1
0
        public function __construct()
        {
            //Global variable for accessing post data
            global $post;
            //get shipment data for this order
            $shipment = get_post_meta($post->ID, '_shipment', true);
            //create instance of WooCommerce order for accessing order data
            $order = wc_get_order($post->ID);
            //Update shipment structure for version compatibility
            $shipment = cleanse_shipment($order, $shipment);
            if ($shipment['_shipment_status'] !== 'Not Shipped' && $shipment['_shipment_status'] !== 'DELIVERED') {
                if ((bool) @fsockopen('www.canyonwerks.com', 80)) {
                    $shipment = slp_ajax_functions::track_shipment($order, $shipment);
                } else {
                    ?>
				<script type="text/javascript">
					$('<div id="message" class="error fade"><p><strong>Connection Error. Please check internet connection.</strong>').insertAfter('#wpbody-content > .wrap > h2');	

				</script><?php 
                }
            }
            //display SLP meta box
            $this->get_meta_box($order, $shipment);
        }
コード例 #2
0
 public function get_shipments()
 {
     global $wpdb, $woocommerce;
     $shipments = array();
     $posts = $wpdb->get_results($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type LIKE %s AND post_status LIKE %s ORDER BY ID", 'shop_order', 'wc-completed'));
     foreach ($posts as $key => $post) {
         $order = wc_get_order($post->ID);
         $shipment = get_post_meta($order->id, '_shipment', true);
         $shipment = cleanse_shipment($order, $shipment);
         $order_number = get_post_meta($order->id, '_order_number') ? get_post_meta($order->id, '_order_number', true) : $order->id;
         $service = $order->get_shipping_method();
         $carrier = explode(',', $service);
         $carrier = trim(preg_replace('#[()]#', '', substr($carrier[0], strpos($carrier[0], '('))));
         $order_link = '<a href="' . admin_url('post.php?post=' . $order->id . '&action=edit') . '">' . $order_number . '</a>';
         foreach ($shipment['_packages'] as $key => $package) {
             $trackingNumbers = get_tracking_url($carrier, $package->id, $order->shipping_postcode);
         }
         if (is_array($shipment['_shipment_status'])) {
             $shipment['_shipment_status'] = $shipment['_shipment_status'][0];
             self::update_shipment($order - id, $shipment);
         }
         /*if( ! isset( $status['status'] ) || ( ! $status['status'] == "DELIVERED" && ! $status['status'] == 'Not Trackable' ) ){
         			$shipment = self::track_shipment( $order->id, $shipment );	
         		}*/
         array_push($shipments, array('<input type="checkbox" class="sel_shipments" id="' . $order->id . '"/>', $order_link, ucwords($order->billing_first_name) . ' ' . ucwords($order->billing_last_name), $trackingNumbers, $service, $shipment['_shipping_date'], $shipment['_shipment_status'], wc_price($shipment['_shipping_costs'])));
     }
     echo json_encode($shipments);
     die;
 }