当购物车计算总数时,我拼命地想要删除一个动作。
这是我的代码:
remove_action('woocommerce_cart_calculate_fees', array('WCS_Cart_Renewal', 'remove_non_recurring_fees'), 1000);当最初的操作钩子发生在WooCommerce订阅插件上时:
// Remove non-recurring fees from renewal carts. Hooked in late (priority 1000), to ensure we handle all fees added by third-parties.
add_action( 'woocommerce_cart_calculate_fees', array( $this, 'remove_non_recurring_fees' ), 1000 );不幸的是,我无法删除remove_non_recurring_fees钩式函数。
知道为什么吗?
发布于 2020-10-19 06:57:55
当您查看
WCS_Cart_RenewalClass andremove_non_recurring_fees()function时,您将看到该函数首先删除所有费用,并在涉及订阅时重新添加经常性费用。该函数的优先级为1000。
您没有尝试删除触发此函数的操作钩子,而是有两个其他选项:
1)。关于您通过主题的functions.php 文件:添加的自定义费用
您只需使用更大的优先级,如下例所示:
add_action( 'woocommerce_cart_calculate_fees', 'my_custom_fee', 2000 );
function my_custom_fee( $cart ) {
// Your code
}2)。或者更好地使用可用的过滤器钩子:
此筛选器钩子允许重新添加在此简单代码行中没有重复出现的所有所需费用:
add_filter( 'woocommerce_subscriptions_is_recurring_fee', '__return_true' );代码位于活动子主题(或活动主题)的functions.php文件中。测试和工作。
https://stackoverflow.com/questions/64421604
复制相似问题