1

I want a pop-up to show with a message after the user clicks PROCEED TO CHECKOUT.

So the process goes like:

  1. User clicks PROCEED TO CHECKOUT
  2. Pop-up shows with the message with AGREE or DISAGREE buttons
  3. If DISAGREEd, close pop-up, and do not do anything, stays in the same page
  4. If AGREEd, redirect to checkout

PS: I do not need this information to go through backend somewhere, because this message has to be agreed to by all customers, no exception, so I will assume that if the order is placed, then the customer agreed to this message.

PS 2: I know I could place this message in html body, but for our business, this condition is so important I want to create a popup for it.

I'm using Magento 2.2.5 with PHP 7.1

Where should I start?

0

Copy file from vendor directory

vendor/magento/module-checkout/view/frontend/web/js/view/payment/default.js

to your custom created theme

app/design/frontend/[vendor]/[theme]/Magento_Checkout/web/js/view/payment/default.js

Now, search for find placeOrder: function (data, event) and edit this function as given below

if(confirm("Are you sure to place order?") == true){
    //default function code
}else{
    return false;
}

For example:

placeOrder: function (data, event) {

    if(confirm("Are you sure to place order?") == true){
        var self = this;

        if (event) {
            event.preventDefault();
        }

        if (this.validate() && additionalValidators.validate()) {
            this.isPlaceOrderActionAllowed(false);

            this.getPlaceOrderDeferredObject()
                .fail(
                    function () {
                        self.isPlaceOrderActionAllowed(true);
                    }
                ).done(
                    function () {
                        self.afterPlaceOrder();

                        if (self.redirectAfterPlaceOrder) {
                            redirectOnSuccessAction.execute();
                        }
                    }
                );

            return true;
        }

        return false;
    }else{
        return false;
    }
},

After compltion run php bin/magento setup:static-content:deploy -f command.

|improve this answer|||||
  • Awesome! Thank you for your answer! Will try this tomorrow and will make sure to comeback here to upvote if it works – RA828 Jan 27 at 20:27

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.