$user->ID, 'status'=> array( 'wc-pending', 'wc-processing', 'wc-on-hold', //'wc-ready-shipment', ), "posts_per_page" => -1 ); $orders = wc_get_orders( $args ); //$orders = array_slice( $orders, 0, 1 ); /*echo "
";
	print_r($orders);
	echo "
";*/ return $orders; } function GetOrdersDatev() { global $wpdb; $results = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}posts WHERE post_type LIKE 'shop_order'"); $order_ids = array(); foreach( $results as $result ){ $order_ids[] = $result->ID; } return $order_ids; } function GetOfferBySKU( $sku ) { global $wpdb; $posts = array(); $products_raw = $wpdb->get_results( "SELECT * FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value='$sku' " ); foreach( $products_raw as $item ) { $posts[] = $item->post_id; } return $posts; } function GetFilesFTP( $server, $login, $password, $directory, $destination_directory, $str_search, $str_search_remove=false ) { $uploaded_files = array(); $conn_id = ftp_connect( $server ); $login_result = ftp_login($conn_id, $login, $password); ftp_pasv($conn_id, true); // Get the content of directory $contents = ftp_nlist($conn_id, $directory); foreach( $contents as $key=>$file ) { if( strpos( $file, $str_search ) ) { $local_file = $contents[ $key ]; $destination_directory = $destination_directory.basename($local_file); $uploaded_files[] = $destination_directory; ftp_get($conn_id, $destination_directory, $local_file, FTP_BINARY); } if( $str_search_remove && strpos( $file, $str_search_remove ) ) { ftp_delete($conn_id, $file); } } ftp_close($conn_id); return $uploaded_files; } function GetRemoteAvCode() { $server = 'ftp.hama.de'; $login = 'k0016968'; $password = 'vbvX639E'; $directory = '/out/'; $destination_directory = $_SERVER['DOCUMENT_ROOT'].'/wp-content/uploads/avcode/'; $files = GetFilesFTP( $server, $login, $password, $directory, $destination_directory, 'hama_av_ecom' ); $destination_file = $files[0]; return $destination_file; } function GetRemoteOrders() { $server = DHL_SERVER_HOST; $login = DHL_SERVER_LOGIN; $password = DHL_SERVER_PASSWORD; $directory = DHL_SERVER_FOLDER; $destination_directory = $_SERVER['DOCUMENT_ROOT'].'/wp-content/uploads/edi-orders-processed-archive/'; $files = GetFilesFTP( $server, $login, $password, $directory, $destination_directory, DHL_FILE_SEARCH, 'edi' ); return $files; } function updateProductMinPrice( $product_id ) { $handle= new WC_Product_Variable( $product_id ); $variations = $handle->get_children(); $prices = array(); foreach( $variations as $item_id ) { $prices[] = get_post_meta( $item_id, '_price', true ); } $min_price = min( $prices ); update_post_meta($product_id, '_regular_price', $min_price); update_post_meta($product_id, '_price', $min_price); /*echo $product_id; echo "
"; echo $min_price; die();*/ return true; } function updateProductMinPrices() { $args = array( 'post_type' => 'product', 'posts_per_page' => 1000 ); $query = new WP_Query( $args ); $products = $query->posts; foreach( $products as $item ) { updateProductMinPrice( $item->ID ); } /*echo "
";
	print_r($products);
	echo "
"; die();*/ } function checkTrackDHL( $track_number ) { $headers = array( 'DHL-API-Key:eAJklppZAAbaLKC88GVFnWkXGi9bGVmm', ); $ch = curl_init( 'https://api-eu.dhl.com/track/shipments?trackingNumber='.$track_number ); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HEADER, false); $html = curl_exec($ch); curl_close($ch); $data = json_decode( $html ); return $data->shipments[0]; echo "
";
	print_r( $data );
	echo "
"; } function deactiveOffersNoSKU() { $lines = file_get_contents( GetRemoteAvCode() ); $rows = explode("\n", $lines); array_shift($rows); $skus = []; foreach($rows as $row => $data) { $row_data = explode(';', $data); $skus[] = str_replace('"', '', $row_data[1]); } global $wpdb; $posts = array(); $products_raw = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE `post_type` = 'product_variation' LIMIT 100000000" ); foreach( $products_raw as $item ) { $supplier_code = get_post_meta( $item->ID, '_supplier_code', true ); $sku = get_post_meta( $item->ID, '_sku', true ); if (!in_array($sku, $skus)) { update_post_meta( $item->ID, '_stock', 0 ); } if( !$supplier_code || trim($supplier_code) == '' ) { $posts[] = $item->ID; } } //Disable product variation with empty supplier_code foreach( $posts as $post_id ) { wp_update_post( array( 'ID' => $post_id, 'post_status' => 'private' ) ); } echo "Empty Supplier Codes:
"; echo "
";
	print_r( $posts );
	echo "
"; } // Clear the Sale start date and Sale end date function updateSaleDates() { global $wpdb; $posts = array(); // $products_raw = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE `post_type` = 'product_variation' LIMIT 100000000" ); // foreach( $products_raw as $item ) { // // update_post_meta( $item->ID, '_sale_price_dates_to', '' ); // update_post_meta( $item->ID, '_sale_price_dates_from', '' ); // // } /* echo "Empty Supplier Codes:
"; echo "
";
	print_r( $posts );
	echo "
"; */ } function NotifyEmptySC( $order_id ) { $to = 'matrosov-stanislav@mail.ru, sk@sformer.com, as@blackrock-mobile.com'; //$to = 'matrosov-stanislav@mail.ru'; $subject = 'New order with emptySC'; $order_link = "https://blackrock-mobile.com/wp-admin/post.php?post=".$order_id."&action=edit"; $message .= "We've got a new order with emptySC: #".$order_id.".
"; $message .= "Here is the link: ".$order_link; $headers = array( 'content-type: text/html', ); wp_mail( $to, $subject, $message, $headers, $attachments ); }