php - Update Fees “Name” Dynamically during checkout process or on cart

It would be great if you could help me with this. I am adding a fee basically named as "Additional Add On" on checkout page.
public function change_fee_price($cart){
$fee_cost = WC()->session->get( 'my_misc_fee_cost' ); // 0 default value.
WC()->cart->add_fee("Additional Add on", $fee_cost);
}
add_action( 'woocommerce_cart_calculate_fees', array($this, 'change_fee_price'), 20, 1 );
I have made this fees amount editable for admin on checkout page.
public function editable_additional_addon_fees($ci, $fee){
if(WC()->customer->get_role() == "administrator"){
if(is_cart()){
if($fee->id == "additional-add-on"){
$fee_total = WC()->cart->display_prices_including_tax() ? $fee->amount + $fee->tax : $fee->amount ;
$fee_total = WC()->session->get( 'my_misc_fee_cost' ) ? WC()->session->get( 'my_misc_fee_cost' ) : $fee_total;
$html = "$$fee_total <strong><i>(Edit on checkout page.)</i></strong>";
return $html;
}
}
if(is_checkout()){
if($fee->id == "additional-add-on"){
$fee_total = WC()->cart->display_prices_including_tax() ? $fee->amount + $fee->tax : $fee->amount ;
$fee_total = WC()->session->get( 'my_misc_fee_cost' ) ? WC()->session->get( 'my_misc_fee_cost' ) : $fee_total;
$html = "$<input type='number' id='misc_fee_charge' name='misc_fee_charge' value='".$fee_total."'>";
return $html;
}
}
return $ci;
}
add_filter( 'woocommerce_cart_totals_fee_html', array($this, 'editable_additional_addon_fees'), 10, 2);
Now what if admin wants to rename the "Additional Add On" fee name to "Extra Charges for XYZ" rather than changing the amount.
woocommerce_cart_totals_fee_html
helped in editing the html of the fee amount and not the fee name. I want to give user the option to name it's fee dynamically on cart from frontend rather than adding a static name.
Does anyone have any idea how to achieve that?
If you still dont understand the question. Please take a look at the image:
To summarize, the question is simple. How to give the option to edit the fee name dynamically from frontend!
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: a non-numeric value encountered
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.