Ad
Remove Checkout Terms & Conditions Conditionally In WooCommerce
I want to remove the Woocommerce Privacy Policy text and the terms & conditions during checkout if there are no available payment gateways.
This is the code that I tried
add_action('woocommerce_checkout_terms_and_conditions', 'disable_woocommerce_checkout_options', 10 );
function disable_woocommerce_checkout_options(){
if ( empty( $available_gateways ) ) {
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 );
}
}
This is removing Privacy policy and Terms & conditions completely even when there is an available payment gateway.
Ad
Answer
The variable $available_gateways
is not defined and woocommerce_checkout_init
is the correct hook to be used. Try the following:
add_action('woocommerce_checkout_init', 'disable_checkout_terms_and_conditions', 10 );
function disable_checkout_terms_and_conditions(){
// Get available payment gateways
$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
if ( empty( $available_gateways ) ) {
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 );
}
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
Related: Remove some hooked functions based on virtual products in WooCommerce Checkout
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad