WC_Abstract_Legacy_Order::add_fee( object $fee )

Add a fee to the order.


Description Description

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.


Parameters Parameters

$fee

(Required) Fee data.


Top ↑

Return Return

(int) Updated order item ID.


Top ↑

Source Source

File: includes/legacy/abstract-wc-legacy-order.php

	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(),
		) );
		$item->save();
		$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();
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.