=== ParcelKit for CDEK ===
Contributors: cdekmsk
Tags: cdek, woocommerce shipping, shipping calculator, pickup points, delivery
Requires at least: 5.8
Tested up to: 7.1
Requires PHP: 7.0
Stable tag: 0.3.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

CDEK delivery calculator and pickup point map for any page, plus CDEK rates, pickup points, shipments and labels for WooCommerce.

== Description ==

For Russian-speaking sites and shops that ship with CDEK. Two parts, use one or both.

**Widgets for any page** — no keys, no WooCommerce needed:

* **Delivery cost calculator** — visitors pick the cities, weight and size and see every CDEK rate with price and delivery time. Rates are live, not a price list.
* **Pickup point map** — all CDEK pickup points and parcel lockers of a city on a map, with addresses, opening hours and a list next to the map.

They are meant for "Delivery" and "Contacts" pages, blogs and landing pages where a visitor wants to know how much and how long the delivery will take, or where the nearest pickup point is.

**CDEK delivery at WooCommerce checkout** — with your own CDEK API keys:

* Up to three options in the cart and at checkout: to a pickup point, to the door, to a parcel locker. Each shows one CDEK rate — the cheapest or the fastest — with its delivery time.
* The customer chooses the pickup point or parcel locker from a searchable list right under the delivery options. The point is saved in the order and shown in the order screen, emails and the "Thank you" page.
* Works with both the block checkout and the classic `[woocommerce_checkout]` shortcode, and with HPOS order storage.
* Markup as an amount or a percentage, free delivery from an order amount, rounding, extra days for packing, preferred CDEK rate codes.
* One parcel per order: the total weight, and a box no smaller than the largest product and the total volume. Default weight and size for products without them.
* Prices in rubles, tenge, Belarusian rubles, dollars or euros — whichever your store uses.
* Test mode with the public CDEK test account, to see everything before signing a contract.
* **Shipments in CDEK from the order screen.** One click creates the CDEK shipment with the rate, pickup point, recipient and products from the order — with cash on delivery if the customer chose to pay on delivery. Then print the waybill and the parcel label, see the CDEK number with a tracking link and the status, or delete the shipment. To send many orders at once, select them in the orders list and choose "Create CDEK shipments"; "Print CDEK waybills" and "Print CDEK labels" give one PDF for all selected orders. The orders list shows the CDEK number and status of each order.

Prices come from CDEK under your contract. Shipments are created in CDEK only when you click the button in an order.

Add a widget with a shortcode:

`[sdekcalc_calculator]`

`[sdekcalc_map]`

