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;
}