Pregunta

I want to disable the "Place Order" button in certain conditions.
I have tried a lot but not getting exact information.
Give some idea for same

¿Fue útil?

Solución

It wont be as easy to hide "Place Order" button directly because it comes separate with each payment method.

You can override individual payment method module's form.html (e.g. for Braintree : vendor/magento/module-braintree/view/frontend/web/template/payment/form.html) file but in this case also there are N no of payments you will have to do for all.

Hence, I would recommend to go through following steps:

  1. Create a button same as "Place Order"
  2. Hide default "Place Order" by CSS
  3. Trigger default "Place Order" on the click of your custom "Place Order" button
  4. You can apply any condition on your custom "Place Order" button

Have a look at this link in order to achieve above :

https://zanetabaran.com/how-to-in-magento-2-how-to-move-checkout-buttons-to-order-summary-only-on-desktop/amp/

Otros consejos

You can create a js file and include it on checkout page with following code.

define(['jquery'], function($) {
    $(document).on('change', 'input[name="payment[method]"]', function() {
        if(!your_condition)
        {
            $('button.checkout').attr('disabled', 'disabled');
        }
    });
});

This should work.

Override the below template in your theme

vendor/magento/module-braintree/view/frontend/web/template/payment/form.html

After that update code from line no 139 to 149 with given below code

<button class="action primary checkout"
        type="submit"
        data-bind="
            click: placeOrderClick,
            attr: {title: $t('Place Order')},
            css: {disabled: !isPlaceOrderActionAllowed()},
            enable: isActive()
        "
        disabled>
    <span data-bind="i18n: 'Place Order'"></span>
</button>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top