woocommerce_model = new A2WL_Woocommerce(); } } public function install() { $user = wp_get_current_user(); $page = "edit-shop_order"; $hidden = array("billing_address"); update_user_option($user->ID, "manage{$page}columnshidden", $hidden, true); } function add_bulk_order_sunc_button() { if (isset($_GET['post_type']) && $_GET['post_type'] == "shop_order") : $fulfilled_order_count = $this->woocommerce_model->get_fulfilled_orders_count(); if ($fulfilled_order_count > 0) : ?>
$this->woocommerce_model->get_fulfilled_orders_data())); restore_error_handler(); } catch (Exception $e) { $result = A2WL_ResultBuilder::buildError($e->getMessage()); } echo json_encode($result); wp_die(); } function ajax_save_tracking_code() { try { $order_id = intval($_POST['id']); $tracking_codes = is_array($_POST['tracking_codes']) ? $_POST['tracking_codes'] : array(strval($_POST['tracking_codes'])); $result = $this->woocommerce_model->save_tracking_code($order_id, $tracking_codes); restore_error_handler(); } catch (Exception $e) { $result = A2WL_ResultBuilder::buildError($e->getMessage()); } echo json_encode($result); wp_die(); } function ajax_order_info() { $result = array("state" => "ok", "data" => ""); $post_id = isset($_POST['id']) ? $_POST['id'] : false; if (!$post_id) { $result['state'] = 'error'; echo json_encode($result); wp_die(); } $content = array(); $order = new WC_Order($post_id); $items = $order->get_items(); $order_external_id_array = get_post_meta($order->get_id(), '_a2wl_external_order_id'); $order_tracking_codes = get_post_meta($order->get_id(), '_a2wl_tracking_code'); $k = 1; foreach ($items as $item) { $normalized_item = new A2WL_WooCommerceOrderItem($item); $product_name = $normalized_item->getName(); $product_id = $normalized_item->getProductID(); $tmp = ''; if ($product_id > 0) { $product_url = get_post_meta($product_id, '_a2wl_product_url', true); $seller_url = get_post_meta($product_id, '_a2wl_seller_url', true); if ($product_url) $tmp = $k . '). ' . _x('Product page', 'hint', 'ali2woo-lite') . ''; if ($seller_url) $tmp .= " | " . _x('Seller', 'hint', 'ali2woo-lite') . ""; } else { $tmp .= $k . '). ' . _x('The product has been deleted', 'hint', 'ali2woo-lite') . ''; } $content[] = $tmp; $k++; } if (!empty($order_external_id_array) && isset($order_external_id_array[0]) && !empty($order_external_id_array[0]) ){ $content[] = "AliExpress order ID(s): " . implode(", ", $order_external_id_array). ""; } if (!empty($order_tracking_codes)) { $content[] = "Tracking number(s): " . (is_array($order_tracking_codes) ? implode(", ", $order_tracking_codes) : strval($order_tracking_codes)) . ""; } $content = apply_filters('a2wl_get_order_content', $content, $post_id); $result['data'] = array('content' => $content, 'id' => $post_id); echo json_encode($result); wp_die(); } function assets() { wp_enqueue_style('a2wl-wc-ol-style', A2WL()->plugin_url() . '/assets/css/wc_ol_style.css', array(), A2WL()->version); wp_enqueue_script('jquery-ui-dialog'); wp_enqueue_script('a2wl-wc-ol-script', A2WL()->plugin_url() . '/assets/js/wc_ol_script.js', array(), A2WL()->version); $lang_data = array( 'aliexpress_info' => _x('AliExpress Info', 'Dialog title', 'ali2woo-lite'), 'please_wait_data_loads' => _x('Please wait, data loads...', 'Status', 'ali2woo-lite'), 'please_wait' => _x('Please wait...', 'Status', 'ali2woo-lite'), 'sync_process' => _x('Sync process', 'Status', 'ali2woo-lite'), 'sync_done' => _x('Sync done!', 'Button text', 'ali2woo-lite'), 'error' => _x('Error!', 'Button text', 'ali2woo-lite'), 'error_please_install_new_extension' => _x('Error! Please install the latest Chrome extension.', 'Error text', 'ali2woo-lite'), 'error_cant_do_tracking_sync' => _x('Can`t do Tracking Sync. Unknown error in the Chrome extension. Please contact with the support.', 'Error text', 'ali2woo-lite'), 'try_again' => _x('Try again?', 'Button text', 'ali2woo-lite'), 'error_didnt_do_find_alix_order_num' => _x('Didn`t find the AliExpress order №', 'Error text', 'ali2woo-lite'), 'error_cant_do_tracking_sync_login_to_account' => _x('Can`t do Tracking Sync. Please log-in to your AliExpress account first.', 'Error text', 'ali2woo-lite'), 'no_tracking_codes_for_order' => _x('No tracking codes for given order on AliExpress.', 'Status', 'ali2woo-lite'), 'tracking_sync' => _x('Tracking Sync All', 'Button text', 'ali2woo-lite'), 'error_403_code' => _x('The error with 403 code occured for the AliExpress order №', 'Error text', 'ali2woo-lite'), 'tracking_sync_done' => _x('The Tracking Sunc has been done!', 'Status', 'ali2woo-lite'), ); wp_localize_script('a2wl-wc-ol-script', 'a2wl_script_data', array('lang' => $lang_data)); } public function manage_columns_data($name) { global $post; switch ($name) { case 'tracking_code': $order_tracking_codes = get_post_meta( $post->ID, '_a2wl_tracking_code'); if ($order_tracking_codes) { foreach ($order_tracking_codes as $k => $tracking_code) { echo $tracking_code; if ($k < count($order_tracking_codes)-1) echo ", "; } } else _e('Not available yet', 'ali2woo-lite'); break; } } public function manage_columns_headers($columns) { $new_columns = array(); foreach ( $columns as $column_name => $column_info ) { $new_columns[ $column_name ] = $column_info; if ( 'order_total' === $column_name ) { $new_columns['tracking_code'] = __( 'Tracking number', 'ali2woo-lite' ); } } return $new_columns; } function admin_order_actions($actions, $object) { $actions['a2wl_order_fulfillment'] = array( 'url' => '#' . $object->get_id(), 'name' => __('Order fulfillment', 'ali2woo-lite'), 'action' => 'a2wl_aliexpress_order_fulfillment', ); $actions['a2wl-order-info'] = array( 'url' => '#' . $object->get_id(), 'name' => __('AliExpress Info', 'ali2woo-lite'), 'action' => 'a2wl-order-info', ); $order_external_id_array = get_post_meta($object->get_id(), '_a2wl_external_order_id'); $order_tracking_codes = get_post_meta($object->get_id(), '_a2wl_tracking_code'); /* if ($order_external_id && (is_null($order_tracking_codes) || empty($order_tracking_codes)))*/ if (!empty($order_external_id_array) && isset($order_external_id_array[0]) && !empty($order_external_id_array[0]) ){ $order_ids_url = implode('-', $order_external_id_array); $actions['a2wl-aliexpress-sync'] = array( 'url' => '#' . $order_ids_url, 'name' => __('Tracking Sync', 'ali2woo-lite'), 'action' => 'a2wl-aliexpress-sync', ); } return $actions; } } endif;