0

I want to remove Coupon code from Discount title on order summary from the Checkout page. please refer screenshot.

nto2

i have checked console:

    <tr class="totals discount">
        <th class="mark" scope="row">
            **<span class="title" data-bind="text: getTitle()">Discount (test5)</span>**
            <span class="discount coupon" data-bind="text: getCouponCode()">test5</span>
        </th>
        <td class="amount">
            <span class="price" data-bind="text: getValue(), attr: {'data-th': name}" data-th="checkout.sidebar.summary.totals.discount">-$8.56</span>
        </td>
    </tr>

di.xml

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
        <type name="Magento\SalesRule\Model\RulesApllier">
            <plugin name="vendor_onestepcheckout_salesrule" type="Vendor\Onepagecheckout\Model\RulesApllierPlugin" sortOrder="1"/>
        </type>
    </config>



    <?php
    namespace Vendor\Onepagecheckout\Model;

    class RulesApllierPlugin
    {
            public function afterAddDiscountDescription(
            \Magento\SalesRule\Model\RulesApplier $rulesApplier,
            callable $proceed,
            \Magento\Quote\Model\Quote\Address $address,
            \Magento\SalesRule\Model\Rule $rule
        ) {
            $description = $address->getDiscountDescriptionArray();
            $ruleLabel = $rule->getStoreLabel($address->getQuote()->getStore());
            $label = '';
            if ($ruleLabel) {
                $label = $ruleLabel;
            }
            //in original method, there was a piece of code here that added the coupon code to the discount
            if (strlen($label)) {
                $description[$rule->getId()] = $label;
            }
            $address->setDiscountDescriptionArray($description);
            return $rulesApplier;
        }

    }
2

Create an around plugin on the method Magento\SalesRule\Model\RulesApllier::addDiscountDescription. That's the one that adds the coupon code to the discount title. Make it look like this:

public function aroundAddDiscountDescription(
    \Magento\SalesRule\Model\RulesApplier $rulesApplier,
    callable $proceed,
    \Magento\Quote\Model\Quote\Address $address,
    \Magento\SalesRule\Model\Rule $rule
) {
    $description = $address->getDiscountDescriptionArray();
    $ruleLabel = $rule->getStoreLabel($address->getQuote()->getStore());
    $label = '';
    if ($ruleLabel) {
        $label = $ruleLabel;
    }
    //in original method, there was a piece of code here that added the coupon code to the discount

    if (strlen($label)) {
        $description[$rule->getId()] = $label;
    }
    $address->setDiscountDescriptionArray($description);
    return $rulesApplier;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.