Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Woocommerce disable script opening terms inline

On the checkout page in Woocommerce there is an "I accept terms and conditions" checkbox. The "terms and conditions" is a link, but Woocommerce captures the click event on the link, and instead opens a small popup(?) with the Terms and conditions page.

I would like to disable the script, and have it be just a normal link.

I identified the js code which captures this event. Unfortunately it's a part of checkout.min.js which controls other parts of the checkout experience too, so I would like to keep the rest of the script intact.

i = {
        init: function() {
            e(document.body).on("click", "a.woocommerce-terms-and-conditions-link", this.toggle_terms)
        },
        toggle_terms: function() {
            if (e(".woocommerce-terms-and-conditions").length)
                return e(".woocommerce-terms-and-conditions").slideToggle(), !1
        }
    };
i.init()

Bonus question, can I change the link to point to an arbitrary url (a pdf in this case)?

like image 357
Fiodor Avatar asked Sep 08 '25 10:09

Fiodor


1 Answers

cale_b is right.

But because the link already has target="_blank" there is no need for add a new click handler. To archieve that your custom javascript code is load / run after WooCommerce's script you can use wp_add_inline_script.

I use this snippet and it works:

function disable_wc_terms_toggle() {
    wp_add_inline_script( 'wc-checkout', "jQuery( document ).ready( function() { jQuery( document.body ).off( 'click', 'a.woocommerce-terms-and-conditions-link' ); } );" );
}

add_action( 'wp_enqueue_scripts', 'disable_wc_terms_toggle', 1000 );

Add this to your theme's functions.php and your done.

like image 186
Alexander Behling Avatar answered Sep 11 '25 03:09

Alexander Behling