A shortcode builder in **Settings → CDEK Calculator** lets you preset the sender city, hide the weight fields, show only pickup points or only parcel lockers, and copy the ready shortcode. The same page sets the theme (light, dark or the visitor's system setting) and the accent color for all widgets.

This plugin is made by the team of сдэккалькулятор.рф and is not affiliated with or endorsed by CDEK.

== External services ==

The widgets are web pages of the сдэккалькулятор.рф service shown in an iframe. The WooCommerce delivery part connects your site to the CDEK API directly. The plugin does not send any data anywhere else.

**сдэккалькулятор.рф** (https://xn--80ahsabfbysbsk9ij2b.xn--p1ai/)

* What it does: shows the calculator and the map, calculates rates and returns the list of pickup points. Rates and pickup points are taken by the service from the CDEK API.
* What is sent and when: the widget page is loaded when a visitor scrolls to the widget. The visitor's browser then sends the cities, weight and parcel size the visitor enters. Once a day per browser the widget reports the domain of the site it is opened on (domain only, without the page address) so that the service knows where the widget is used. As with any web page, the server receives the visitor's IP address and browser user agent.
* In the WordPress admin: when an administrator types a city in the shortcode builder, the typed text is sent from your server to the service to suggest city names.
* Terms of use: https://xn--80ahsabfbysbsk9ij2b.xn--p1ai/vidzhet.html
* Privacy policy: https://xn--80ahsabfbysbsk9ij2b.xn--p1ai/policy.html

**CDEK API** (WooCommerce delivery only, when you enter API keys or turn on test mode)

* What it does: finds the customer's city, calculates rates and returns the list of pickup points; when you click a button in an order, creates, prints or deletes the CDEK shipment.
* What is sent and when: your API keys, to get an access token. When a customer's cart or checkout needs delivery rates: the sender city, the customer's country, city and postcode, the parcel weight and size. When the customer picks a delivery option that needs a pickup point: the city code. Nothing is sent before you set up the method. At checkout, names, phone numbers, emails and street addresses of customers are not sent.
* Shipments: only when a store manager clicks "Create a CDEK shipment" in an order or applies "Create CDEK shipments" to orders selected in the orders list, the plugin sends the order number, the recipient's name, phone, email and delivery address or pickup point, the customer's order note, the products (name, SKU, price, weight, quantity), the parcel weight and size, cash on delivery amounts and the sender details from the plugin settings. Printing, refreshing the status and deleting send only the CDEK shipment ID.
* Servers: https://api.cdek.ru (live) and https://api.edu.cdek.ru (test mode).
* Terms of use: https://www.cdek.ru/ru/integration/
* Privacy policy: https://www.cdek.ru/ru/privacy_policy/

**Yandex Maps API** (pickup point map only)

* The map inside the widget is drawn with the Yandex Maps JavaScript API, loaded by the widget page in the visitor's browser.
* Terms of use: https://yandex.ru/legal/maps_api/
* Privacy policy: https://yandex.ru/legal/confidential/

== Installation ==

1. Install the plugin from the Plugins screen or upload the `parcelkit-for-cdek` folder to `/wp-content/plugins/`.
2. Activate it.
3. Open **Settings → CDEK Calculator**, build a shortcode and paste it into a page, a post or a Shortcode block.

For delivery at checkout:

1. Open **WooCommerce → Settings → Shipping → CDEK**, enter the API keys from your CDEK account (Integration section) or turn on test mode, choose the sender city and save. The page tells you right away whether CDEK accepted the keys.
2. Add the **CDEK** method to a shipping zone and choose which options to show.
3. To create shipments from orders, fill in the "Shipments in CDEK" section on the CDEK settings page: the office where you bring parcels, or the pickup address for a courier.

== Frequently Asked Questions ==

= Do I need a CDEK contract or API keys? =

Not for the widgets: they work without any keys. If you have a contract, the calculator can show the contract-only "Parcel" rate; you can hide it in the builder.

Delivery at WooCommerce checkout needs API keys, and CDEK gives them to customers with a contract. Until then you can try it in test mode — test prices are not real.

= Why does a customer see no CDEK options? =

The customer's city is not filled in yet, CDEK does not deliver there, or the keys or sender city are not set. Check **WooCommerce → Status → Logs** (source "parcelkit-for-cdek") for errors from CDEK.

= Does it create shipments in CDEK or print labels? =

Yes, from the order screen. The CDEK box there creates the shipment, prints the waybill (two copies: for you and for the parcel) and the parcel label (A4 or A6, set in the CDEK settings), refreshes the status and deletes the shipment while CDEK has not received it yet.

To create shipments for many orders, select them in the orders list and choose "Create CDEK shipments" in the bulk actions (up to 30 orders at once). Orders already in CDEK and orders without CDEK delivery are skipped; the list shows what was created and why an order was not. "Print CDEK waybills" and "Print CDEK labels" download one PDF for all selected orders that have a CDEK number (up to 100 at once). The CDEK column in the orders list shows the number with a tracking link and the last known status.

The plugin does not call a courier: if a CDEK courier picks parcels up, request the pickup in your CDEK account.

= I already use another CDEK plugin for checkout =

Then you don't need this part: just don't add the CDEK method from this plugin to your shipping zones. The widgets work alongside any checkout plugin.

= Will the widget slow my site down? =

The widget is an iframe with lazy loading: the browser loads it only when a visitor scrolls to it. It does not touch your scripts or styles.

= The calculator shows its own scroll bar =

The plugin includes a small script that resizes the iframe to its content. If a caching or optimization plugin removes footer scripts, set the height manually: `[sdekcalc_calculator height="900"]`.

= Is a link to your site required? =

No. A small link under the widget is off by default. You can turn it on in the settings if you want to support the project.

= Does it work with page builders? =

Yes, anywhere a shortcode works: the block editor (Shortcode block), the classic editor, Elementor's Shortcode widget and text widgets.

== Screenshots ==

1. The delivery cost calculator on a store page: every CDEK rate with its price and delivery time.
2. The pickup point map: CDEK pickup points and parcel lockers of a city with addresses and opening hours.
3. Block checkout: CDEK options with the delivery time and the pickup point choice.
4. The order screen: the CDEK box creates the shipment in CDEK, with cash on delivery for orders paid on delivery.
5. CDEK settings in WooCommerce: API keys, test mode and where you ship from.
6. The shortcode builder and the settings for all widgets.

== Changelog ==

= 0.3.0 =
* New: CDEK shipments from the order screen — create the shipment (cash on delivery for orders paid on delivery), print the waybill and the parcel label, see the CDEK number, tracking link and status, delete the shipment.
* New: "Create CDEK shipments", "Print CDEK waybills" and "Print CDEK labels" bulk actions in the orders list, and a CDEK column with the shipment number and status.
* New: "Shipments in CDEK" settings — drop-off office, courier pickup address, sender contact, label size.
* Fix: the service fields of the CDEK shipping line are no longer listed on the order screen.

= 0.2.1 =
* New: a "No contract with CDEK?" box and a test mode warning on the plugin's settings pages, with a link to sign a contract.
* Fix: CDEK service rates (fulfilment issue, cargo pickup) no longer reach the checkout. Within a city the fulfilment rate was shown as the cheapest one, although a regular store cannot ship with it.

= 0.2.0 =
* New: CDEK delivery method for WooCommerce shipping zones — rates to a pickup point, to the door and to a parcel locker with your own CDEK API keys.
* New: pickup point and parcel locker choice at checkout (block and classic checkout), saved in the order.
* New: test mode with the public CDEK test account.

= 0.1.0 =
* First release: calculator and pickup point map shortcodes, shortcode builder, theme and accent settings.
