Create Discount Code


Creates an Easy Digital Downloads discount code for a percentage or a fixed amount off, with optional start and end dates, a limit on uses, once per customer, a minimum order amount and product restrictions. The code works at checkout as soon as it is created (within its dates) unless status "inactive" is passed. Reversible: deactivate or delete it in the Discount Codes screen. Get download IDs from mosmcp/edd-list-downloads.

Also known as: coupon, coupon code, promo code, voucher, sale code.

Property Value
Ability slug mosmcp/edd-create-discount
Wire tool name mosmcp__edd-create-discount
Category Easy Digital Downloads (mosmcp-edd)
Plan Pro

 

Required access

Requirement Value
Capability manage_shop_discounts
Minimum default role Shop Manager (Easy Digital Downloads)
Annotations readOnly: false · destructive: false · idempotent: false · openWorld: false

 

Input schema

Field Type Required Default Description
code string Yes — The code customers type at checkout: letters, numbers, hyphens and underscores, up to 50 characters. Must not already exist.
name string — Optional name shown only in the admin. Defaults to the code.
type string (one of percent, flat) Yes — "percent" for a percentage off, or "flat" for a fixed amount off in the store currency.
amount number (min 0) Yes — How much off: a percentage up to 100 for "percent", or an amount in the store currency for "flat".
status string (one of active, inactive) active "active" (the default) so it works at checkout, or "inactive" to create it switched off.
starts_at string — Optional start, YYYY-MM-DD or YYYY-MM-DD HH:MM in the site's timezone. The code does nothing before then.
expires_at string — Optional expiry, YYYY-MM-DD or YYYY-MM-DD HH:MM in the site's timezone. A date alone means the end of that day.
max_uses integer (min 0) — Optional total number of times the code can be used. 0 or left out means unlimited.
once_per_customer boolean false Whether each customer can use it only once.
min_amount number (min 0) — Optional minimum cart amount, in the store currency, before the code applies.
product_ids integer[] — Optional download IDs the cart must contain for the code to apply.
product_condition string (one of all, any) all With product_ids: "all" (the default) means the cart must contain every one of them, "any" means at least one.
apply_to string (one of cart, products) cart "cart" (the default) takes the discount off the whole purchase; "products" takes it off only the downloads in product_ids.
excluded_product_ids integer[] — Optional download IDs the discount never applies to.

 

Output schema

Field Type Required Description
discount_id integer Yes
code string Yes
name string
status string Yes
type string Yes
amount number Yes
amount_label string The discount as a person would say it, for example "20%" or "$5.00".
starts_at string Start in the site's timezone, or empty for straight away.
expires_at string Expiry in the site's timezone, or empty for never.
max_uses integer
once_per_customer boolean
min_amount number
product_ids integer[]
product_condition string
apply_to string
excluded_product_ids integer[]
edit_url string
notes string[]

 

Example

Sample prompt
Create an EDD discount code BLACKFRIDAY25 for 25% off, valid until 1 December 2026 and limited to 200 uses.

Example request (json)

{
  "jsonrpc": "2.0",
  "id": 623,
  "method": "tools/call",
  "params": {
    "name": "mosmcp__edd-create-discount",
    "arguments": {
      "input": {
        "code": "BLACKFRIDAY25",
        "name": "Black Friday 2026",
        "type": "percent",
        "amount": 25,
        "expires_at": "2026-12-01",
        "max_uses": 200
      }
    }
  }
}

Example response (json)

{
  "jsonrpc": "2.0",
  "id": 623,
  "result": {
    "isError": false,
    "structuredContent": {
      "discount_id": 18,
      "code": "BLACKFRIDAY25",
      "name": "Black Friday 2026",
      "status": "active",
      "type": "percent",
      "amount": 25,
      "amount_label": "25%",
      "starts_at": "",
      "expires_at": "2026-12-01 23:59:59",
      "max_uses": 200,
      "once_per_customer": false,
      "min_amount": 0,
      "product_ids": [],
      "product_condition": "",
      "apply_to": "cart",
      "excluded_product_ids": [],
      "edit_url": "https://example.com/wp-admin/edit.php?post_type=download&page=edd-discounts&view=edit_discount&discount=18",
      "notes": [
        "Customers can use the code at checkout now."
      ]
    }
  }
}

 

Edge cases / errors

  • A code with characters other than letters, numbers, hyphens and underscores, or longer than 50 → mosmcp_edd_discount_code_invalid. A code already in use (letter case ignored) → mosmcp_edd_discount_code_exists, with the existing discount_id.
  • A percentage of 0 or over 100, or a flat amount of 0 → mosmcp_edd_discount_amount_invalid; expires_at already past → mosmcp_edd_discount_already_expired; expires_at not after starts_at → mosmcp_edd_discount_dates_reversed.
  • apply_to "products" without product_ids → mosmcp_edd_discount_products_required; a download in both product_ids and excluded_product_ids → mosmcp_edd_discount_products_conflict.
  • The code works at checkout as soon as it is created unless status is "inactive". An expiry given as a date alone runs to 23:59:59 that day.

 


<< Previous Next >>
Create Download

For more information about the Secure MCP Server for WordPress plugin, explore the following resources:

Product Overview | Pricing | Try for Free | Documentation

If you have any questions regarding plugin configuration, pricing plans or licensing, please contact us or mail us at aisupport@xecurify.com.