Override the template located in:
vendor/magento/module-sales-rule/view/frontend/web/template/payment/discount.html
Change line 7 from:
<div class="payment-option _collapsible opc-payment-additional discount-code"
data-bind="mageInit: {'collapsible':{'openedState': '_active'}}">
To:
<div class="payment-option _collapsible opc-payment-additional discount-code _active">
Line 9 from:
<div class="payment-option-title field choice" data-role="title">
To:
<div class="payment-option-title field choice" data-role="title" aria-selected="true" aria-expanded="true">
Line 14 from:
<div class="payment-option-content" data-role="content">
To:
<div class="payment-option-content" data-role="content" style="display: block" aria-hidden="false">
This makes the Apply Discount Code
section expanded by default.
To override the template, add the following to your requirejs-config.js:
var config = {
map: {
'*': {
'Magento_SalesRule/template/payment/discount.html':
'Vendor_Module/template/payment/discount.html'
}
}
};
If you don't have a requirejs-config, create one in app/code/Vendor/Module/view/frontend/requirejs-config.js.
Create the template in: app/code/Vendor/Module/view/frontend/web/template/payment/discount.html
The entire template (in Magento 2.4) would look like this:
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<div class="payment-option _collapsible opc-payment-additional discount-code _active">
<div class="payment-option-title field choice" data-role="title" aria-selected="true" aria-expanded="true">
<span class="action action-toggle" id="block-discount-heading" role="heading" aria-level="2">
<!-- ko i18n: 'Apply Discount Code'--><!-- /ko -->
</span>
</div>
<div class="payment-option-content" data-role="content" style="display: block" aria-hidden="false">
<!-- ko foreach: getRegion('messages') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
<form class="form form-discount" id="discount-form">
<div class="payment-option-inner">
<div class="field">
<label class="label" for="discount-code">
<span data-bind="i18n: 'Enter discount code'"></span>
</label>
<div class="control">
<input class="input-text"
type="text"
id="discount-code"
name="discount_code"
data-validate="{'required-entry':true}"
data-bind="value: couponCode, attr:{disabled:isApplied() , placeholder: $t('Enter discount code')} " />
</div>
</div>
</div>
<div class="actions-toolbar">
<div class="primary">
<!-- ko ifnot: isApplied() -->
<button class="action action-apply" type="submit" data-bind="'value': $t('Apply Discount'), click: apply">
<span><!-- ko i18n: 'Apply Discount'--><!-- /ko --></span>
</button>
<!-- /ko -->
<!-- ko if: isApplied() -->
<button class="action action-cancel" type="submit" data-bind="'value': $t('Cancel'), click: cancel">
<span><!-- ko i18n: 'Cancel coupon'--><!-- /ko --></span>
</button>
<!-- /ko -->
</div>
</div>
<!-- ko foreach: getRegion('captcha') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!-- /ko -->
</form>
</div>
</div>