skip to Main Content

I am testing fees with WooCommerce Subscriptions and have noticed a missing feature that support is unable to help with.

When adding a ‘recurring fee’ to the checkout using their sample code (below), the plugin does not add the subscription interval after the fee price.

Example:

Actual: FEE: £5.00

Expected: FEE: £5.00 / month

I first came across this problem by trying to add a fee using WooCommerce Extra Product Options by Themecomplete, however, I’ve noticed even using the code below from the WooCommerce plugin developer guide, it does not work for any recurring fees.

add_filter( 'woocommerce_cart_calculate_fees', 'add_recurring_postage_fees', 10, 1 );
function add_recurring_postage_fees( $cart ) {
if ( ! empty( $cart->recurring_cart_key ) ) {
    $cart->add_fee( 'Postage', 5 );
}
}

I can see within WooCommerce Subscriptions (file: recurring-totals.php) that the plugin recognises the recurring fee:

<?php foreach ( $recurring_cart->get_fees() as $recurring_fee ) : ?>
    <tr class="fee recurring-total">
        <th><?php echo esc_html( $recurring_fee->name ); ?></th>
        <td><?php wc_cart_totals_fee_html( $recurring_fee ); ?></td>
    </tr>
<?php endforeach; ?>

Developer Guide: https://docs.woocommerce.com/document/subscriptions/develop/recurring-cart-fees/

As can be seen in their screenshot, the words ‘/ month’ is missing from the fee in their example: Recurring Fees Image >

It needs to be dynamic based on the subscription interval, not just a predetermined phrase. Does anyone have knowledge of WooCommerce Subscriptions and Fee’s to be able to identify the problem?

2

Answers


  1. Chosen as BEST ANSWER

    Rather than set a fee, I'm looking for something that works with fees from any source such as other plugins. Something that replaces the recurring fee price string would work better... (I know this doesn't work, just an idea):

    add_filter( 'woocommerce_cart_totals_fee_html', 'sab_custom_fee_interval' );
    function sab_custom_fee_interval( $price ) {
    return $price . $cart->recurring_cart_key;
    }
    

    But I do not know how $cart->recurring_cart_key works within the subscriptions plugin. Still playing around with this...


  2. add_filter( 'woocommerce_subscriptions_is_recurring_fee', '__return_true' );
    
    add_filter( 'woocommerce_cart_calculate_fees', 'add_recurring_postage_fees', 10, 1 );
    
    function add_recurring_postage_fees( $cart ) {
    
        if ( !empty( $cart->recurring_cart_key ) ) {
    
            $intervals = explode( '_', $cart->recurring_cart_key );
            $cart->add_fee( 'Postage/' . end( $intervals ), 5, false, '' );
        }
    }
    

    enter image description here

    Try this as a possible solution.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search