'.esc_html($msg).'

'; } add_action('manage_shop_order_posts_custom_column', 'a1post_order_column_old', 99, 2); add_action('woocommerce_shop_order_list_table_custom_column', 'a1post_order_column', 99, 2); add_action('admin_menu', 'a1post_admin_menu'); add_action('add_meta_boxes', 'a1post_ship_order_boxf'); add_action('admin_init', 'a1post_window'); add_action('admin_init', 'a1post_window_print'); add_action('admin_head', 'a1post_css'); add_action('a1post_del_track_but', 'a1post_del_track'); add_filter('manage_woocommerce_page_wc-orders_columns', 'a1post_new_order_column'); add_filter('manage_edit-shop_order_columns', 'a1post_new_order_column'); add_filter('plugin_action_links_' . plugin_basename(__FILE__) , 'a1post_action_links'); add_filter('bulk_actions-woocommerce_page_wc-orders', 'a1post_bulk_action', 20, 1); add_filter('bulk_actions-edit-shop_order', 'a1post_bulk_action', 20, 1); add_filter('handle_bulk_actions-woocommerce_page_wc-orders', 'a1post_bulk_action_handle', 10, 3); add_filter('handle_bulk_actions-edit-shop_order', 'a1post_bulk_action_handle', 10, 3); if (get_option('a1post_u') != '') $user = get_option('a1post_u'); else a1admin_warning('Моля, въведете потребителско име в "A1POST Настройки"'); if (get_option('a1post_p') != '') $pass = get_option('a1post_p'); else a1admin_warning('Моля, въведете парола в "A1POST Настройки"'); if (get_option('a1post_lbl') != '') $lbl_type = get_option('a1post_lbl');else a1admin_warning('Моля, въведете формат на етикета в "A1POST Настройки"'); if (get_option('a1post_st') != '') $ordar_state = get_option('a1post_st'); else $ordar_state = 1; $args = ['headers' => ['Authorization: Basic ' => base64_encode("$user:$pass")]]; function a1post_del_track($actions) { global $pagenow, $typenow; if ($typenow === 'shop_order' && $pagenow === 'edit.php' && isset($_GET['import_courier']) && $_GET['import_courier'] === 'yes') { echo 'del'; } } function a1post_bulk_action($actions) { $actions['a1post_bulk_print'] = 'A1POST Print'; $e = (!empty($_GET['post_type']) && $_GET['post_type'] == 'shop_order') ? 'posts-filter' : 'wc-orders-filter'; echo ''; return $actions; } function a1post_bulk_action_handle($redirect_to, $action, $post_ids) { if ($action !== 'a1post_bulk_print') return $redirect_to; return $redirect_to = add_query_arg(['a1post_batch' => implode(',', $post_ids)], $redirect_to); } function a1post_window_print() { global $args, $user, $pass, $lbl_type; if (isset($_GET['a1post_batch'])) { if (!is_user_logged_in()) exit; $batch = preg_replace('/[^0-9,]/', '', $_GET['a1post_batch']); $orders = explode(',', $batch); foreach ($orders as $order_id) { $order = new WC_Order($order_id); $trk = $order->get_meta('a1post_track', true, 'edit'); if (!empty($trk)) $trks[] = $trk; } $trks = implode(',', $trks); $c = wp_remote_get("https://api.a1post.bg/print.php?track=$trks&lbl=$lbl_type", $args); $http_code = wp_remote_retrieve_response_code($c); if ($http_code == "401") die('Грешно потребителско име/парола!'); $d = json_decode(wp_remote_retrieve_body($c)); if (!empty($d->error)) die(esc_html($d->error->message)); if (!empty($d->lbl)) { header("Content-type:application/pdf"); echo base64_decode($d->lbl); } exit; } } function a1post_window() { global $args, $user, $pass, $lbl_type, $ordar_state; if (isset($_GET['a1post'])) { $nonce = key_exists('_wpnonce', $_GET) ? sanitize_text_field(wp_unslash($_GET['_wpnonce'])) : ''; if (!(wp_verify_nonce($nonce, 'A1P0st-bg')) || !(is_user_logged_in())) exit; $orders = !empty($_GET['o']) ? explode(',', preg_replace('/\D/', '', (int) $_GET['o'])) : ''; $serv = !empty($_GET['serv']) ? sanitize_text_field(wp_unslash($_GET['serv'])) : ''; $print = !empty($_GET['print']) ? sanitize_text_field(wp_unslash($_GET['print'])) : ''; $total_wgh = 0; $notes = ''; foreach ($orders as $order_id) { $order = new WC_Order($order_id); $items = $order->get_items(); $total_qty = $total_weight = 0; foreach ($items as $item) { $p = $item->get_product(); $p_wgh = floatval($p->get_weight()); $qty = floatval($item->get_quantity()); $total_qty += $qty; $total_wgh += floatval($p_wgh * $qty); $notes .= "{$item['name']}. "; } $id = $order->get_id(); if (!empty($order->get_shipping_company())) { $addr1 = $order->get_shipping_company(); $addr2 = $order->get_shipping_address_1(); $addr3 = $order->get_shipping_address_2(); } else { $addr1 = $order->get_shipping_address_1(); $addr2 = $order->get_shipping_address_2(); $addr3 = ''; } $tel = empty($order->get_billing_phone()) ? $order->get_shipping_phone() : $order->get_billing_phone(); $email = empty($order->get_billing_email()) ? $order->get_shipping_email() : $order->get_billing_email(); $data = ['name' => $order->get_shipping_first_name().' '.$order->get_shipping_last_name(), 'addr1' => $addr1, 'addr2' => $addr2, 'addr3' => $addr3, 'city' => $order->get_shipping_city(), 'state' => $order->get_shipping_state(), 'zip' => $order->get_shipping_postcode(), 'iso' => $order->get_shipping_country(), 'tel' => $tel, 'email' => $email, 'notes' => 'WOO- ' . $notes, 'weight' => $total_wgh, 'lbl' => $lbl_type, 'serv' => $serv]; } remove_action('shutdown', 'wp_ob_end_flush_all', 1); if (!empty($print)) $c = wp_remote_get("https://api.a1post.bg/print.php?track=$print&lbl=$lbl_type", $args); else { $args['timeout'] = 15; $args['body'] = $data; $c = wp_remote_post("https://api.a1post.bg", $args); } $http_code = wp_remote_retrieve_response_code($c); if ($http_code == "401") die('Грешно потребителско име/парола!'); $d = json_decode(wp_remote_retrieve_body($c)); if (isset($d->lbl)) { if (empty($print)) { $order->update_meta_data('a1post_track', (string)$d->track); if (!empty($ordar_state)) $order->update_status($ordar_state); } } die(wp_remote_retrieve_body($c)); } } function a1post_new_order_column($columns) { $columns['a1post'] = 'A1POST'; return $columns; } function a1post_admin_menu() { global $a1post_settings_page; $a1post_settings_page = add_submenu_page('woocommerce', 'A1POST Настройки', 'A1POST Настройки', 'manage_woocommerce', 'a1post_admin_settings', 'a1post_admin_settings_page'); } function a1post_admin_settings_page() { if (!current_user_can('manage_woocommerce')) die("You are not authorized to view this page"); $lbl_options = get_option('a1post_lbl'); $st_options = get_option('a1post_st'); if (isset($_POST['a1post_settings_submitted']) && $_POST['a1post_settings_submitted'] == 'submitted') { $nonce = key_exists('_wpnonce', $_POST) ? sanitize_text_field(wp_unslash($_POST['_wpnonce'])) : ''; if (!(wp_verify_nonce($nonce, 'A1P0st-bg')) || !(is_user_logged_in())) exit; foreach ($_POST as $key => $value) { if (get_option($key) != $value) update_option($key, $value); else $status = add_option($key, $value, '', 'no'); } echo '

