Skip to content

Instantly share code, notes, and snippets.

@rynaldos-zz
Last active December 14, 2020 17:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rynaldos-zz/4993f8515580601856d51fccf974f8de to your computer and use it in GitHub Desktop.
Save rynaldos-zz/4993f8515580601856d51fccf974f8de to your computer and use it in GitHub Desktop.
[WooCommerce 3.0+] Disable terms and conditions toggle and force it to open in a new tab
function disable_wc_terms_toggle() {
wp_enqueue_script( 'disable-terms-toggle', '/disable-terms-toggle.js', array( 'wc-checkout', 'jquery' ), null, true );
wp_add_inline_script( 'disable-terms-toggle', "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 );
// This snippet can be used alongside https://gist.github.com/rynaldos/0bee7d84a83c5b52096c747c19d088c0 (custom terms and conditions link)
Copy link

ghost commented Sep 6, 2018

This doesn't work because the script disable-terms-toggle wouldn't be found.

The code which is responsible for this bad behaviour is in /wp-content/plugins/woocommerce/assets/js/frontend/checkout.js respectively checkout.min.js .
This script is enqueue by /wp-content/plugins/woocommerce/includes/class-wc-frontend-scripts.php with the slug wc-checkout.

Of course you could dequeue and enqueue a custom version of this script but then you have to check it everytime an update for woocommerce is made. So this is not a good solution.

But you could also add an inline script for this slug which remove the click event from the "terms and condition" link.

For doing that just copy this snippet into your functions.php

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');

@bjornweb
Copy link

WC 3.4.0 +

Use the following remove_action and WC will default back to opening a tab with the terms and conditions page.

add_action( 'wp', 'my_project_wc_change_hooks' );
function my_project_wc_change_hooks() {
  remove_action( 'woocommerce_checkout_terms_and_conditions', 'wc_checkout_privacy_policy_text', 20 );
  remove_action( 'woocommerce_checkout_terms_and_conditions', 'wc_terms_and_conditions_page_content', 30 );
}

@Frithir
Copy link

Frithir commented Jan 24, 2019

Prefect @bjornweb just what I needed :)

@ECWireless
Copy link

@bjornweb what folder do you put this function in?

@damadorPL
Copy link

@bjornweb what folder do you put this function in?

usually functions php - best in child theme :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment