Last active
December 14, 2020 17:37
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
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 );
}
Prefect @bjornweb just what I needed :)
@bjornweb what folder do you put this function in?
@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
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