WC_REST_Orders_V2_Controller::prepare_fee_lines()
Create or update an order fee.
Method of the class: WC_REST_Orders_V2_Controller{}
No Hooks.
Return
WC_Order_Item_Fee
.
Usage
// protected - for code of main (parent) or child class $result = $this->prepare_fee_lines( $posted, $action, $item );
- $posted(array) (required)
- Item data.
- $action(string)
- 'create' to add fee or 'update' to update it.
Default: 'create' - $item(object)
- Passed when updating an item. Null during creation.
Default: null
WC_REST_Orders_V2_Controller::prepare_fee_lines() WC REST Orders V2 Controller::prepare fee lines code WC 9.8.2
protected function prepare_fee_lines( $posted, $action = 'create', $item = null ) { $item = is_null( $item ) ? new WC_Order_Item_Fee( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item; if ( 'create' === $action ) { if ( empty( $posted['name'] ) ) { throw new WC_REST_Exception( 'woocommerce_rest_invalid_fee_item', __( 'Fee name is required.', 'woocommerce' ), 400 ); } } $this->maybe_set_item_props( $item, array( 'name', 'tax_class', 'tax_status', 'total' ), $posted ); $this->maybe_set_item_meta_data( $item, $posted ); return $item; }