Add surcharge to extra fields options

When you add an extra field with select or toggleButtonGroup type, you can add a surcharge to their options — the cart total will be increased when an option is chosen.

Extra field attributes for a surcharge

FieldTypeDescription
surchargeTypestringThis attribute allows setting surcharge as a fixed sum to the cart total or a percentage sum depending on the cart total. Accepts ABSOLUTE and PERCENT values.
surchargeShortName<surchargeShortName>Surcharge name in the cart details section (where subtotal, discount, total, etc values are shown). If this attribute is not specified, the default !Surcharge.default_text! name will be shown on the cart details section
options → surchargenumberSurcharge attribute can be specified in each object inside options array. If the extra field surchargeType is ABSOLUTE, Ecwid will add a fixed sum to the order total specified in the surcharge attribute. If the extra field surchargeType is PERCENT, Ecwid will calculate the sum for a surcharge based on the order total and percentage value specified in the surcharge attribute.
showZeroSurchargeInTotalbooleanIf not specified, the default value is true. If true, the surcharge name and its 0 value will be shown on the cart details section (if the surcharge attribute is set to 0 or not specified inside the options array). If false, 0 surcharge name and its value won't be shown on the cart details section.
surchargeTaxablebooleanDefines if taxes should be applied to the surcharge.

surchargeShortName

FieldTypeDescription
namestringSurcharge's names shown on the cart details section
showSurchargePercentValuebooleanApplicable to the extra fields with the PERCENT surchargeType. If true, the surcharge percentage value (e.g. 50%) will be shown next to the name in the cart details. If false, nothing will be shown
nameTranslatedobjKeeps the translations for the surcharge name on the cart details section. More on translations here: Translate extra fields
window.ec = window.ec || {};
ec.order = ec.order || {};
ec.order.extraFields = ec.order.extraFields || {};

ec.order.extraFields.tips = {
    'title': 'Tips',
    'type': 'toggleButtonGroup',
    'options': [
    { 
      'title': 'No tips',
    },
    {
      'title': '5%',
      'subtitle': 'Tip 5% from your order total',  
      'surcharge': 5
    },
    {
      'title': '10%',
      'subtitle': 'Tip 10% from your order total',
      'surcharge': 10
    }
  ],
  'surchargeType': 'PERCENT',
  'surchargeShortName': {
    'name': 'Tips',
    'showSurchargePercentValue': true,
    'nameTranslated': {
      'en': 'Tips',
      'ru': 'Чаевые'
    }
  },
  'showZeroSurchargeInTotal' : false,
  'required': true,
  'checkoutDisplaySection': 'payment_details'
};

window.Ecwid && Ecwid.refreshConfig();