Kargo seçeneklerine teslimat notu ekleme

Kargo seçeneklerinin adına “3–5 iş günü” gibi bir teslimat notu ekleyen, başlığa ve ülkeye göre çalışan Shopify teslimat özelleştirme Function’ı.

Function API
Delivery Customization
Hedef (target)
cart.delivery-options.transform.run
Plan
Herkese açık uygulamada her plan; özel uygulamada Shopify Plus
Uygulama yetkisi
write_delivery_customizations
API sürümü
2026-10
Son kontrol

Kısaca

Bu teslimat özelleştirme Function’ı, ödeme sayfasındaki kargo seçeneklerinin adına “Standart · 3–5 iş günü” gibi kısa bir not ekler. Kurallar seçenek başlığının başıyla eşleşir, isterseniz ülkeyle sınırlanır ve bir JSON metafield’da durur. Delivery Customization API’nin cart.delivery-options.transform.run hedefindeki deliveryOptionRename işlemini kullanır, sürüm 2026-10.

Nasıl kullanılır

  1. Shopify CLI ile bir uygulama oluşturun ve uzantıyı ekleyin: shopify app generate extension --template delivery_customization, dil olarak JavaScript.
  2. Oluşturulan shopify.extension.toml dosyasını ve src/ içindeki iki dosyayı aşağıdakilerle değiştirin.
  3. Testleri çalıştırın: shopify app function run --input tests/notes-added.input.json.
  4. shopify app deploy ile deploy edin ve özelleştirmeyi deliveryCustomizationCreate ile oluşturun.
  5. Kuralları $app:function-configuration metafield’ına yazın; örneğin {"rules": [{"title": "Standart", "note": "3–5 iş günü"}]}.

Kod

shopify.extension.toml
api_version = "2026-10"

[[extensions]]
name = "Add a delivery note to shipping options"
handle = "shipping-option-delivery-note"
type = "function"

  [[extensions.targeting]]
  target = "cart.delivery-options.transform.run"
  input_query = "src/cart_delivery_options_transform_run.graphql"
  export = "cart-delivery-options-transform-run"

  [extensions.build]
  command = ""
  path = "dist/function.wasm"
src/cart_delivery_options_transform_run.graphql
query CartDeliveryOptionsTransformRunInput {
  cart {
    deliveryGroups {
      deliveryAddress {
        countryCode
      }
      deliveryOptions {
        handle
        title
      }
    }
  }
  deliveryCustomization {
    metafield(namespace: "$app", key: "function-configuration") {
      jsonValue
    }
  }
}
src/cart_delivery_options_transform_run.js
// @ts-check

/**
 * @typedef {import("../generated/api").CartDeliveryOptionsTransformRunInput} CartDeliveryOptionsTransformRunInput
 * @typedef {import("../generated/api").CartDeliveryOptionsTransformRunResult} CartDeliveryOptionsTransformRunResult
 */

/**
 * Settings stored as JSON in the customization's metafield, so delivery
 * promises can change (holidays, carrier delays) without a deploy.
 */
const DEFAULT_CONFIG = {
  /**
   * Rules checked in order; the first one whose title matches wins.
   * `title` is matched case-insensitively against the start of the option
   * title; `countries` (optional) limits the rule to delivery addresses there.
   * @type {{title: string, note: string, countries?: string[]}[]}
   */
  rules: [],
  // Placed between the original title and the note.
  separator: " · ",
};

/**
 * @param {CartDeliveryOptionsTransformRunInput} input
 * @returns {CartDeliveryOptionsTransformRunResult}
 */
