Unhook remove_non_recurring_fees() WooCommerce Subscriptions function

139 Views Asked by At

I'm desperately trying to remove an action while the cart calculates the total.

Here is my code:

remove_action('woocommerce_cart_calculate_fees', array('WCS_Cart_Renewal', 'remove_non_recurring_fees'), 1000);

While the original action hook is taking place on the WooCommerce Subscriptions plugin:

// 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 );

Unfortunately I could not remove the remove_non_recurring_fees hooked function.

Any idea why?

1

There are 1 best solutions below

0
On BEST ANSWER

When you Look at WCS_Cart_Renewal Class and remove_non_recurring_fees() function, you will see that this function removes all fees first and re-add only recurring fees, when a subscription is involved. This function is hooked with a priority of 1000.

Instead of trying to remove the action hook that trigger this function, you have 2 other choices:

1). For custom fees added by you via your theme's functions.php file:

You will have just to use a greater priority like in this following example:

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

2). Or better using woocommerce_subscriptions_is_recurring_fee available filter hook:

This filter hook that allows to re-add all desired fees that are not recurring with this simple code line:

add_filter( 'woocommerce_subscriptions_is_recurring_fee', '__return_true' );

Code goes in functions.php file of the active child theme (or active theme). Tested and works.