' . esc_html__( 'Settings', 'codbox' ) . '' ); return $links; } ); /* ---------------- connect / disconnect ---------------- */ add_action( 'admin_post_codbox_connect', 'codbox_handle_connect' ); add_action( 'admin_post_codbox_disconnect', 'codbox_handle_disconnect' ); /** Shows a message on the CODbox settings page after a redirect (kept for one minute, per user). */ function codbox_redirect( $msg, $type = 'success' ) { set_transient( 'codbox_notice_' . get_current_user_id(), array( 'msg' => (string) $msg, 'type' => 'error' === $type ? 'error' : 'success' ), MINUTE_IN_SECONDS ); wp_safe_redirect( admin_url( 'options-general.php?page=codbox' ) ); exit; } function codbox_handle_connect() { if ( ! current_user_can( 'manage_woocommerce' ) ) { wp_die( esc_html__( 'Not allowed.', 'codbox' ) ); } check_admin_referer( 'codbox_connect' ); if ( ! class_exists( 'WC_Webhook' ) ) { codbox_redirect( __( 'WooCommerce is not active.', 'codbox' ), 'error' ); } $code = isset( $_POST['codbox_code'] ) ? strtoupper( sanitize_text_field( wp_unslash( $_POST['codbox_code'] ) ) ) : ''; if ( ! preg_match( '/^CB-[A-Z0-9]{4}-[A-Z0-9]{4}$/', $code ) ) { codbox_redirect( __( 'The code should look like CB-XXXX-XXXX.', 'codbox' ), 'error' ); } $response = wp_remote_post( CODBOX_API . '/api/connect', array( 'timeout' => 20, 'headers' => array( 'Content-Type' => 'application/json' ), 'body' => wp_json_encode( array( 'code' => $code, 'site_url' => home_url(), 'wp_version' => get_bloginfo( 'version' ), 'wc_version' => defined( 'WC_VERSION' ) ? WC_VERSION : '', 'plugin' => CODBOX_VERSION, ) ), ) ); if ( is_wp_error( $response ) ) { codbox_redirect( __( 'Could not reach CODbox: ', 'codbox' ) . $response->get_error_message(), 'error' ); } $data = json_decode( wp_remote_retrieve_body( $response ), true ); if ( empty( $data['ok'] ) || empty( $data['secret'] ) || empty( $data['webhook_url'] ) ) { codbox_redirect( __( 'This code is not valid. Copy it again from app.codbox.app.', 'codbox' ), 'error' ); } // Remove old webhooks if the store is reconnected. codbox_delete_webhooks(); $ids = array(); foreach ( array( 'order.created' => 'CODbox: order created', 'order.updated' => 'CODbox: order updated' ) as $topic => $name ) { $webhook = new WC_Webhook(); $webhook->set_name( $name ); $webhook->set_user_id( get_current_user_id() ); $webhook->set_topic( $topic ); $webhook->set_secret( $data['secret'] ); $webhook->set_delivery_url( esc_url_raw( $data['webhook_url'] ) ); $webhook->set_status( 'active' ); $webhook->set_api_version( 'wp_api_v3' ); $ids[] = $webhook->save(); } $old = codbox_get_settings(); update_option( CODBOX_OPTION, array( 'complete_on_ship' => isset( $old['complete_on_ship'] ) ? (bool) $old['complete_on_ship'] : true, 'connected' => true, 'shop_name' => sanitize_text_field( $data['shop_name'] ?? '' ), 'secret' => $data['secret'], 'webhook_url' => esc_url_raw( $data['webhook_url'] ), 'app_url' => esc_url_raw( $data['app_url'] ?? CODBOX_API ), 'webhook_ids' => array_map( 'absint', $ids ), 'connected_at' => time(), ), false ); $sent = codbox_send_recent_orders( 20 ); /* translators: %d: number of orders */ codbox_redirect( sprintf( __( 'Connected! %d recent orders were sent to CODbox.', 'codbox' ), $sent ) ); } function codbox_delete_webhooks() { $s = codbox_get_settings(); if ( empty( $s['webhook_ids'] ) || ! function_exists( 'wc_get_webhook' ) ) { return; } foreach ( (array) $s['webhook_ids'] as $id ) { $w = wc_get_webhook( absint( $id ) ); if ( $w ) { $w->delete( true ); } } } function codbox_handle_disconnect() { if ( ! current_user_can( 'manage_woocommerce' ) ) { wp_die( esc_html__( 'Not allowed.', 'codbox' ) ); } check_admin_referer( 'codbox_disconnect' ); codbox_delete_webhooks(); delete_option( CODBOX_OPTION ); codbox_redirect( __( 'Disconnected. No more orders are sent to CODbox.', 'codbox' ) ); } /* ---------------- send recent orders after connecting ---------------- */ function codbox_order_payload( $order ) { $created = $order->get_date_created(); $items = array(); foreach ( $order->get_items() as $item ) { $meta = array(); foreach ( $item->get_formatted_meta_data( '_', true ) as $m ) { $meta[] = array( 'key' => $m->key, 'display_key' => wp_strip_all_tags( $m->display_key ), 'display_value' => wp_strip_all_tags( $m->display_value ) ); } $items[] = array( 'name' => $item->get_name(), 'quantity' => $item->get_quantity(), 'total' => $item->get_total(), 'meta_data' => $meta, 'codbox_cost' => codbox_item_cost( $item ) ); } return array( 'id' => $order->get_id(), 'parent_id' => $order->get_parent_id(), 'number' => $order->get_order_number(), 'status' => $order->get_status(), 'total' => $order->get_total(), 'currency' => $order->get_currency(), 'payment_method' => $order->get_payment_method(), 'payment_method_title' => $order->get_payment_method_title(), 'shipping_total' => $order->get_shipping_total(), 'discount_total' => $order->get_discount_total(), 'customer_note' => $order->get_customer_note(), 'date_created_gmt' => $created ? gmdate( 'Y-m-d\TH:i:s', $created->getTimestamp() ) : null, 'billing' => array( 'first_name' => $order->get_billing_first_name(), 'last_name' => $order->get_billing_last_name(), 'phone' => $order->get_billing_phone(), 'email' => $order->get_billing_email(), 'city' => $order->get_billing_city(), 'address_1' => $order->get_billing_address_1(), 'address_2' => $order->get_billing_address_2(), 'postcode' => $order->get_billing_postcode(), 'country' => $order->get_billing_country(), ), 'shipping' => array( 'city' => $order->get_shipping_city(), 'address_1' => $order->get_shipping_address_1(), 'address_2' => $order->get_shipping_address_2(), 'postcode' => $order->get_shipping_postcode(), 'country' => $order->get_shipping_country(), ), 'line_items' => $items, ); } function codbox_send_recent_orders( $limit ) { $s = codbox_get_settings(); if ( empty( $s['secret'] ) || ! function_exists( 'wc_get_orders' ) ) { return 0; } $orders = wc_get_orders( array( 'limit' => $limit, 'orderby' => 'date', 'order' => 'DESC', 'type' => 'shop_order' ) ); $sent = 0; foreach ( array_reverse( $orders ) as $order ) { $body = wp_json_encode( codbox_order_payload( $order ) ); $res = wp_remote_post( $s['webhook_url'], array( 'timeout' => 10, 'headers' => array( 'Content-Type' => 'application/json', 'X-WC-Webhook-Topic' => 'order.updated', 'X-WC-Webhook-Source' => home_url( '/' ), 'X-WC-Webhook-Signature' => base64_encode( hash_hmac( 'sha256', $body, $s['secret'], true ) ), ), 'body' => $body, ) ); if ( ! is_wp_error( $res ) && 200 === wp_remote_retrieve_response_code( $res ) ) { $sent++; } } return $sent; } /* ---------------- changes from the CODbox app (confirm / ship / cancel) ---------------- */ add_action( 'rest_api_init', function () { foreach ( array( 'order-update' => 'codbox_rest_order_update', 'resync' => 'codbox_rest_resync', 'blacklist' => 'codbox_rest_blacklist' ) as $route => $cb ) { register_rest_route( 'codbox/v1', '/' . $route, array( 'methods' => 'POST', 'callback' => $cb, 'permission_callback' => '__return_true', // checked by HMAC signature in codbox_verify_request() ) ); } } ); /** * Checks the HMAC signature and timestamp of a request from CODbox. Returns the decoded body or a WP_REST_Response error. */ function codbox_verify_request( WP_REST_Request $request ) { $s = codbox_get_settings(); if ( empty( $s['secret'] ) ) { return new WP_REST_Response( array( 'ok' => false, 'error' => 'not_connected' ), 403 ); } $body = $request->get_body(); $sig = (string) $request->get_header( 'x_codbox_signature' ); $calc = base64_encode( hash_hmac( 'sha256', $body, $s['secret'], true ) ); if ( '' === $sig || ! hash_equals( $calc, $sig ) ) { return new WP_REST_Response( array( 'ok' => false, 'error' => 'bad_signature' ), 401 ); } $d = json_decode( $body, true ); if ( ! is_array( $d ) || empty( $d['ts'] ) || abs( time() - (int) $d['ts'] ) > 300 ) { return new WP_REST_Response( array( 'ok' => false, 'error' => 'expired' ), 400 ); } return $d; } function codbox_rest_resync( WP_REST_Request $request ) { $d = codbox_verify_request( $request ); if ( $d instanceof WP_REST_Response ) { return $d; } $limit = min( 50, max( 1, absint( $d['limit'] ?? 50 ) ) ); return new WP_REST_Response( array( 'ok' => true, 'sent' => codbox_send_recent_orders( $limit ) ), 200 ); } function codbox_phase_label( $phase ) { $l = array( 'new' => __( 'New', 'codbox' ), 'confirmed' => __( 'Confirmed with the buyer', 'codbox' ), 'packed' => __( 'Packed', 'codbox' ), 'shipped' => __( 'Shipped', 'codbox' ), 'delivered' => __( 'Delivered', 'codbox' ), 'cancelled' => __( 'Cancelled', 'codbox' ), 'unpaid' => __( 'Unpaid', 'codbox' ), ); return $l[ $phase ] ?? $phase; } function codbox_rest_order_update( WP_REST_Request $request ) { $d = codbox_verify_request( $request ); if ( $d instanceof WP_REST_Response ) { return $d; } $s = codbox_get_settings(); $order = wc_get_order( absint( $d['woo_id'] ?? 0 ) ); if ( ! $order ) { return new WP_REST_Response( array( 'ok' => false, 'error' => 'order_not_found' ), 404 ); } $action = sanitize_key( $d['action'] ?? '' ); if ( 'phase' === $action ) { $phase = sanitize_key( $d['phase'] ?? '' ); $courier = sanitize_text_field( $d['courier'] ?? '' ); $tracking = sanitize_text_field( $d['tracking'] ?? '' ); $najava = sanitize_text_field( $d['najava'] ?? '' ); $before = array( $order->get_meta( '_codbox_phase' ), $order->get_meta( '_codbox_courier' ), $order->get_meta( '_codbox_tracking' ), $order->get_meta( '_codbox_najava' ) ); $order->update_meta_data( '_codbox_phase', $phase ); $order->update_meta_data( '_codbox_courier', $courier ); $order->update_meta_data( '_codbox_tracking', $tracking ); $order->update_meta_data( '_codbox_najava', $najava ); $track_url = esc_url_raw( (string) ( $d['track_url'] ?? '' ), array( 'https' ) ); $order->update_meta_data( '_codbox_track_url', $tracking ? $track_url : '' ); if ( 'confirmed' === $phase && ! $order->get_meta( '_codbox_confirmed_at' ) ) { $order->update_meta_data( '_codbox_confirmed_at', time() ); } $order->save(); if ( array( $phase, $courier, $tracking, $najava ) === $before ) { return new WP_REST_Response( array( 'ok' => true, 'unchanged' => true ), 200 ); } $note = sprintf( 'CODbox: %s', codbox_phase_label( $phase ) ); if ( $tracking || $najava ) { $note .= ' · ' . $courier . ( $tracking ? ' · ' . $tracking : '' ) . ( $najava ? ' · ' . $najava : '' ); } $status = $order->get_status(); $complete = ! isset( $s['complete_on_ship'] ) || $s['complete_on_ship']; if ( 'cancelled' === $phase ) { $order->update_status( 'cancelled', $note ); } elseif ( 'delivered' === $phase || ( 'shipped' === $phase && $complete ) ) { $order->update_status( 'completed', $note ); } elseif ( in_array( $phase, array( 'confirmed', 'packed', 'shipped' ), true ) && in_array( $status, array( 'cancelled', 'completed', 'pending', 'failed' ), true ) ) { $order->update_status( 'processing', $note ); } else { $order->add_order_note( $note ); } } elseif ( 'cancel' === $action ) { $order->update_status( 'cancelled', __( 'Cancelled in CODbox.', 'codbox' ) ); } else { return new WP_REST_Response( array( 'ok' => false, 'error' => 'unknown_action' ), 400 ); } return new WP_REST_Response( array( 'ok' => true ), 200 ); } /* ---------------- purchase cost (nabavna cena) ---------------- */ function codbox_parse_cost( $v ) { $v = trim( (string) $v ); if ( '' === $v ) { return ''; } return (string) wc_format_decimal( str_replace( ',', '.', $v ) ); } // Simple products: field under the regular price. add_action( 'woocommerce_product_options_pricing', function () { woocommerce_wp_text_input( array( 'id' => '_codbox_cost', 'label' => __( 'Purchase cost', 'codbox' ) . ' (' . get_woocommerce_currency_symbol() . ')', 'desc_tip' => true, 'description' => __( 'What one piece costs you. Only CODbox uses it, to show your profit. Buyers never see it.', 'codbox' ), 'data_type' => 'price', ) ); } ); add_action( 'woocommerce_admin_process_product_object', function ( $product ) { if ( isset( $_POST['_codbox_cost'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification -- WooCommerce checks the product nonce. $product->update_meta_data( '_codbox_cost', codbox_parse_cost( sanitize_text_field( wp_unslash( $_POST['_codbox_cost'] ) ) ) ); // phpcs:ignore WordPress.Security.NonceVerification } } ); // Variations: field next to the variation price. add_action( 'woocommerce_variation_options_pricing', function ( $loop, $variation_data, $variation ) { woocommerce_wp_text_input( array( 'id' => '_codbox_cost_' . $loop, 'name' => '_codbox_cost[' . $loop . ']', 'value' => get_post_meta( $variation->ID, '_codbox_cost', true ), 'label' => __( 'Purchase cost', 'codbox' ) . ' (' . get_woocommerce_currency_symbol() . ')', 'wrapper_class' => 'form-row form-row-full', 'placeholder' => __( 'Same as the main product', 'codbox' ), 'data_type' => 'price', ) ); }, 10, 3 ); add_action( 'woocommerce_save_product_variation', function ( $variation_id, $i ) { if ( isset( $_POST['_codbox_cost'][ $i ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification $v = wc_get_product( $variation_id ); if ( $v ) { $v->update_meta_data( '_codbox_cost', codbox_parse_cost( sanitize_text_field( wp_unslash( $_POST['_codbox_cost'][ $i ] ) ) ) ); // phpcs:ignore WordPress.Security.NonceVerification $v->save(); } } }, 10, 2 ); function codbox_product_cost( $product ) { if ( ! $product ) { return ''; } $c = $product->get_meta( '_codbox_cost' ); if ( '' === (string) $c && $product->get_parent_id() ) { $parent = wc_get_product( $product->get_parent_id() ); $c = $parent ? $parent->get_meta( '_codbox_cost' ) : ''; } return (string) $c; } // Remember the cost at the moment of the order, so later price changes do not change old profit. add_action( 'woocommerce_checkout_create_order_line_item', function ( $item, $cart_item_key, $values ) { $c = codbox_product_cost( isset( $values['data'] ) ? $values['data'] : null ); if ( '' !== $c ) { $item->add_meta_data( '_codbox_cost', $c, true ); } }, 10, 3 ); /** Cost of ONE piece for an order item, or null when the shop has not entered it. */ function codbox_item_cost( $item ) { if ( ! is_a( $item, 'WC_Order_Item_Product' ) ) { return null; } $c = $item->get_meta( '_codbox_cost' ); if ( '' === (string) $c ) { $c = codbox_product_cost( $item->get_product() ); } return '' === (string) $c ? null : (float) $c; } // Add the cost to CODbox webhooks only (other webhooks stay as they are). add_filter( 'woocommerce_webhook_payload', function ( $payload, $resource, $resource_id, $webhook_id ) { $s = codbox_get_settings(); if ( 'order' !== $resource || empty( $s['webhook_ids'] ) || ! in_array( (int) $webhook_id, array_map( 'intval', (array) $s['webhook_ids'] ), true ) || empty( $payload['line_items'] ) ) { return $payload; } $order = wc_get_order( $resource_id ); if ( ! $order ) { return $payload; } $items = $order->get_items(); foreach ( $payload['line_items'] as $k => $li ) { $id = isset( $li['id'] ) ? (int) $li['id'] : 0; $payload['line_items'][ $k ]['codbox_cost'] = isset( $items[ $id ] ) ? codbox_item_cost( $items[ $id ] ) : null; } return $payload; }, 10, 4 ); /* ---------------- blacklist: no cash on delivery for these buyers ---------------- */ function codbox_rest_blacklist( WP_REST_Request $request ) { $d = codbox_verify_request( $request ); if ( $d instanceof WP_REST_Response ) { return $d; } $phones = array_values( array_unique( array_filter( array_map( 'codbox_norm_phone', (array) ( $d['phones'] ?? array() ) ) ) ) ); $emails = array_values( array_unique( array_filter( array_map( 'codbox_norm_email', (array) ( $d['emails'] ?? array() ) ) ) ) ); update_option( 'codbox_blacklist', array( 'phones' => array_slice( $phones, 0, 5000 ), 'emails' => array_slice( $emails, 0, 5000 ) ), false ); return new WP_REST_Response( array( 'ok' => true, 'n' => count( $phones ) + count( $emails ) ), 200 ); } function codbox_norm_phone( $p ) { $d = preg_replace( '/\D/', '', (string) $p ); return strlen( $d ) >= 6 ? substr( $d, -9 ) : ''; } function codbox_norm_email( $e ) { return strtolower( trim( (string) $e ) ); } function codbox_is_blacklisted( $phone, $email ) { $bl = get_option( 'codbox_blacklist', array() ); if ( empty( $bl['phones'] ) && empty( $bl['emails'] ) ) { return false; } $p = codbox_norm_phone( $phone ); $e = codbox_norm_email( $email ); return ( $p && in_array( $p, (array) ( $bl['phones'] ?? array() ), true ) ) || ( $e && in_array( $e, (array) ( $bl['emails'] ?? array() ), true ) ); } function codbox_blocked_message() { $s = codbox_get_settings(); if ( ! empty( $s['bl_message'] ) ) { return $s['bl_message']; } return 0 === strpos( get_locale(), 'sr' ) || 0 === strpos( get_locale(), 'bs' ) || 0 === strpos( get_locale(), 'hr' ) ? 'Plaćanje pouzećem nije dostupno za ovu porudžbinu. Izaberite drugi način plaćanja.' : __( 'Cash on delivery is not available for this order. Please choose another payment method.', 'codbox' ); } // Classic checkout: hide the COD option while the buyer types their phone and email. add_filter( 'woocommerce_available_payment_gateways', function ( $gateways ) { if ( is_admin() && ! wp_doing_ajax() ) { return $gateways; } if ( ! isset( $gateways['cod'] ) || ! function_exists( 'WC' ) || ! WC()->customer ) { return $gateways; } $phone = WC()->customer->get_billing_phone(); $email = WC()->customer->get_billing_email(); if ( isset( $_POST['post_data'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification -- read-only, WooCommerce checks the checkout nonce. parse_str( sanitize_text_field( wp_unslash( $_POST['post_data'] ) ), $pd ); // phpcs:ignore WordPress.Security.NonceVerification $phone = isset( $pd['billing_phone'] ) ? sanitize_text_field( (string) $pd['billing_phone'] ) : $phone; $email = isset( $pd['billing_email'] ) ? sanitize_email( (string) $pd['billing_email'] ) : $email; } elseif ( isset( $_POST['billing_phone'] ) || isset( $_POST['billing_email'] ) ) { // phpcs:ignore $phone = sanitize_text_field( wp_unslash( $_POST['billing_phone'] ?? '' ) ); // phpcs:ignore $email = sanitize_text_field( wp_unslash( $_POST['billing_email'] ?? '' ) ); // phpcs:ignore } if ( codbox_is_blacklisted( $phone, $email ) ) { unset( $gateways['cod'] ); } return $gateways; } ); // Classic checkout: final check when the order is placed. add_action( 'woocommerce_after_checkout_validation', function ( $data, $errors ) { if ( 'cod' === ( $data['payment_method'] ?? '' ) && codbox_is_blacklisted( $data['billing_phone'] ?? '', $data['billing_email'] ?? '' ) ) { $errors->add( 'codbox_cod_blocked', codbox_blocked_message() ); } }, 10, 2 ); // Block checkout (Store API): stop the order before payment. add_action( 'woocommerce_store_api_checkout_update_order_from_request', function ( $order, $request ) { if ( 'cod' !== (string) $request['payment_method'] ) { return; } if ( codbox_is_blacklisted( $order->get_billing_phone(), $order->get_billing_email() ) && class_exists( '\Automattic\WooCommerce\StoreApi\Exceptions\RouteException' ) ) { throw new \Automattic\WooCommerce\StoreApi\Exceptions\RouteException( 'codbox_cod_blocked', codbox_blocked_message(), 400 ); // phpcs:ignore WordPress.Security.EscapeOutput } }, 10, 2 ); /* ---------------- tracking for the buyer: email and My account ---------------- */ function codbox_is_local() { $l = get_locale(); foreach ( array( 'sr', 'bs', 'hr', 'cnr', 'me' ) as $p ) { if ( 0 === strpos( $l, $p ) ) { return true; } } return false; } function codbox_tracking_text( $key ) { $local = array( 'title' => 'Vaša pošiljka', 'courier' => 'Kurir', 'number' => 'Broj pošiljke', 'track' => 'Prati pošiljku', 'enter' => 'Na stranici kurira unesite broj pošiljke.', ); $en = array( 'title' => __( 'Your shipment', 'codbox' ), 'courier' => __( 'Courier', 'codbox' ), 'number' => __( 'Tracking number', 'codbox' ), 'track' => __( 'Track your parcel', 'codbox' ), 'enter' => __( 'Enter the tracking number on the courier page.', 'codbox' ), ); return codbox_is_local() ? $local[ $key ] : $en[ $key ]; } function codbox_tracking_data( $order ) { if ( ! $order instanceof WC_Order ) { return null; } $s = codbox_get_settings(); if ( isset( $s['show_tracking'] ) && ! $s['show_tracking'] ) { return null; } $tracking = (string) $order->get_meta( '_codbox_tracking' ); if ( '' === $tracking || ! in_array( $order->get_meta( '_codbox_phase' ), array( 'shipped', 'delivered' ), true ) ) { return null; } $url = (string) $order->get_meta( '_codbox_track_url' ); return array( 'courier' => (string) $order->get_meta( '_codbox_courier' ), 'tracking' => $tracking, 'url' => $url, 'has_num' => $url && false !== strpos( $url, rawurlencode( $tracking ) ), ); } add_action( 'woocommerce_email_before_order_table', function ( $order, $sent_to_admin, $plain_text = false ) { if ( $sent_to_admin ) { return; } $t = codbox_tracking_data( $order ); if ( ! $t ) { return; } if ( $plain_text ) { echo "\n" . esc_html( codbox_tracking_text( 'title' ) ) . "\n"; if ( $t['courier'] ) { echo esc_html( codbox_tracking_text( 'courier' ) ) . ': ' . esc_html( $t['courier'] ) . "\n"; } echo esc_html( codbox_tracking_text( 'number' ) ) . ': ' . esc_html( $t['tracking'] ) . "\n"; if ( $t['url'] ) { echo esc_html( codbox_tracking_text( 'track' ) ) . ': ' . esc_url( $t['url'] ) . "\n"; } echo "\n"; return; } echo '
';
if ( $t['courier'] ) {
echo esc_html( codbox_tracking_text( 'courier' ) ) . ': ' . esc_html( $t['courier'] ) . '
';
}
echo esc_html( codbox_tracking_text( 'number' ) ) . ': ' . esc_html( $t['tracking'] ) . '
' . esc_html( codbox_tracking_text( 'track' ) ) . '
'; if ( ! $t['has_num'] ) { echo '' . esc_html( codbox_tracking_text( 'enter' ) ) . '
'; } } echo '';
if ( $t['courier'] ) {
echo esc_html( codbox_tracking_text( 'courier' ) ) . ': ' . esc_html( $t['courier'] ) . '
';
}
echo esc_html( codbox_tracking_text( 'number' ) ) . ': ' . esc_html( $t['tracking'] ) . '
CODbox: ' . esc_html( codbox_phase_label( $order->get_meta( '_codbox_phase' ) ) ) . '
' . esc_html( $courier ) . ' · ' . esc_html( $order->get_meta( '_codbox_tracking' ) ) . ( $url ? ' · ' . esc_html__( 'Track', 'codbox' ) . '' : '' ) . ( $najava ? '
' . esc_html__( 'Pre-advice:', 'codbox' ) . ' ' . esc_html( $najava ) : '' ) . '