[英]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.如果没有可用的支付网关,我想在结帐期间删除 Woocommerce 隐私政策文本和条款和条件。
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.即使有可用的支付网关,这也会完全删除隐私政策和条款和条件。
The variable $available_gateways
is not defined and woocommerce_checkout_init
is the correct hook to be used.变量
$available_gateways
未定义, woocommerce_checkout_init
是要使用的正确挂钩。 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).代码位于活动子主题(或活动主题)的 function.php 文件中。 Tested and works.
测试和工作。
Related: Remove some hooked functions based on virtual products in WooCommerce Checkout相关: 在 WooCommerce Checkout 中删除一些基于虚拟产品的挂钩功能
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.