export function cartDeliveryOptionsTransformRun(input) {
  const config = { ...DEFAULT_CONFIG, ...input.deliveryCustomization?.metafield?.jsonValue };
  const operations = [];

  for (const group of input.cart.deliveryGroups) {
    const country = group.deliveryAddress?.countryCode ?? null;
    for (const option of group.deliveryOptions) {
      const title = option.title ?? "";
      const rule = config.rules.find(
        (r) =>
          title.toLowerCase().startsWith(r.title.toLowerCase()) &&
          (!r.countries?.length || (country !== null && r.countries.some((code) => code.toUpperCase() === country))),
      );
      // Keep the original title in front: Shopify adds the carrier name before
      // it anyway, and customers recognise the rate they saw on the cart page.
      if (rule) {
        operations.push({
          deliveryOptionRename: { deliveryOptionHandle: option.handle, title: `${title}${config.separator}${rule.note}` },
        });
      }
    }
  }

  return { operations };
}
Test girdisi ve beklenen çıktı
tests/country-rule-skipped.input.json
{
  "cart": {
    "deliveryGroups": [
      {
        "deliveryAddress": { "countryCode": "CA" },
        "deliveryOptions": [{ "handle": "77aa-express", "title": "Express" }]
      }
    ]
  },
  "deliveryCustomization": {
    "metafield": {
      "jsonValue": {
        "rules": [
          { "title": "Express", "note": "next business day", "countries": ["US"] },
          { "title": "Standard", "note": "3–5 business days" }
        ]
      }
    }
  }
}
tests/country-rule-skipped.output.json
{ "operations": [] }
tests/not-configured.input.json
{
  "cart": {
    "deliveryGroups": [
      { "deliveryAddress": { "countryCode": "US" }, "deliveryOptions": [{ "handle": "51c2-standard", "title": "Standard" }] }
    ]
  },
  "deliveryCustomization": { "metafield": null }
}
tests/not-configured.output.json
{ "operations": [] }
tests/notes-added.input.json
{
  "cart": {
    "deliveryGroups": [
      {
        "deliveryAddress": { "countryCode": "US" },
        "deliveryOptions": [
          { "handle": "51c2-standard", "title": "Standard" },
          { "handle": "51c2-express", "title": "Express" },
          { "handle": "51c2-pickup", "title": "Pickup in store" }
        ]
      }
    ]
  },
  "deliveryCustomization": {
    "metafield": {
      "jsonValue": {
        "rules": [
          { "title": "Express", "note": "next business day", "countries": ["US"] },
          { "title": "Standard", "note": "3–5 business days" }
        ]
      }
    }
  }
}
tests/notes-added.output.json
{
  "operations": [
    { "deliveryOptionRename": { "deliveryOptionHandle": "51c2-standard", "title": "Standard · 3–5 business days" } },
    { "deliveryOptionRename": { "deliveryOptionHandle": "51c2-express", "title": "Express · next business day" } }
  ]
}

Lintel tarafından yazıldı. MIT lisansı: kendi mağazanızda da müşteri işlerinizde de ücretsiz kullanabilirsiniz.

Sınırlar ve özel durumlar

  • Kargo firması fiyatlarında Shopify, firma adını başlığın önüne ekler ve bu kaldırılamaz; yalnızca sonrasını değiştirebilirsiniz.
  • İlk eşleşen kural geçerli olur; ülkeye özel kuralları genel kuralların önüne koyun.
  • Teslimat süreleri sizin yazdığınız metindir; gerçek kargo süreleriyle karşılaştırılmaz. Bayram ve yoğun dönemlerden önce metafield’ı güncelleyin.

Sık sorulan sorular

Shopify ödeme sayfasında tahmini teslimat süresini nasıl gösteririm?
Bu örnekteki gibi bir teslimat özelleştirme Function’ı, her seçeneğin adını “Standart · 3–5 iş günü” gibi bir teslimat aralığı içerecek şekilde değiştirebilir.
Not ülkeye göre değişebilir mi?
Evet. Kurala bir countries listesi verin, örneğin ["TR"]; kural yalnızca teslimat adresi bu ülkelerden birindeyse uygulanır.
Teslimat mesajını ürün sayfasına da ekleyebilir miyim?
Function yalnızca checkout’u değiştirir. Ürün sayfası için bir tema snippet’ı kullanın; dinamik teslimat mesajı ekleme yazımıza bakabilirsiniz.
  • Function API sürümü 2026-10 için yazıldı ve gösterilen tarihte Shopify’ın başvuru belgeleriyle karşılaştırıldı. Shopify her çeyrekte yeni bir sürüm yayımlar.
  • Function içeren özel (custom) uygulamalar yalnızca Shopify Plus mağazalarında çalışır. Aynı Function herkese açık bir uygulamada, sayfada aksi yazmıyorsa her planda çalışır.
  • Her örnek test verileriyle gelir ve yayımlamadan önce bu testleri çalıştırırız. Kodu değiştirdikten sonra testleri tekrar çalıştırın: shopify app function run.
  • MIT lisansı. Kodu kendi mağazanızda da müşteri işlerinizde de kullanabilirsiniz.

Mağazanız için kurulmasını, test edilmesini ve bakımını isterseniz: Shopify Functions geliştirme.

Geliştirmek istediğiniz bir şey mi var? Gelin, birlikte konuşalım.

Aynı anda sınırlı sayıda proje alıyoruz.

Gencer KarakayaShopify mühendisi

Proje özetinizi bir mühendis okur; size e-postayla yanıt veririz.