Woocommerce: how to disable AJAX for coupon application / removal?

In my woocommerce based store I have combined the cart and checkout pages in one, it works well but there is a problem when I try to remove the coupon. The coupon is deleting from the cart with AJAX handling, so when the deletion is complete - the page does not reload and the coupon still shows as applied (but in fact it is deleted). So I need to disable AJAX to apply / remove the coupon function.

I tried to add this code to my theme's functions.php:

function disable_checkout_script(){
wp_dequeue_script( 'wc-checkout' );
}
add_action( 'wp_enqueue_scripts', 'disable_checkout_script' );

      

It solves my problem, but this code disables ALL AJAX on the checkout page, and I would like to disable ajax only for applying / removing the coupon and keep other ajax handling like checking billing / shipping fields.

Please help, unfortunately I'm not a JS expert. Hello!

+3


source to share


1 answer


In your JS file, you need to remove a couple of event handlers. There, when clicking the delete coupon button, and also when submitting the coupon form, an event occurs.

The corresponding lines are 381 - 383 of woocommerce/assets/js/frontend/checkout.js

(WooCommerce downloads a smaller version of this file).

$( document.body ).on( 'click', 'a.showcoupon', this.show_coupon_form );
$( document.body ).on( 'click', '.woocommerce-remove-coupon', this.remove_coupon );
$( 'form.checkout_coupon' ).hide().submit( this.submit );

      



You need to remove 2 and 3.

Add the following code to your JS file:

$( document.body ).off( 'click', '.woocommerce-remove-coupon', wc_checkout_coupons.remove_coupon );
$( 'form.checkout_coupon' ).off( 'submit' );

      

0


source







All Articles