'Overwrite total order_shipping costs during checkout

I am using the plug-in E-Signature by https://www.approveme.com. This plugin allows me to gather a signature under a contract after the checkout process. So as soon as the user submits the checkout formula, he will be redirected to the contract.

In the template from of the contract I was able to access different woocoomerce fields, such as:

{{billing_first_name}}
{{order_id}}
{{order_total}}

etc. and {{order_shipping}}

The order_shipping value is the important one fore me since I want to update it during the checkout. So far I setup woocoomerce for no shipping costs at all. So this value seems to not be set. During the checkout I want to calculate the shipping costs using the address of the user. For doing this I wrote a function that will calculate the costs based on distance.

All that is now left to update the shipping costs for the whole order to be able to display it in the contract. This is the part where I get lost. I have no idea how to do this. I hoped doing:

WC()->cart->set_shipping_total(<caclulatedShippingCosts>);

would solve the problem, however it does not affect the order_shipping I am able to use as variable in the contract.

Does anyone has any idea how to update the order shipping and make it work?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source