Prijava
Registracija
Or
/* * Plugin Name:DPD Slovenia Integration * Description: This plugin creates an order in the EasyShip DPD system automatically when creating an order in woocommerce. * Author: Dmitriy Macherko * Version: 1.0.0 * Author URI: https://vk.com/mecker_pry */ add_action('woocommerce_thankyou', 'wdm_send_order_to_ext'); function wdm_send_order_to_ext ( $order_id ){ // get order object and order details $order = new WC_Order( $order_id ); $email = $order->get_billing_email(); $phone = $order->get_billing_phone(); $shipping_type = $order->get_shipping_method(); $shipping_cost = $order->get_total_shipping(); $order_id = $order->get_id(); $order = wc_get_order( $order_id ); $order_data = $order->get_data(); // The Order data ## Creation and modified WC_DateTime Object date string ## $order_billing_first_name = $order_data['billing']['first_name']; $order_billing_address_1 = $order_data['billing']['address_1']; $order_billing_city = $order_data['billing']['city']; $order_billing_postcode = $order_data['billing']['postcode']; $order_billing_country = $order_data['billing']['country']; $order_billing_address_2 = str_replace(' ', '%20', $order_billing_address_1); ## SHIPPING INFORMATION: $order_shipping_first_name = $order_data['shipping']['first_name']; $order_shipping_address_1 = $order_data['shipping']['address_1']; $order_shipping_city = $order_data['shipping']['city']; $order_shipping_postcode = $order_data['shipping']['postcode']; $order_shipping_country = $order_data['shipping']['country']; $order_shipping_address_2 = str_replace(' ', '%20', $order_shipping_address_1); // set the username and password $api_username = 'tblcdoo'; $api_password = 'GreenGrows123'; $first_name = $order_shipping_first_name; $address_1 = $order_shipping_address_2; $city = $order_shipping_city; $postcode = $order_shipping_postcode; $country = $order_shipping_country; if (empty($order_shipping_first_name)) { $first_name = $order_billing_first_name; } if (empty($order_shipping_address_2)) { $address_1 = $order_billing_address_2; } if (empty($order_shipping_city)) { $city = $order_billing_city; } if (empty($order_shipping_postcode)) { $postcode = $order_billing_postcode; } if (empty($order_shipping_country)) { $country = $order_billing_country; } $chosen_methods = WC()->session->get( 'chosen_shipping_methods' ); if ( 'flat_rate:2' === $chosen_methods[0] ) { $url = 'https://easyship.si/api/parcel/parcel_import?username='.$api_username.'&password='.$api_password.'&name1='.$first_name.'&street='.$address_1.'&city='.$city.'&country='.$country.'&pcode='.$postcode.'&email='.$email.'&phone='.$phone.'&remark=&weight=4.0&order_number='.$order_id.'&parcel_type=D&num_of_parcel=1&predict=1'; $result = file_get_contents($url, false, stream_context_create(array( "http" => array( "method" => "POST", "header" => "Content-type: application/x-www-form-urlencoded", ) ))); } } ?>
Or