/* Decoded by unphp.net */
__("Partido", "woocommerce"), "placeholder" => _x("SELECCIONAR PROVINCIA ", "placeholder", "wanderlust-ca"), "required" => false, "clear" => false, "type" => "text", "class" => array("form-row-wide"), "priority" => 80); return $checkout_fields; } add_action("wp_ajax_get_localidades_ca", "get_localidades_ca", 1); add_action("wp_ajax_nopriv_get_localidades_ca", "get_localidades_ca", 1); function get_localidades_ca() { $client_state = $_POST["state"]; if ($client_state == "C") { $client_state = "CAPITAL FEDERAL"; } if ($client_state == "B") { $client_state = "Buenos Aires"; } if ($client_state == "K") { $client_state = "Catamarca"; } if ($client_state == "H") { $client_state = "Chaco"; } if ($client_state == "U") { $client_state = "Chubut"; } if ($client_state == "X") { $client_state = "Cordoba"; } if ($client_state == "W") { $client_state = "Corrientes"; } if ($client_state == "E") { $client_state = "Entre Rios"; } if ($client_state == "P") { $client_state = "Formosa"; } if ($client_state == "Y") { $client_state = "Jujuy"; } if ($client_state == "L") { $client_state = "La Pampa"; } if ($client_state == "F") { $client_state = "La Rioja"; } if ($client_state == "M") { $client_state = "Mendoza"; } if ($client_state == "N") { $client_state = "Misiones"; } if ($client_state == "Q") { $client_state = "Neuquen"; } if ($client_state == "R") { $client_state = "Rio Negro"; } if ($client_state == "A") { $client_state = "Salta"; } if ($client_state == "J") { $client_state = "San Juan"; } if ($client_state == "D") { $client_state = "San Luis"; } if ($client_state == "Z") { $client_state = "Santa Cruz"; } if ($client_state == "S") { $client_state = "Santa Fe"; } if ($client_state == "G") { $client_state = "Santiago del Estero"; } if ($client_state == "V") { $client_state = "Tierra del Fuego"; } if ($client_state == "T") { $client_state = "Tucuman"; } $delivery_zones = WC_Shipping_Zones::get_zones(); foreach ($delivery_zones as $zones) { foreach ($zones["shipping_methods"] as $methods) { if ($methods->id == "correo_argentino") { if ($methods->enabled == "yes") { $api_key = $methods->instance_settings["wanderlust_api"]; } } } } $params = array("method" => array("get_localidad" => array("api_key" => $api_key, "provincia_destino" => $client_state))); $ch = curl_init(); curl_setopt_array($ch, array(CURLOPT_TIMEOUT => 30, CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => http_build_query($params), CURLOPT_URL => "https://wanderlust.codes/apica/", CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_FOLLOWLOCATION => TRUE)); $ca_response = curl_exec($ch); $ca_response = json_decode($ca_response); echo ""; die; } add_action("wp_ajax_check_sucursalesca", "check_sucursalesca", 1); add_action("wp_ajax_nopriv_check_sucursalesca", "check_sucursalesca", 1); function check_sucursalesca() { global $wp_session; $delivery_zones = WC_Shipping_Zones::get_zones(); foreach ($delivery_zones as $zones) { foreach ($zones["shipping_methods"] as $methods) { if ($methods->id == "correo_argentino") { if ($methods->enabled == "yes") { $api_key = $methods->instance_settings["wanderlust_api"]; } } } } if (isset($_POST["localidad"])) { $params = array("method" => array("get_sucursal" => array("api_key" => $api_key, "localidad" => $_POST["localidad"], "provincia_destino" => $_POST["provincia"]))); $ch = curl_init(); curl_setopt_array($ch, array(CURLOPT_TIMEOUT => 30, CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => http_build_query($params), CURLOPT_URL => "https://wanderlust.codes/apica/", CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_FOLLOWLOCATION => TRUE)); $ca_response = curl_exec($ch); $ca_response = json_decode($ca_response); echo ""; die; } else { echo "* Seleccionar un partido"; exit; } } add_action("wp_footer", "only_numbers_cas"); function only_numbers_cas() { if (is_checkout()) { echo " \xd
\xd
\x9"; } } add_action("woocommerce_after_order_notes", "order_sucursal_mainca"); function order_sucursal_mainca($checkout) { global $woocommerce, $wp_session; echo "
" . __("Sucursal Correo Argentino") . "
"; echo "
Si seleccionaste retirar por sucursal, eleg\303\255 tu sucursal en el listado."; echo "
Cargando Sucursales..."; echo "
"; echo "
Cargando Sucursales..."; echo "
"; echo "
"; } add_action("woocommerce_checkout_process", "checkout_field_ca_process"); function checkout_field_ca_process() { global $woocommerce, $wp_session; $chosen_methods = WC()->session->get("chosen_shipping_methods"); $chosen_shipping = $chosen_methods[0]; $wp_session["chosen_shipping"] = $chosen_shipping; if (strpos($chosen_shipping, "-sas") !== false) { if (empty($_POST["pv_centro_ca_estandar"])) { wc_add_notice(__("Por favor, seleccionar sucursal de retiro."), "error"); } } } add_action("woocommerce_checkout_update_order_meta", "order_sucursal_mainca_update_order_meta_ca", 10); function order_sucursal_mainca_update_order_meta_ca($order_id) { global $wp_session; if (!empty($_POST["pv_centro_ca_estandar"])) { update_post_meta($order_id, "_sucursal_pv_centro_ca_estandar", $_POST["pv_centro_ca_estandar"]); update_post_meta($order_id, "sucursal_ca_c", $_POST["pv_centro_ca_estandar"]); } $chosen_shipping = json_encode($wp_session["chosen_shipping"]); update_post_meta($order_id, "_chosen_shipping", $chosen_shipping); } function ca_admin_notice() { global $wp_session; echo "\x9
\xa\x9\x9 \x9\x9
"; print_r($wp_session["ca_notice"]); echo "
\xd\xa \x9
\x9\x9 "; } function wanderlust_ca_exportar_admin() { $my_page = add_submenu_page("woocommerce", "Wanderlust Correo Argentino Exportador", "Exportar a Correo Argentino", "manage_woocommerce", "wanderlust-ca-exportar", "wanderlust_ca_exportar"); add_action("load-" . $my_page, "wanderlust_ca_exportar_js"); } add_action("admin_menu", "wanderlust_ca_exportar_admin"); function wanderlust_ca_exportar_js() { add_action("admin_enqueue_scripts", "wanderlust_ca_exportar_admin_js"); } function wanderlust_ca_exportar_admin_js() { wp_enqueue_script("easypost-label-admin-script", plugins_url("includes/cajs.js", __FILE__), array("jquery")); } function wanderlust_ca_exportar() { if (!current_user_can("manage_woocommerce")) { wp_die(__("You do not have sufficient permissions to access this page.")); } require_once dirname(__FILE__) . "/admin.php"; } add_action("wp_ajax_wanderlust_ca_export", "wanderlust_ca_export"); add_action("wp_ajax_nopriv_wanderlust_ca_export", "wanderlust_ca_export"); function wanderlust_ca_export() { global $wpdb; $post_status = implode("','", array("wc-processing", "wc-completed")); $result = $wpdb->get_results("SELECT * FROM {$wpdb->posts} \xd\xa WHERE post_type = 'shop_order'
\xa AND post_status IN ('{$post_status}')\xd\xa AND post_date BETWEEN '{$_POST["desde"]} 00:00:00' AND '{$_POST["hasta"]} 23:59:59'
"); $pedidos = array(); foreach ($result as $orders) { $order = wc_get_order($orders->ID); $shipping_method = @array_shift($order->get_shipping_methods()); $shipping_method_id = $shipping_method["method_id"]; if ($shipping_method_id == "correo_argentino") { $peso = null; $precio = null; $items = $order->get_items(); foreach ($items as $item) { if ($item["product_id"] > 0) { $product = wc_get_product($item["product_id"]); $peso += $product->get_weight(); $precio += $product->get_price(); } } $calle = preg_replace("/[0-9]+/", '', $order->get_shipping_address_1()); preg_match_all("!\d+!", $order->get_shipping_address_1(), $numero); $unwanted_array = array("\305\240" => "S", "\xc5\xa1" => "s", "\305\275" => "Z", "\305\xbe" => "z", "\303\x80" => "A", "\xc3\201" => "A", "\xc3\x82" => "A", "\303\203" => "A", "\303\204" => "A", "\xc3\205" => "A", "\303\206" => "A", "\xc3\x87" => "C", "\303\x88" => "E", "\303\x89" => "E", "\xc3\212" => "E", "\303\x8b" => "E", "\303\x8c" => "I", "\xc3\215" => "I", "\303\216" => "I", "\303\217" => "I", "\303\221" => "N", "\303\222" => "O", "\303\223" => "O", "\303\x94" => "O", "\xc3\x95" => "O", "\xc3\x96" => "O", "\xc3\x98" => "O", "\303\231" => "U", "\xc3\232" => "U", "\xc3\x9b" => "U", "\303\x9c" => "U", "\xc3\235" => "Y", "\xc3\x9e" => "B", "\303\x9f" => "Ss", "\xc3\240" => "a", "\303\xa1" => "a", "\xc3\242" => "a", "\xc3\243" => "a", "\xc3\xa4" => "a", "\303\245" => "a", "\303\246" => "a", "\xc3\247" => "c", "\xc3\250" => "e", "\303\xa9" => "e", "\xc3\xaa" => "e", "\303\253" => "e", "\303\xac" => "i", "\xc3\xad" => "i", "\303\256" => "i", "\303\xaf" => "i", "\xc3\260" => "o", "\303\261" => "n", "\303\262" => "o", "\xc3\263" => "o", "\xc3\264" => "o", "\xc3\xb5" => "o", "\xc3\266" => "o", "\303\xb8" => "o", "\303\271" => "u", "\303\xba" => "u", "\303\xbb" => "u", "\xc3\xbd" => "y", "\303\276" => "b", "\303\277" => "y", "\xc2\xb0" => '', "\302\xba" => ''); $ciudad = strtr($order->get_shipping_city(), $unwanted_array); $destino_nombre = strtr($order->get_shipping_first_name() . " " . $order->get_shipping_last_name(), $unwanted_array); $piso = strtr($order->get_shipping_address_2(), $unwanted_array); $phone = $order->get_billing_phone(); $phone = preg_replace("/[^0-9.]+/", '', $phone); $sucursal_ca_c = get_post_meta($orders->ID, "sucursal_ca_c", true); if ($sucursal_ca_c) { $pedidos[] = array("tipo_producto" => "CP", "largo" => "70", "ancho" => "70", "altura" => "70", "peso" => $peso, "valor_del_contenido" => $precio, "provincia_destino" => $order->get_shipping_state(), "sucursal_destino" => $sucursal_ca_c, "localidad_destino" => " ", "calle_destino" => " ", "altura_destino" => " ", "piso" => " ", "dpto" => " ", "codpostal_destino" => " ", "destino_nombre" => $destino_nombre, "destino_email" => $order->get_billing_email(), "cod_area_tel" => "054", "tel" => $phone, "cod_area_cel" => " ", "cel" => " "); } else { $pedidos[] = array("tipo_producto" => "CP", "largo" => "70", "ancho" => "70", "altura" => "70", "peso" => $peso, "valor_del_contenido" => $precio, "provincia_destino" => $order->get_shipping_state(), "sucursal_destino" => " ", "localidad_destino" => $ciudad, "calle_destino" => $calle, "altura_destino" => $numero[0][0], "piso" => $piso, "dpto" => " ", "codpostal_destino" => $order->get_shipping_postcode(), "destino_nombre" => $destino_nombre, "destino_email" => $order->get_billing_email(), "cod_area_tel" => "054", "tel" => $phone, "cod_area_cel" => " ", "cel" => " "); } } } if (!empty($pedidos)) { $delivery_zones = WC_Shipping_Zones::get_zones(); foreach ($delivery_zones as $zones) { foreach ($zones["shipping_methods"] as $methods) { if ($methods->id == "correo_argentino") { if ($methods->enabled == "yes") { $api_key = $methods->instance_settings["wanderlust_api"]; } } } } $params = array("method" => array("generar_csv" => array("api_key" => $api_key, "pedidos" => json_encode($pedidos)))); $ch = curl_init(); curl_setopt_array($ch, array(CURLOPT_TIMEOUT => 30, CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => http_build_query($params), CURLOPT_URL => "https://wanderlust.codes/apica/", CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_FOLLOWLOCATION => TRUE)); $ca_response = curl_exec($ch); $ca_response = base64_decode($ca_response); $save_path = CA_EXPORTADOR_WANDERLUST_PATH . "csv/"; $save_url = CA_EXPORTADOR_WANDERLUST_DIR . "csv/"; $file_handle = fopen($save_path . "correo_argentino.csv", "w"); fwrite($file_handle, $ca_response); fclose($file_handle); $archivo_cbte = plugins_url("/csv/correo_argentino.csv", __FILE__); echo "DESCARGAR"; } else { echo "NO SE ENCONTRARON RESULTADOS"; } die; }
?>