解除挂钩remove_non_recurring_fees()WooCommerce订阅功能

时间:2020-10-19 05:27:04

标签: php wordpress woocommerce hook-woocommerce woocommerce-subscriptions

我正拼命试图在购物车计算总数时删除一个动作。

这是我的代码:

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挂钩函数。

知道为什么吗?

1 个答案:

答案 0 :(得分:1)

当您查看WCS_Cart_Renewal Class and remove_non_recurring_fees() function时,您会看到此功能会在涉及订阅的情况下先删除所有费用,然后仅重新添加经常性费用。挂钩此功能的优先级为1000。

除了尝试删除触发该功能的动作挂钩之外,您还有2个其他选择:

1)。对于您通过主题的functions.php文件添加的自定义费用:

您将不得不使用更高的优先级,例如以下示例:

add_action( 'woocommerce_cart_calculate_fees', 'my_custom_fee', 2000 );
function my_custom_fee( $cart ) {
     // Your code
}

2)。或者最好使用woocommerce_subscriptions_is_recurring_fee可用的过滤器挂钩:

此过滤器挂钩允许重新添加所有不需要的费用,而这些费用并非通过以下简单代码行出现:

add_filter( 'woocommerce_subscriptions_is_recurring_fee', '__return_true' );

代码进入活动子主题(或活动主题)的functions.php文件中。经过测试,可以正常工作。