# 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’ı.

Sayfa: https://lintelagency.com/tr/kaynaklar/shopify-functions/kargo-seceneklerine-teslimat-notu-ekleme

## 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.

## Bilgiler

- **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:** 2 Kasım 2026

## 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

```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

```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

```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

```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

```json
{ "operations": [] }
```

### tests/not-configured.input.json

```json
{
  "cart": {
    "deliveryGroups": [
      { "deliveryAddress": { "countryCode": "US" }, "deliveryOptions": [{ "handle": "51c2-standard", "title": "Standard" }] }
    ]
  },
  "deliveryCustomization": { "metafield": null }
}
```

### tests/not-configured.output.json

```json
{ "operations": [] }
```

### tests/notes-added.input.json

```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

```json
{
  "operations": [
    { "deliveryOptionRename": { "deliveryOptionHandle": "51c2-standard", "title": "Standard · 3–5 business days" } },
    { "deliveryOptionRename": { "deliveryOptionHandle": "51c2-express", "title": "Express · next business day" } }
  ]
}
```

## 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.

## 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.

## Shopify belgeleri

- [Delivery Customization Function API](https://shopify.dev/docs/api/functions/latest/delivery-customization)

## İlgili içerikler

- [Teslimat, ödeme ya da doğrulama Function’ını etkinleştirme](https://lintelagency.com/tr/kaynaklar/graphql/function-ozellestirmesini-etkinlestirme)
- [Shopify temasına dinamik teslimat mesajı ekleme](https://lintelagency.com/tr/blog/shopify-temasina-dinamik-teslimat-mesaji-ekleme)
- [Teslimat özelleştirme: kargo seçeneklerini gizlemek, yeniden adlandırmak ve sıralamak](https://lintelagency.com/tr/blog/shopify-teslimat-ozellestirme)
- [Ürün etiketine göre kargo seçeneklerini gizleme](https://lintelagency.com/tr/kaynaklar/shopify-functions/urun-etiketine-gore-kargo-seceneklerini-gizleme)

Lisans: MIT. Kendi mağazanızda da müşteri işlerinizde de ücretsiz kullanabilirsiniz.
