WC_Abstract_Legacy_Order::add_fee()publicWC 1.0

Add a fee to the order. Order must be saved prior to adding items.

Fee is an amount of money charged for a particular piece of work or for a particular right or service, and not supposed to be negative.

Method of the class: WC_Abstract_Legacy_Order{}

No Hooks.


Int. Updated order item ID.


$WC_Abstract_Legacy_Order = new WC_Abstract_Legacy_Order();
$WC_Abstract_Legacy_Order->add_fee( $fee );
$fee(object) (required)
Fee data.

WC_Abstract_Legacy_Order::add_fee() code WC 8.9.0

public function add_fee( $fee ) {
	wc_deprecated_function( 'WC_Order::add_fee', '3.0', 'a new WC_Order_Item_Fee object and add to order with WC_Order::add_item()' );

	$item = new WC_Order_Item_Fee();
	$item->set_props( array(
		'name'      => $fee->name,
		'tax_class' => $fee->taxable ? $fee->tax_class : 0,
		'total'     => $fee->amount,
		'total_tax' => $fee->tax,
		'taxes'     => array(
			'total' => $fee->tax_data,
		'order_id'  => $this->get_id(),
	) );
	$this->add_item( $item );
	wc_do_deprecated_action( 'woocommerce_order_add_fee', array( $this->get_id(), $item->get_id(), $fee ), '3.0', 'woocommerce_new_order_item action instead.' );
	return $item->get_id();