Give_Payment::remove_fee_by PHP Method

remove_fee_by() public method

Remove a fee by the defined attributed
Since: 1.5
public remove_fee_by ( string $key, integer | string $value, boolean $global = false ) : boolean
$key string The key to remove by
$value integer | string The value to search for
$global boolean False - removes the first value it fines, True - removes all matches.
return boolean If the item is removed
    public function remove_fee_by($key, $value, $global = false)
    {
        $allowed_fee_keys = apply_filters('give_payment_fee_keys', array('index', 'label', 'amount', 'type'));
        if (!in_array($key, $allowed_fee_keys)) {
            return false;
        }
        $removed = false;
        if ('index' === $key && array_key_exists($value, $this->fees)) {
            $removed_fee = $this->fees[$value];
            $removed_fee['action'] = 'remove';
            $this->pending['fees'][] = $removed_fee;
            $this->decrease_fees($removed_fee['amount']);
            unset($this->fees[$value]);
            $removed = true;
        } else {
            if ('index' !== $key) {
                foreach ($this->fees as $index => $fee) {
                    if (isset($fee[$key]) && $fee[$key] == $value) {
                        $removed_fee = $fee;
                        $removed_fee['action'] = 'remove';
                        $this->pending['fees'][] = $removed_fee;
                        $this->decrease_fees($removed_fee['amount']);
                        unset($this->fees[$index]);
                        $removed = true;
                        if (false === $global) {
                            break;
                        }
                    }
                }
            }
        }
        if (true === $removed) {
            $this->fees = array_values($this->fees);
        }
        return $removed;
    }