5
votes

I would like to ask how to add a custom fee to the woocommerce subscription recurring total?

Found this on the web:

function woo_add_cart_fee() {
  global $woocommerce;
  $woocommerce->cart->add_fee( __('Custom', 'woocommerce'), 5 );
}

add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );

However that certain function is just for the regular product. NOT SUBSCRIPTION — it doesn't add the fee to the recurring totals.

2

2 Answers

0
votes

As of right now, WooCommerce subscriptions doesn't support adding fees to recurring totals.

0
votes

This may be too late to be of any use to you, but you might find this useful: https://docs.woocommerce.com/document/subscriptions/develop/recurring-cart-fees/

I believe this example would be relevant to your question:

In some cases, you may require the fee to only apply to the on-going recurring payment for any subscriptions. To achieve this, you need to ... add a condition to check whether the cart being passed into your callback is a recurring cart, or the standard WooCommerce cart.

Recurring carts have a $recurring_cart_key property we can use to determine if the cart is a recurring cart.

add_filter( 'woocommerce_cart_calculate_fees', 'add_recurring_postage_fees', 10, 1 );

function add_recurring_postage_fees( $cart ) {
   // Check to see if the recurring_cart_key is set 
   if ( ! empty( $cart->recurring_cart_key ) ) {
       $cart->add_fee( 'Postage', 5 );
    }
}