4

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)?

Fiodor
  • 796
  • 2
  • 7
  • 18

4 Answers4

2

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.

2

You can also do this by removing the woocommerce 'action'. Add this code to your functions.php file:

function stknat01_woocommerce_checkout_t_c_link() {
  remove_action( 'woocommerce_checkout_terms_and_conditions', 'wc_terms_and_conditions_page_content', 30 );
}
add_action( 'wp', 'stknat01_woocommerce_checkout_t_c_link' )
Nat
  • 621
  • 1
  • 6
  • 17
1

WooCommerce uses jQuery, so you can use jQuery's off API to remove the event binding, and then assign your own event listener.

Important: The key to making this work is that your script MUST load / run after WooCommerce's script, otherwise the event won't be there to turn "off". If Woo's script runs after yours, it'll bind the event and yours won't remove it. I've demonstrated one method below, but you might need to use others (such as using a setTimeout):

// no-conflict-safe document ready shorthand
jQuery(function($) {
    // wait until everything completely loaded all assets
    $(window).on('load', (function() {
        // remove the click event, and add your own to redirect
        $( document.body )
            .off( 'click', 'a.woocommerce-terms-and-conditions-link' )
            .on( 'click', location.href='your_full_url_here');
    });
});

Next, I anticipate you asking how to open the PDF in a new tab - for answers to that, see this question.

random_user_name
  • 25,694
  • 7
  • 76
  • 115
1

I followed this instructions for the removing inline toggle display of "Terms and conditions". It does not work until following code it is removed from checkout.min.js.

.slideToggle(),!1}},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}};

After removing this line from checkout.min.js my checkout.js is also changed, here it is:

//remove toggle
 /*
 var wc_terms_toggle = {
  init: function() {
   $( document.body ).on( 'click', 'a.woocommerce-terms-and-conditions-link', this.toggle_terms );
  },

  toggle_terms: function() {
   if ( $( '.woocommerce-terms-and-conditions' ).length ) {
    $( '.woocommerce-terms-and-conditions' ).slideToggle();
    return false;
   }
  }
 };

 */
 
  
  // no-conflict-safe document ready shorthand
jQuery(function($) {
    // wait until everything completely loaded all assets
    $(window).on('load', (function() {
        // remove the click event, and add your own to redirect
        $( document.body )
            .off( 'click', 'a.woocommerce-terms-and-conditions-link' );
            .on( 'click', location.href='https://yoursite.whatever');
    });
});

 
 wc_checkout_form.init();
 wc_checkout_coupons.init();
 wc_checkout_login_form.init();
 
 //wc_terms_toggle.init();
});

Thank you for the script.

jmatesic
  • 13
  • 2