export->is_postnl_destination($shipping_country)) { return; } $order_id = WCX_Order::get_id($order); $shipment_options = WooCommerce_PostNL()->export->get_options($order); $postnl_options_extra = WCX_Order::get_meta($order, '_postnl_shipment_options_extra'); $package_types = WooCommerce_PostNL()->export->get_package_types(); $recipient = WooCommerce_PostNL()->export->get_recipient($order); // get shipment data (exclude concepts = true) $consignments = $this->get_order_shipments($order, true); $style = $hide ? 'style="display:none"' : ''; // if we have shipments, then we show status & link to Track & Trace, settings under i if ( ! empty($consignments)) { // only use last shipment $last_shipment = array_pop($consignments); $last_shipment_id = $last_shipment['shipment_id']; ?>
> show_order_delivery_options($order); ?> i
> show_order_delivery_options($order); ?>
> %s ▾', $package_types[$shipment_options['package_type']]); ?>
export->get_shipment_data($shipment_id, $order); if ( ! empty($shipment['tracktrace'])) { $order_has_shipment = true; $tracktrace_url = $this->getTrackTraceUrl($order_id, $shipment['tracktrace']); } $package_types = WooCommerce_PostNL()->export->get_package_types(); include('views/wcmp-order-shipment-summary.php'); die(); } public function order_list_return_shipment_options($order, $hide = true) { $shipping_country = WCX_Order::get_prop($order, 'shipping_country'); if ($shipping_country != 'NL' && ! WooCommerce_PostNL()->export->is_eu_country($shipping_country)) { return; } $style = $hide ? 'style="display:none"' : ''; ?>
>
__('PostNL: Prepare shipment', 'woocommerce-postnl'), 'wcmp_print' => __('PostNL: Print', 'woocommerce-postnl'), 'wcmp_export_print' => __('PostNL: Prepare & print shipment', 'woocommerce-postnl'), ); if ('shop_order' == $post_type) { ?> 3.3.0 * Call the function admin_order_actions for the same settings * * @param $order */ public function admin_wc_actions($order) { return $this->admin_order_actions($order); } /** * Add print actions to the orders listing */ public function admin_order_actions($order) { if (empty($order)) { return; } $shipping_country = WCX_Order::get_prop($order, 'shipping_country'); if ( ! WooCommerce_PostNL()->export->is_postnl_destination($shipping_country)) { return; } $order_id = WCX_Order::get_id($order); $listing_actions = array( 'add_shipment' => array( 'url' => wp_nonce_url(admin_url('admin-ajax.php?action=wc_postnl&request=add_shipment&order_ids=' . $order_id), 'wc_postnl'), 'img' => WooCommerce_PostNL()->plugin_url() . '/assets/img/postnl-up.png', 'alt' => esc_attr__('Export to PostNL', 'woocommerce-postnl'), ), 'get_labels' => array( 'url' => wp_nonce_url(admin_url('admin-ajax.php?action=wc_postnl&request=get_labels&order_ids=' . $order_id), 'wc_postnl'), 'img' => WooCommerce_PostNL()->plugin_url() . '/assets/img/postnl-pdf.png', 'alt' => esc_attr__('Print PostNL label', 'woocommerce-postnl'), ), ); $consignments = $this->get_order_shipments($order); if (empty($consignments)) { unset($listing_actions['get_labels']); } $processed_shipments = $this->get_order_shipments($order, true); if (empty($processed_shipments) || $shipping_country != 'NL') { unset($listing_actions['add_return']); } $target = (isset(WooCommerce_PostNL()->general_settings['download_display']) && WooCommerce_PostNL()->general_settings['download_display'] == 'display') ? 'target="_blank"' : ''; $nonce = wp_create_nonce('wc_postnl'); foreach ($listing_actions as $action => $data) { printf( '', $data['url'], $action, $data['alt'], $order_id, $nonce, $target ); ?> <?php echo $data['alt']; ?> $consignment_id, 'tracktrace' => WCX_Order::get_meta($order, '_postnl_tracktrace'), ), ); } else { if ($legacy_consignments = WCX_Order::get_meta($order, '_postnl_consignments')) { $consignments = array(); foreach ($legacy_consignments as $consignment) { if (isset($consignment['consignment_id'])) { $consignments[] = array( 'shipment_id' => $consignment['consignment_id'], 'tracktrace' => $consignment['tracktrace'], ); } } } } } if (empty($consignments) || ! is_array($consignments)) { return false; } if ( ! empty($consignments) && $exclude_concepts) { foreach ($consignments as $key => $consignment) { if (empty($consignment['tracktrace'])) { unset($consignments[$key]); } } } return $consignments; } public function save_shipment_options_ajax() { check_ajax_referer('wc_postnl', 'security'); extract($_POST); parse_str($form_data, $form_data); $order = WCX::get_order($order_id); if (isset($form_data['postnl_options'][$order_id])) { $shipment_options = $form_data['postnl_options'][$order_id]; // convert insurance option if (isset($shipment_options['insured'])) { unset($shipment_options['insured']); $shipment_options['insurance'] = array( 'amount' => (int) $shipment_options['insured_amount'] * 100, 'currency' => 'EUR', ); unset($shipment_options['insured_amount']); } // separate extra options if (isset($shipment_options['extra_options'])) { WCX_Order::update_meta_data( $order, '_postnl_shipment_options_extra', $shipment_options['extra_options'] ); unset($shipment_options['extra_options']); } WCX_Order::update_meta_data($order, '_postnl_shipment_options', $shipment_options); } // Quit out die(); } /** * Add the meta box on the single order page */ public function shop_order_metabox() { add_meta_box( 'postnl', //$id __('PostNL', 'woocommerce-postnl'), //$title array($this, 'create_box_content'), //$callback 'shop_order', //$post_type 'side', //$context 'default' //$priority ); } /** * Callback: Create the meta box content on the single order page */ public function create_box_content() { global $post_id; // get order $order = WCX::get_order($post_id); if ( ! $order) { return; } $order_id = WCX_Order::get_id($order); $shipping_country = WCX_Order::get_prop($order, 'shipping_country'); if ( ! WooCommerce_PostNL()->export->is_postnl_destination($shipping_country)) { return; } // show buttons and check if WooCommerce > 3.3.0 is used and select the correct function and class if (version_compare(WOOCOMMERCE_VERSION, '3.3.0', '>=')) { echo '
'; $this->admin_wc_actions($order, false); } else { echo '
'; $this->admin_order_actions($order, false); } echo '
'; $consignments = $this->get_order_shipments($order); // show shipments if available if ( ! empty($consignments)) { ?> general_settings['download_display']) && WooCommerce_PostNL()->general_settings['download_display'] == 'display') ? 'target="_blank"' : ''; $nonce = wp_create_nonce('wc_postnl'); $label_button_text = esc_attr__('Print PostNL label', 'woocommerce-postnl'); foreach ($consignments as $shipment_id => $shipment): $shipment = WooCommerce_PostNL()->export->get_shipment_data($shipment_id, $order); $label_url = wp_nonce_url(admin_url('admin-ajax.php?action=wc_postnl&request=get_labels&shipment_ids=' . $shipment_id),'wc_postnl'); if (isset($shipment['tracktrace'])) { $tracktrace_url = $this->getTrackTraceUrl($order_id, $shipment['tracktrace']); $tracktrace_link = sprintf('%s', $tracktrace_url, $shipment['tracktrace']); } else { if (isset($shipment['shipment']) && isset($shipment['shipment']['options'])) { $tracktrace_link = '(' . WooCommerce_PostNL()->export->get_package_name( $shipment['shipment']['options']['package_type']) . ')'; } else { $tracktrace_link = '(Unknown)'; } } $status = isset($shipment['status']) ? $shipment['status'] : '-'; ?>
 
', $label_url, $action, $label_button_text, $order_id, $nonce, $target ); printf( '%2$s', WooCommerce_PostNL()->plugin_url() . "/assets/img/postnl-pdf.png", $label_button_text ); printf(""); ?>
export->is_postnl_destination($shipping_country)) { return; } echo '
' . __('PostNL shipment:', 'woocommerce-postnl') . '
'; $this->order_list_shipment_options($order, false); echo '
'; } public function show_order_delivery_options($order) { $delivery_options = WCX_Order::get_meta($order, '_postnl_delivery_options'); $shipping_country = WCX_Order::get_prop($order, 'shipping_country'); if ( ! empty($delivery_options) && is_array($delivery_options)) { extract($delivery_options); } echo '
'; if ( ! empty($date) && ! (isset(WooCommerce_PostNL()->checkout_settings['deliverydays_window']) && WooCommerce_PostNL()->checkout_settings['deliverydays_window'] == 0) && $shipping_country === 'NL' ) { $formatted_date = date_i18n( apply_filters('wcpostnl_delivery_date_format', wc_date_format()), strtotime($date) ); if ( ! empty($time)) { $time = array_shift($time); // take first element in time array if (isset($time['price_comment'])) { switch ($time['price_comment']) { case 'morning': $time_title = __('Morning delivery', 'woocommerce-postnl'); break; case 'standard': // $time_title = __( 'Standard delivery', 'woocommerce-postnl' ); break; case 'evening': case 'avond': $time_title = __('Evening delivery', 'woocommerce-postnl'); break; } } $time_title = ! empty($time_title) ? "({$time_title})" : ''; } printf( '
%s: %s %s
', __('Delivery date', 'woocommerce-postnl'), $formatted_date, $time_title ); } if ($pickup = WooCommerce_PostNL()->export->is_pickup($order, $delivery_options)) { switch($pickup['price_comment']) { case 'retail': $title = __('PostNL Pickup', 'woocommerce-postnl'); break; case 'retailexpress': $title = __('PostNL Pickup Express', 'woocommerce-postnl'); break; } echo "
{$title}: {$pickup['location']}, {$pickup['street']} {$pickup['number']}, {$pickup['postal_code']} {$pickup['city']}
"; } echo '
'; } public function getTrackTraceUrl($order_id, $tracktrace) { if (empty($order_id)) { return; } $order = WCX::get_order($order_id); $country = WCX_Order::get_prop($order, 'shipping_country'); $postcode = preg_replace('/\s+/', '', WCX_Order::get_prop($order, 'shipping_postcode')); // set url for NL or foreign orders if ($country == 'NL') { // use billing postcode for pickup/pakjegemak if (WooCommerce_PostNL()->export->is_pickup($order)) { $postcode = preg_replace('/\s+/', '', WCX_Order::get_prop($order, 'billing_postcode')); } $trackTraceUrlNl = sprintf( 'https://jouw.postnl.nl/#!/track-en-trace/%s/%s/%s', $tracktrace, $country, $postcode ); return $trackTraceUrlNl; } $trackTraceUrl = sprintf( 'https://www.internationalparceltracking.com/Main.aspx#/track/%s/%s/%s', $tracktrace, $country, $postcode ); return $trackTraceUrl; } public function get_tracktrace_links($order_id) { if ($consignments = $this->get_tracktrace_shipments($order_id)) { foreach ($consignments as $key => $consignment) { $tracktrace_links[] = $consignment['tracktrace_link']; } return $tracktrace_links; } else { return false; } } public function get_tracktrace_shipments($order_id) { $order = WCX::get_order($order_id); $shipments = $this->get_order_shipments($order, true); if (empty($shipments)) { return false; } foreach ($shipments as $shipment_id => $shipment) { // skip concepts, letters & mailbox packages if (empty($shipment['tracktrace'])) { unset($shipments[$shipment_id]); continue; } // add links & urls $shipments[$shipment_id]['tracktrace_url'] = $tracktrace_url = $this->getTrackTraceUrl( $order_id, $shipment['tracktrace'] ); $shipments[$shipment_id]['tracktrace_link'] = sprintf( '%s', $tracktrace_url, $shipment['tracktrace'] ); } if (empty($shipments)) { return false; } return $shipments; } public function product_hs_code_field() { echo '
'; woocommerce_wp_text_input( array( 'id' => '_postnl_hs_code', 'label' => __('HS Code', 'woocommerce-postnl'), 'description' => sprintf( __('HS Codes are used for PostNL world shipments, you can find the appropriate code on the %ssite of the Dutch Customs%s.', 'woocommerce-postnl'), '', '' ) ) ); echo '
'; } public function product_hs_code_field_save($post_id) { // check if hs code is passed and not an array (=variation hs code) if (isset($_POST['_postnl_hs_code']) && ! is_array($_POST['_postnl_hs_code'])) { $product = wc_get_product($post_id); $hs_code = $_POST['_postnl_hs_code']; if ( ! empty($hs_code)) { WCX_Product::update_meta_data($product, '_postnl_hs_code', esc_attr($hs_code)); } else { if (isset($_POST['_postnl_hs_code']) && empty($hs_code)) { WCX_Product::delete_meta_data($product, '_postnl_hs_code'); } } } } /** * @snippet Add Column to Orders Table (e.g. Barcode) - WooCommerce * * @param $columns * * @return mixed */ public function barcode_add_new_order_admin_list_column($columns) { // I want to display Barcode column just after the date column return array_slice($columns, 0, 6, true) + array('barcode' => 'Barcode') + array_slice($columns, 6, null, true); } /** * @param $column */ public function barcode_add_new_order_admin_list_column_content($column) { global $post; if ('barcode' === $column) { $order = WCX::get_order($post->ID); echo $this->get_barcode($order); } } /** * @param $order * @param null $barcode * * @return string|null */ public function get_barcode($order, $barcode = null) { $shipments = $this->get_order_shipments($order, true); if (empty($shipments)) { return __('No label has created yet', 'woocommerce-postnl'); } foreach ($shipments as $shipment_id => $shipment) { $barcode .= "" . $shipment['tracktrace'] . "
"; } return $barcode; } } endif; // class_exists return new WooCommerce_PostNL_Admin();