3
votes

I'd like to ask how I could disable AJAX at the checkout page (where you enter shipping and billing information) and that instead of using AJAX to update the cart summary based on your location, it would update by doing a natural refresh.

Currently the cart summary would update itself without reloading the page whenever the user switches their location via shipping location. I'd like to remove that AJAX and just have the page reload with the updated information.

I'm not too sure what sort of codes or direction I should be pointing at but I'm ready to provide whatever details necessary. Just let me know! Thank you!!

5
Why are you trying to remove Ajax? Under Woocommerce->Settings->Products->Add to cart there is a section to disable Ajax but it may not be what your looking for.Robert Lee
@Robert Lee I'm trying to remove AJAX because it's overwriting my translations. I've been looking for ways to have the updated content via AJAX become translated each time so instead, I'd rather just remove it and have the page reload with the proper content that's translated each time. Unfortunately, disable AJAX using the method you spoke of only disables the AJAX when adding products to your cart.chdltest

5 Answers

9
votes

All WooCommerce strings are properly localized with wp_localize_script so I would think you could correctly translate them by creating the appropriate .po/.mo file, but I confess to not having a lot of experience with translations. For reference: all available language packs are at Github and you might also want to read the documentation.

Anyway, the checkout scripts are all in checkout.js. Like any script you can dequeue it via wp_dequeue_script() as long as you know the handle.

function so_27023433_disable_checkout_script(){
    wp_dequeue_script( 'wc-checkout' );
}
add_action( 'wp_enqueue_scripts', 'so_27023433_disable_checkout_script' );
3
votes

I had a similar issue, and instead of remove the entire script, i went to see when the event is created, and i found this.

$( document.body ).bind( 'update_checkout', this.update_checkout );

After reading a little, i found that I will not be able to unbind because of the namespace, so i hooked up on the on event and since i can't prevent default i stoped the propagation of the event.

and these solved my problem.

jQuery(document.body).on('update_checkout', function(e){
    //e.preventDefault();
    //e.stopPropagation();
    e.stopImmediatePropagation();
    //console.log(e);
});
0
votes

If you follow the logic of checkout.js source code you will notice that these AJAX actions related to editing the billing|shipping addresses can be safely disabled by changing the checkout form's class name. Yes, I know, it's that simple. So instead of form.checkout make it form.checkout1 where .checkout1 is just an imaginary class name (it doesn't have to be real/existent).

Here is a sample code that might help you understand what's required:

var default_class = 'checkout';
var mask_class = 'checkout1';

// hijack the form's AJAX by changing form's default class name
$('form.'+default_class).addClass(mask_class).removeClass(default_class);

// restore the original class name whenever you want it
$('form.'+mask_class).addClass(default_class).removeClass(mask_class);

Please note that this is a hack which it's not documented. They may however change the checkout form functionality at any time so keep that in mind. I can confirm it works on WC 2.6.14 and probably in earlier versions too.

0
votes

We had a similar problem: loaded checkout scripts at a quote list checkout. The scripts where loaded through another plugin again (WooCommerce Germanized).

Our solution is a more explicit one:

  • Configure a custom field on the page, you don't want the checkout script be loaded.

And than:

add_action('wp_enqueue_scripts', 'myprefix_dequeue_woocommerce_checkout', 10000);

function myprefix_dequeue_woocommerce_checkout() {
  if (get_post_meta(get_the_ID(), 'disable_woocommerce_checkout_scripts')) {
    wp_dequeue_script('wc-checkout');
    wp_dequeue_script('wc-gzd-checkout');
    wp_dequeue_script('wc-gzdp-checkout');
  }
}
-1
votes

One way to not disable checkout.js.

First it is possible that checkout.min.js is loaded instead of checkout.js.

Then comment thoses 2 lines :

update_checkout:function(){
    //b.reset_update_checkout_timer(),
    //b.updateTimer=setTimeout(b.update_checkout_action,"5")
},

Then your checkout page will be ajax free!