Промените са записани

'; } ?>

A1POST Настройки

Попълнете всички полета

Формат на етикета

>

>

>

>

Може да използвате 'Custom Order Status Manager for WooCommerce' или друг plug-in, за да създадете статуси по ваш избор.

get_meta('a1post_track', true, 'edit'); echo "".esc_html($trk).""; } } function a1post_order_column($column, $object) { if ($column === 'a1post') { $order = is_a($object, 'WP_Post') ? wc_get_order($object->ID) : $object; $trk = $order->get_meta('a1post_track', true, 'edit'); echo "".esc_html($trk).""; } } function a1post_ship_order_box($object) { global $args; if (is_a($object, 'WP_Post')) { $order = wc_get_order($object->ID); $order_id = $order->get_id(); } else { $order = $object; $order_id = $order->get_order_number(); } $trk = $order->get_meta('a1post_track', true, 'edit'); if (isset($_GET['a1post_del'])) { if (get_option('a1post_u') != '') $user = get_option('a1post_u'); else die('Моля, въведете потребителско име в "A1POST Настройки"'); if (get_option('a1post_p') != '') $pass = get_option('a1post_p'); else die('Моля, въведете парола в "A1POST Настройки"'); if ($_GET['a1post_del'] == $trk) { $args['method'] = 'DELETE'; $args['timeout'] = 15; $args['body'] = "trk=$trk"; $c = wp_remote_post("https://api.a1post.bg", $args); $http_code = wp_remote_retrieve_response_code($c); if ($http_code == "401") die('Грешно потребителско име/парола!'); $d = json_decode(wp_remote_retrieve_body($c)); if (isset($d->error)) die(esc_html($d->error->message)); $order->update_meta_data('a1post_track', ''); $order->update_status('processing'); $trk = ''; } } if (!empty($trk)) echo '

'.esc_html($trk).'

Принтирай етикет


Анулирай текущата и генерирай нова товарителница:

Нова товарителница

'; else echo '

'; } function a1post_css() {echo '';} function a1post_ship_order_boxf() { $screen = class_exists('\Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController') && wc_get_container()->get(CustomOrdersTableController::class)->custom_orders_table_usage_is_enabled() ? wc_get_page_screen_id('shop-order') : 'shop_order'; add_meta_box('woocommerce-shipment-a1post', 'A1POST Генерирай пратка', 'a1post_ship_order_box', $screen, 'side', 'high'); } function a1post_action_links($links) {return $links += ['Настройки', 'A1POST.BG'];} } ?>