Twig Math: Subtract Cart Total from Minimum order amount for Free shipping

Hi!

I thought this would be easy with Twig, but I just cannot get it working. I need to subtract the Cart total from 40,00 €, which is the minimum order amount for free shipping.

I have the current cart amount: {{ woocommerce.cart_total_raw }}. (I tried the other cart total versions as well). This outputs 8,78 €, with a comma and with a space.

I have the Minimum order amount set dynamically: {{woocommerce.free_shipping_min}}, but this can be hard-coded to 40,00 € if that makes it simpler.

I have a hard-coded Twig calculation that works:

{% set currency = ' €' %}
{% set min_clean = '40.00' %}
{% set cart_clean = '8.78' %}
{% set remaining = max(min_clean - cart_clean, 0) %}
{{ remaining | number_format(2, ',', '.') ~ currency }}

But, I simply cannot get the dynamic one to work, that would show the remaining amount left until free shipping. (I tried with the “Advanced” extension on as well).

Can you please help me with this?
Thank you!

Try with this replace and striptags. Really we need way to get the raw number which you would assume is what raw does, but there is html that outputs in the woocommerce function we are calling. I’ll probably add an argument to the dynamic content to get a float value. Let us know if this helps. Have a great weekend.

{% set total = woocommerce.cart_total_raw | striptags | replace({".": "", ",": ".", "€": ""}) %}