I have a custom shipping method and form that collects data on the shipping step. The data comes through fine, but when I go back and checkout again, the data still appears in the order and the order email even if I chose a different method. It is like the data is cached or stored somehow. I have tried to force nothing when it loads using:

$("#myform input[type='text']").val('');

But that doesn't do the trick. When it loads the data isn't in the fields, but the old data is still "stored" and shows up on the other order. It does seem that after 30 minutes or so the data is gone. I submit an order using a different method and it isn't there. But I am not totally sure that is always the case.

How can I make sure that data is gone after checkout is done?


UPDATE web/js/action - Mixin

], function ($) {
    'use strict';

    return function (target) {
        return function (shippingMethod) {
            // call original method

            if(shippingMethod && shippingMethod.carrier_code == 'carrier_code') {
                $("#opc-custom-checkout-form input[type='text']").val('');
            } else {

Form JS

], function(ko, $, urlFormatter, Component, customer, quote, urlBuilder, errorProcessor, cartCache, formData) {
    'use strict';

    return Component.extend({
        customFields: ko.observable(null),
        formData: formData.customFieldsData,

         * Initialize component
         * @returns {exports}
        initialize: function () {
            var self = this;
            formData = this.source.get('customCheckoutForm');
            var formDataCached = cartCache.get('custom-form');
            if (formDataCached) {
                formData = this.source.set('customCheckoutForm', formDataCached);


            return this;

         * Trigger save method if form is change
        onFormChange: function () {

         * Form submit handler
        saveCustomFields: function() {
            this.source.set('params.invalid', false);

            if (!this.source.get('params.invalid')) {
                var formData = this.source.get('customCheckoutForm');
                var quoteId = quote.getQuoteId();
                var isCustomer = customer.isLoggedIn();
                var url;

                if (isCustomer) {
                    url = urlBuilder.createUrl('/carts/mine/set-order-custom-fields', {});
                } else {
                    url = urlBuilder.createUrl('/guest-carts/:cartId/set-order-custom-field', {cartId: quoteId});

                var payload = {
                    cartId: quoteId,
                    customFields: formData
                var result = true;
                    url: urlFormatter.build(url),
                    data: JSON.stringify(payload),
                    global: false,
                    contentType: 'application/json',
                    type: 'PUT',
                    async: true
                    function (response) {
                        cartCache.set('custom-form', formData);
                        result = true;
                    function (response) {
                        result = false;

                return result;


  • Show your code here
    – Sohel Rana
    Aug 29, 2020 at 7:25
  • @SohelRana I added some code above. See if that helps.
    – stanhook
    Aug 31, 2020 at 12:53

1 Answer 1


Totally unknown but you can try the following simple way:

$("#myform input[type='text']").val('').change();
  • I placed this in the mixin after the target(shippingMethod) and it does clear the form. But the problem is that it also clears it when the Next button is clicked so the data is then reset and doesn't pass through. Any way to initialize/reset the form right when the page loads? I have tried jQuery in a bunch of places with no luck. I have a block class that uses ``` public function getCustomFields(Order $order) { return $this->customFieldsRepository->getCustomFields($order); } ``` Maybe something here?
    – stanhook
    Sep 2, 2020 at 19:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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