0

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.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Ari Patwary
  • 80
  • 1
  • 8
  • Where are you using WC_Order_Item_Fee::set_subtotal() ? – LoicTheAztec Jan 15 '21 at 00:54
  • @LoicTheAztec i'm not but thats the error that ends up coming up. – Ari Patwary Jan 15 '21 at 01:59
  • So there is something else somewhere that is making trouble that use `WC_Order_Item_Fee` non existing method `set_subtotal()`, as we don't see that in your provided code. Note that *"The question should be updated to include desired behavior, a specific problem or error, **and the shortest code necessary to reproduce the problem."*** Your provided code **is not testable**, see [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example)… – LoicTheAztec Jan 15 '21 at 02:11
  • To finish don't use the `woocommerce_order_after_calculate_totals` hook from my answer code, instead try to use the code inside the function, that shows the way to set or update an order fee. – LoicTheAztec Jan 15 '21 at 02:14
  • @LoicTheAztec added the contents of the function within the html-vendor-order-edit-page.php from above and it still didn't work. – Ari Patwary Jan 15 '21 at 15:50

0 Answers0