• Resolved pcaraway1

    (@pcaraway1)


    We are having a challenge when we do a monthly subscription where we set the subscription to a month. In the “Subtotal” section I can add a code snippet to change the “for month” to “per month” using a WooCommerce name. But, for the Totals portion it will not update the “For month” to “Per month”. The reason we are doing this is for a monthly Subscription model. Grammatically it looks for to show $20 for month. It should show as $20 per month. It would be fine for multiples but, that is not how we are using this. If I set the Subscription for X days it would me that it would very on when it would hit each month. The subtotal works… totals do not work.

    Any suggestion on how I can accomplish this!

    Sincerely,
    Paul

    Here is the code I am using:

    // Replace “for month” and “For month” in cart item subtotals
    add_filter(‘woocommerce_cart_item_subtotal’, ‘update_subtotal_text’, 10, 3);

    function update_subtotal_text($subtotal, $cart_item, $cart_item_key) {
    // Replace “for month” with “per month”
    return str_replace([‘for month’, ‘For month’], [‘per month’, ‘Per month’], $subtotal);
    }

    // Replace “for month” and “For month” in cart totals
    add_filter(‘woocommerce_cart_item_totals’, ‘update_totals_text’, 10, 1);
    //add_filter(‘woocommerce_cart_totals_html’, ‘update_totals_text’, 10, 1);

    function update_totals_text($cart_totals_html) {
    // Replace “for month” with “per month”
    return str_replace([‘for month’, ‘For month’], [‘per month’, ‘Per month’], $cart_totals_html);
    }

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support sebastianrybacki

    (@sebastianrybacki)

    Hello Paul,

    Thank you for reaching out!

    I’ve reviewed your code and made some adjustments to ensure the replacement works for both sections.

    Here is the updated code:

    // Replace "for month" and "For month" in cart item subtotals
    add_filter('woocommerce_cart_item_subtotal', 'update_subtotal_text', 10, 3);
    function update_subtotal_text($subtotal, $cart_item, $cart_item_key) {
    // Replace "for month" with "per month"
    return str_replace(['for month', 'For month'], ['per month', 'Per month'], $subtotal);
    }

    // Replace "for month" and "For month" in cart totals (adjusting totals section)
    add_filter('woocommerce_get_order_item_totals', 'update_totals_text', 10, 1);
    function update_totals_text($totals) {
    foreach ($totals as $key => $total) {
    if (isset($total['value'])) {
    // Replace "for month" with "per month"
    $totals[$key]['value'] = str_replace(['for month', 'For month'], ['per month', 'Per month'], $total['value']);
    }
    }
    return $totals;
    }

    // Additional filter for cart totals on the cart/checkout page
    add_filter('woocommerce_cart_totals_order_total_html', 'update_order_total_text', 10, 1);
    function update_order_total_text($value) {
    // Replace "for month" with "per month"
    return str_replace(['for month', 'For month'], ['per month', 'Per month'], $value);
    }

    Your existing filter for subtotals remains unchanged as it works correctly.

    The woocommerce_get_order_item_totals filter is added to update the totals section for orders in a more structured way.

    The woocommerce_cart_totals_order_total_html filter addresses the totals displayed on the cart and checkout pages.

    This should resolve the inconsistency and ensure the phrase “per month” is applied throughout both the subtotal and totals sections.

    Please give this code a try and let me know if it resolves your issue. I’d be happy to assist further if needed!

    Best regards,

    Plugin Support rzepsen

    (@rzepsen)

    Hi @pcaraway1

    Thank you for feedback.

    We apologize for the inconvenience, the problem has been reported, and our technicians are trying to resolve it as soon as possible. As soon as I receive further information on this subject, I will notify you immediately.

    In case of further questions, please contact me.

    Best Regards,

    Thread Starter pcaraway1

    (@pcaraway1)

    Hi @sebastianrybacki ,

    That code did not work either… I looked at the plugin code and the “For’ is not considering a single month, day or year. The assumption would be that you would do the plugin is assuming multiple days, months or years. Any other suggestions are appreciated!

    Sincerely,
    Paul

    Plugin Support sebastianrybacki

    (@sebastianrybacki)

    Hi Paul,

    Thank you for your feedback and for testing the updated code.

    I’m sorry to hear that it didn’t resolve the issue. If this solution didn’t work, we’ll need to wait for further intervention from the development team, as mentioned earlier.

    The issue might be related to how the plugin handles singular versus plural cases for time periods, which may require adjustments on the plugin level. Rest assured, our technicians are already investigating the problem, and as soon as we have a resolution or further suggestions, we’ll notify you immediately.

    We appreciate your patience and understanding. If you have any other questions in the meantime, feel free to reach out.

    Best regards,

    Plugin Support sebastianrybacki

    (@sebastianrybacki)

    Hello Paul,

    Thank you for your patience.

    We’ve just released an update for Flexible Subscriptions (1.5.0), which includes multiple improvements and fixes, including the issue you reported regarding the “For month” to “Per month” text in the Totals section.

    We encourage you to update the plugin.

    Kind regards,

    Plugin Support sebastianrybacki

    (@sebastianrybacki)

    Hello,

    I haven’t heard from you in a while, so I’m marking this thread as resolved. Please don’t hesitate to open a new one if you encounter other issues while using our plugin.

    Have a fantastic day,

    Thread Starter pcaraway1

    (@pcaraway1)

    Yes, it appears tobe working! Thank you for the update!

    Sincerely,
    Paul

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.