Hidden extra fields with surcharges

You might need to add a surcharge to the order without showing an extra field at checkout (e.g. you'd like to add a surcharge when a certain shipping method is chosen). In this case, you can initiate a hidden extra field with surcharges.

Hidden extra fields with surcharges require 4 attributes: value, surchargeShortName, options, surchargeType. You can find these attributes description here: Extra field attributes for a surcharge

// Initialize extra fields
window.ec = window.ec || {};
ec.order = ec.order || {};
ec.order.extraFields = ec.order.extraFields || {};
// Set order surcharge
ec.order.extraFields.surcharge = {
    'value': 'Custom charge',
    "options": [
    { 
        "title": "Custom charge",
        "surcharge": 5
    },
    ],
    "surchargeShortName": {
        "name": "Surcharge",
         "showSurchargePercentValue": false
    },
    'surchargeType': 'PERCENT'
}
window.Ecwid && Ecwid.refreshConfig();

Example hidden extra field won't be shown at checkout but will add 5% surcharge to the order subtotal.

Dynamically change or remove the surcharge

In case, you'd like to change or remove the surcharge in some circumstances (e.g. shipping method is changed), you can redefine the surcharge extra field value. When you want to remove the surcharge and not to show 0 surcharge value in the order total table, add showZeroSurchargeInTotal attribute to the surcharge extra field.

// Change order surcharge
ec.order.extraFields.surcharge = {
    'value': 'Custom charge',
    "options": [
    { 
        "title": "Custom charge",
        "surcharge": 10
    },
    ],
    "surchargeShortName": {
        "name": "Surcharge",
         "showSurchargePercentValue": false
    },
    'surchargeType': 'PERCENT',
}
Ecwid.refreshConfig && Ecwid.refreshConfig();
ec.order.extraFields.surcharge = {
    'value': 'Custom charge',
    "options": [
    { 
        "title": "Custom charge",
        "surcharge": 0
    },
    ],
    "surchargeShortName": {
        "name": "Surcharge",
         "showSurchargePercentValue": false
    },
    'surchargeType': 'PERCENT',
    'showZeroSurchargeInTotal': false // hides 0 surcharge from the order total table
}
Ecwid.refreshConfig()