'.ucfirst( $carrier ).' '.$machine['name'] . '' . $machine['address'] . '
';
}
}
} else {
//in case of a courier, wrap the time and trackinglink in address div as well
//to hide it during order editing.
//can be an empty div in case of other shipping methods
echo '
';
}
$shipment_id = $order->get_meta( '_parcel_machine_shipment_id', true );
$shipment_id_error = $order->get_meta( '_parcel_machine_error', true );
$shipment_manifest = $order->get_meta( '_parcel_machine_manifest', true );
$shippingMethod["method_title"] = '';
//currently the only delivery time option exists for smartpost courier shipping method.
//only one shipping method, get it easily from array with foreach
foreach ( $order->get_shipping_methods() as $shippingMethod) {
if ( $shippingMethod["method_id"] == "courier_smartpost" && !$shipment_id_error ) {
$delivery_time = $order->get_meta( '_delivery_time', true );
switch ( $delivery_time ) {
case '1':
echo '
'.__( 'Delivery time', 'wc_makecommerce_domain' ).' - '.__( 'Any time', 'wc_makecommerce_domain' ).'
';
break;
case '2':
echo '
'.__( 'Delivery time', 'wc_makecommerce_domain' ).' - 09:00..17:00
';
break;
case '3':
echo '
'.__( 'Delivery time', 'wc_makecommerce_domain' ).' - 17:00..21:00
';
break;
}
}
}
if ( $shipment_id ) {
$trackinglink = '
'.__( 'Shipment tracking code', 'wc_makecommerce_domain' ).' ';
if ( $carrier == "" ) {
$carrier = $this->get_order_shipment_carrier( $order );
}
if ( $carrier === 'lp_express_lt' ) {
$shipment_id = $order->get_meta( '_parcel_machine_shipment_barcode', true );
$carrier = "lpexpress";
}
$theLink = $this->get_tracking_link( $carrier, $order, $shipment_id, true );
if ( $carrier != "" && $theLink != "" ) {
$trackinglink .= ' ('. ucfirst( $shippingMethod["method_title"] ) .'): ' . $shipment_id . ' ';
} else {
$trackinglink .= ': '.$shipment_id;
}
echo $trackinglink.'
';
}
if ( $shipment_manifest ) {
echo '
'.__( 'Shipments pickup manifest' ).': link
';
}
if ( $shipment_id_error ) {
echo '
'.__( 'Shipment registration error' ).': ' . $shipment_id_error . '
';
}
echo '
';
}
/**
* Add shipping information on order list view
*
* @since 3.0.0
*/
public function shipping_method_order_view( $column ) {
global $post, $woocommerce, $the_order;
if ( !$the_order ) {
return;
}
$the_order_id = $the_order->get_id();
if ( empty( $the_order ) || $the_order_id != $post->ID ) {
$the_order = wc_get_order( $post->ID );
}
if ( $column === 'shipping_address' ) {
$shipment_id = $the_order->get_meta( '_parcel_machine_shipment_id', true );
$shipment_id_error = $the_order->get_meta( '_parcel_machine_error', true );
$identifier = $the_order->get_meta( '_lp_express_cart_identifier', true );
$barcode = $the_order->get_meta( '_parcel_machine_shipment_barcode', true );
// LP Express
if ( !empty( $identifier ) && !empty( $barcode ) ) {
$shipment_id = $barcode;
}
if ( $shipment_id ) {
echo __( 'Shipment tracking code', 'wc_makecommerce_domain' ) . ': ' . $shipment_id . '
';
echo '
';
} else if ( $shipment_id_error ) {
echo '
'.__( 'Package shipment generation error:', 'wc_makecommerce_domain' ) . ' ' .$shipment_id_error;
}
}
}
/**
* Fires before the Filter button on the Posts and Pages list tables.
* Allows filtering of orders by shipping method
*
* @since 3.0.0
*/
public function filter_orders() {
global $typenow;
if ( in_array( $typenow, wc_get_order_types( 'order-meta-boxes' ) ) ) {
$selected_method = !empty( $_REQUEST['_shipping_method'] ) ? $_REQUEST['_shipping_method'] : false;
$methods = WC()->shipping->load_shipping_methods();
echo '
';
echo ''.__( '-- filter by shipping method', 'wc_makecommerce_domain' ) . ' ';
foreach ( $methods as $method ) {
echo 'id ? ' selected="selected"' : '').'>'.$method->get_method_title().' ';
}
echo ' ';
}
}
/**
* Fires before the Filter button on the orders page
* Allows filtering of orders by shipping method
*
* @since 3.4.0
*/
public function hpos_filter_orders() {
if ( $_GET['page'] == 'wc-orders' ) {
$selected_method = !empty( $_REQUEST['_shipping_method'] ) ? $_REQUEST['_shipping_method'] : false;
$methods = WC()->shipping->load_shipping_methods();
echo '
';
echo ''.__( '-- filter by shipping method', 'wc_makecommerce_domain' ) . ' ';
foreach ( $methods as $method ) {
// Can not filter by methods which are not provided by MK
if ( !$method instanceof \MakeCommerce\Shipping\Method ) continue;
echo 'id ? ' selected="selected"' : '').'>'.$method->get_method_title().' ';
}
echo ' ';
}
}
/**
* Returns order shipment carrier
*
* @since 3.0.0
*/
private function get_order_shipment_carrier( $order ) {
foreach ( $order->get_shipping_methods() as $shippingMethod ) {
$carrier = explode( "_", $shippingMethod["method_id"] );
$carrier = $carrier[1];
}
return $carrier;
}
/**
* Add shipment data to email
*
* @since 3.0.0
*/
public function shipping_email_details( $fields, $sent_to_admin, $order ) {
// No mc metadata without calling the wc_get_order again
$order = wc_get_order( $order->get_id() );
//check if makecommerce shipping has been used
//add tracking information (if possible)
$shipment_id = $order->get_meta( "_parcel_machine_shipment_id", true );
$machine_id = $order->get_meta( '_parcel_machine', true );
$machine = "";
$carrier = "";
$machineIdArr = explode( '||', $machine_id );
if ( count( $machineIdArr ) == 2 ) {
$carrier = $machineIdArr[0];
$machine = $machineIdArr[1];
} else if ( count( $machineIdArr ) == 1 ) {
$carrier = $machineIdArr[0];
}
$machine = self::mk_get_machine( $carrier, $machine );
//do something about the language only if we even have something to add to the email
if ( $shipment_id || ( $machine != "" && $carrier != "" ) ) {
//this only needs to be done for polylang. Don't do it for wpml, that won't work.
if ( \MakeCommerce\i18n::is_polylang_active() ) {
$orderLang = get_locale();
if ( $orderLang != "" ) {
if ( substr( $orderLang, 0 ,2 ) == "en" ) {
switch_to_locale( "et" );
do_action( 'wpml_switch_language', "et" );
} else {
switch_to_locale( "en_GB" );
do_action( 'wpml_switch_language', "en_GB" );
}
switch_to_locale( $orderLang );
do_action( 'wpml_switch_language', $orderLang );
}
load_plugin_textdomain( 'wc_makecommerce_domain', false, '/makecommerce/languages/' );
}
}
if ( $machine != "" && $carrier != "" ) {
//add parcel machine name/location
if ( strtolower( $carrier ) == 'lp_express_lt') {
$fields[] = array( 'label' => __( 'Parcel machine', 'wc_makecommerce_domain' ).' (LP Express)', 'value' => $machine['name'].' - '.$machine['address']);
} else {
$fields[] = array( 'label' => __( 'Parcel machine', 'wc_makecommerce_domain' ).' ('.ucfirst( $carrier ).')', 'value' => $machine['name'].' - '.$machine['address']);
}
}
$shipment_id_error = $order->get_meta( '_parcel_machine_error', true );
//currently the only delivery time option exists for smartpost courier shipping method.
foreach ( $order->get_shipping_methods() as $shippingMethod ) {
if ( $shippingMethod["method_id"] == "courier_smartpost" ) {
$delivery_time = $order->get_meta( '_delivery_time', true );
if ( !$shipment_id_error ) {
if ( $delivery_time === '1' ) {
$fields[] = array( 'label' => __( 'Delivery time', 'wc_makecommerce_domain' ), 'value' => __( 'Any time', 'wc_makecommerce_domain' ) );
}
if ( $delivery_time === '2' ) {
$fields[] = array( 'label' => __( 'Delivery time', 'wc_makecommerce_domain' ), 'value' => "09:00..17:00" );
}
if ( $delivery_time === '3' ) {
$fields[] = array( 'label' => __( 'Delivery time', 'wc_makecommerce_domain' ), 'value' => "17:00..21:00" );
}
}
}
}
//add tracking information (if possible)
if ( $shipment_id && strtolower( $carrier ) !== "lp_express_lt" ) {
if ( $carrier == "" ) {
$carrier = $this->get_order_shipment_carrier( $order );
}
$href = $this->get_tracking_link( $carrier, $order, $shipment_id );
if ( $href != "" ) {
$fields[] = array( 'label' => __( 'Shipment tracking info', 'wc_makecommerce_domain' ).' ('.$carrier.')', 'value' => "
".$href." " );
} else {
$fields[] = array( 'label' => __( 'Shipment tracking info', 'wc_makecommerce_domain' ), 'value' => $shipment_id );
}
}
return $fields;
}
/**
* Adds bulk actions to orders page without JS
* Works with HPOS enabled
*
* @since 3.4.0
*/
public function mc_bulk_actions( $actions ) {
$actions['parcel_machine_register_orders'] = __( 'Register parcel machine shipments', 'wc_makecommerce_domain' );
$actions['parcel_machine_print_labels'] = __( 'Print parcel machine labels', 'wc_makecommerce_domain' );
return $actions;
}
/**
* Filters orders by _mc_shipping_method meta key
* Relies on hpos_filter_orders()
* Works with HPOS enabled
*
* @since 3.4.0
*/
public function order_filter_by_shipping_method( $args ) {
if ( is_admin() && !empty( $_REQUEST['_shipping_method'] ) && $_GET['page'] == 'wc-orders' ) {
$shipping_method = sanitize_text_field( $_REQUEST['_shipping_method'] );
$args['meta_query'] = [
[
'key' => '_mc_shipping_method',
'value' => $shipping_method
]
];
}
return $args;
}
}