So I have this Edit order page that allows my client to re-edit the order. The issue is the paypal fee I have set wont update with the item total and I was trying to include the order total in the nonce fields and then edit them on change with Javascript however when i add the field and save it i get a "Call to undefined method WC_Order_Item_Fee::set_subtotal()" error.
PHP:
<?php
$order = wc_get_order( absint( $_REQUEST['id'] ) );
$paypal_fee = 0;
foreach( $order->get_items('fee') as $item_id => $item_fee ){
$fee_name = $item_fee->get_name();
if ($fee_name == 'Paypal Fee') {
// The fee total amount
$fee_total = $item_fee->get_total();
// // The fee total tax amount
// $fee_total_tax = $item_fee->get_total_tax();
$paypal_fee = $fee_total;
}
}
$price = $order->get_item_total( $item );
?>
HTML:
<form id="wcpv-vendor-order-detail" method="POST">
<input type="hidden" name="id" value="<?php echo $id; ?>" />
<input type="hidden" name="item_id" value="<?php echo $item_id; ?>" />
<input type="hidden" name="page" value="wcpv-vendor-order" />
<input type="hidden" name="action" value="confirmed_edit_item" />
<?php wp_nonce_field( 'website-confirmed-edit-item', '_wpnonce' ); ?>
<p>
<table>
<tr>
<th>
<label for="price"><?php echo $product_name; ?></label>
</th>
<td>
<input type="text" class="wc_input_price" id="price" name="price" value="<?php echo $price; ?>" />
<input type="text" class="wc_input_fee" id="fee" name="fee" value="<?php echo $paypal_fee; ?>" />
</td>
</tr>
</table>
</p>
<?php submit_button( __( 'Save new price', 'website' ), 'delete' ); ?>
</form>
I tried using Auto add or update a custom fee via admin edit orders in WooCommerce answer code in my functions.php hoping that it'll trigger when anyone hits the edit price. But it still does not work.