Add additional fee to the cart.
public add_fee ( string $name, float $amount, boolean $taxable = false, string $tax_class = '' ) | ||
$name | string | Unique name for the fee. Multiple fees of the same name cannot be added. |
$amount | float | Fee amount. |
$taxable | boolean | (default: false) Is the fee taxable? |
$tax_class | string | (default: '') The tax class for the fee if taxable. A blank string is standard tax class. |
/** * Add order/subscription fee line items to the cart when a renewal order, initial order or resubscribe is in the cart. * * @param WC_Cart $cart * @since 2.0.13 */ public function maybe_add_fees($cart) { if ($cart_item = $this->cart_contains()) { $order = $this->get_order($cart_item); if ($order instanceof WC_Order) { foreach ($order->get_fees() as $fee) { $cart->add_fee($fee['name'], $fee['line_total'], abs($fee['line_tax']) > 0, $fee['tax_class']); } } } }