[Plugin: Woocommerce] How to Delete Custom Fees
-
This bothered me for a while, but I found a solution:
There is no native function to remove fees, you have to retrieve all the fees, and then cycle through them, checking the names, and storing all the fee objects in an array. Check the “name” property, and if you find the fee(s) you wish to delete, simply exclude them from the process. Afterward, replace the entire ‘fees’ session variable with the updated array of fees.
I’m sure the code could be refactored into a much more elegant plugin, but this is how I did it.
$fees = WC()->cart->get_fees; $newfees = array(); foreach ($fees as $fee) { if ($fee->name == 'NAME OF FEE YOU WANT TO DELETE') {} //Don't add Shipping Insurance else {$newfees[] = $fee;} } WC()->session->set('fees',$newfees);
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘[Plugin: Woocommerce] How to Delete Custom Fees’ is closed to new replies.