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']; ?>
$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 '|
',
$label_url,
$action,
$label_button_text,
$order_id,
$nonce,
$target
);
printf(
' |