How-to library · Developer docs

How-to library

Task-shaped pages: a title that starts with a verb, the situation in a few lines, the steps, the working code in both engines, and why this way rather than another. Found from a search, done, and left.

How-to Commerce

Sell digital products, gift cards and services without shipping

A shipping category and a method with Nothing to ship: its free rate is chosen for the shopper, the order is marked delivered as soon as it is paid, and with inventory tracking on the products hold no stock.

Context

Context. A store sells e-books, gift cards or workshop places, on their own or beside goods it posts. Nothing goes in a parcel, but every order still gets a fulfilment, and a checkout needs a selected shipping rate on it before it can be paid. A shipping method with Nothing to ship switched on covers these products: its free rate is chosen for the shopper, the fulfilment is marked delivered as soon as the order is paid, and with inventory tracking on the products need no stock.

Before you start

Access to Transactions › Shipping in the admin, a shipping group for the method, and a development site with a test checkout you can create shipping on (Creating shipping and showing the rates).

Steps

  1. Under Transactions › Shipping › Shipping Categories, add a category Digital.
  2. On each digital product, set Shipping Category, in its Shipping section, to Digital. Its variants use the product's.
  3. Under Transactions › Shipping › Shipping Methods, add a method of type Template: Name Digital delivery, Active on, a Group, Shipping Categories Digital, and the template below as its Template code. Under Fulfillment, switch Nothing to ship on, and save.
  4. Leave Digital off the methods that send parcels.
  5. On the test checkout, with a digital product in it, create shipping as for any order (below). The fulfilment that holds the digital product has one rate, Digital delivery, already in selectedShippingRate, and nothingToShip is true.
  6. Pay for it on the development site and open the order in the admin: its fulfilment shows as Digital delivery, Delivered digitally.

Code

The method's Template code:

Template code Shipping method "Digital delivery": Template code
{$rates->create('0', 'Digital delivery', 'digital')}
{{ rates.create('0', 'Digital delivery', 'digital') }}

Creating shipping on the test checkout, asking only for what step 5 checks:

HTTP
POST /cdna-api/checkout/<id>/shipping/simple-delivery?properties={ fulfillments { id, nothingToShip, selectedShippingRate { name, total }, shippingRates { name, total } } }
Content-Type: application/json

{"countryName": "Australia", "addressLine1": "1 Collins Street", "postcode": "3000"}

Why this and not that

  • The rate is chosen for the shopper. When the only rate for a fulfilment comes from a method with Nothing to ship, it is selected as shipping is created, so the checkout is ready for payment without a shipping choice for those items. A fulfilment that another method also rates waits for the shopper's choice, as usual.
  • Delivered on payment. As the order is created, a fulfilment whose selected rate has Nothing to ship is marked delivered. It gets no packing slip or shipments, and no email is sent: send the download link or gift card code from a job on the order (Customer emails).
  • Why Digital stays off the parcel methods. With inventory tracking on, a product whose shipping methods all have Nothing to ship holds no stock and is not checked for it, and its items get a fulfilment of their own, without a warehouse, beside the parcel's. A category that a parcel method also carries holds stock like any other, because the shopper may choose that method, and a cart of digital items alone could then get the parcel method's rates as well.
  • With inventory tracking off, a checkout keeps all its items in one fulfilment, and a method rates it only when it carries every item's category. A cart that mixes digital and posted products is then rated by the methods that carry both categories. For click and collect, a method serves a pickup only from the warehouses it lists, so list the pickup warehouses on Digital delivery too.
  • A method that already has orders. Switching Nothing to ship on for a method with open fulfilments offers to complete them as well; saving with that box ticked marks them delivered in the background.
Go deeper

Was this page helpful?

Your answer goes to the docs team.