1

I'm trying to uncheck Billing and Shipping Address are the same but for only one payment method and leave all the other with this option selected but I'm unable to do it with this solution bellow. The bellow solution will uncheck all boxes for all payment methods and I want to uncheck just one. Does anyone have an idea on how to do that?

Copy the following file to your theme:

vendor/magento/module-checkout/view/frontend/web/js/model/checkout-data-resolver.js

applyBillingAddress: function () {
    var shippingAddress;

    if (quote.billingAddress()) {
        selectBillingAddress(quote.billingAddress());

        return;
    }
    shippingAddress = quote.shippingAddress();

    if (shippingAddress &&
        shippingAddress.canUseForBilling() &&
        (shippingAddress.isDefaultShipping() || !quote.isVirtual())
    ) {
        if(quote.shippingMethod()['method_code']=='store pick_up code'){
           //uncheck here
        }else{
           //check here
           selectBillingAddress(quote.shippingAddress());
        }
    }
}

And also copy the following file to your theme:

vendor/magento/module-checkout/view/frontend/web/js/model/shipping-save-processor/default.js

saveShippingInformation: function () {
    var payload;

    if (!quote.billingAddress()) {
        if(quote.shippingMethod()['method_code']=='store pick_up code'){
           //uncheck here
        }else{
           //check here
           selectBillingAddress(quote.shippingAddress());
        }
    }

    payload = {
        addressInformation: {
            'shipping_address': quote.shippingAddress(),
            'billing_address': quote.billingAddress(),
            'shipping_method_code': quote.shippingMethod()['method_code'],
            'shipping_carrier_code': quote.shippingMethod()['carrier_code']
        }
    };

    payloadExtender(payload);

    fullScreenLoader.startLoader();

    return storage.post(
        resourceUrlManager.getUrlForSetShippingInformation(quote),
        JSON.stringify(payload)
    ).done(
        function (response) {
            quote.setTotals(response.totals);
            paymentService.setPaymentMethods(methodConverter(response['payment_methods']));
            fullScreenLoader.stopLoader();
        }
    ).fail(
        function (response) {
            errorProcessor.process(response);
            fullScreenLoader.stopLoader();
        }
    );
}

Don't forget to run static-content:deploy and cache flush.

Your Answer

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

Browse other questions tagged or ask your own question.