0

所以我有这个编辑订单页面,允许我的客户重新编辑订单。问题是我设置的贝宝费用不会随项目总数更新,我试图将订单总数包含在 nonce 字段中,然后使用 Javascript 在更改时对其进行编辑,但是当我添加字段并保存它时,我得到一个“呼叫到未定义的方法 WC_Order_Item_Fee::set_subtotal()" 错误。

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>

我尝试在我的functions.php中通过WooCommerce答案代码中的管理员编辑订单使用自动添加或更新自定义费用,希望它会在任何人达到编辑价格时触发。但它仍然不起作用。

4

0 回答 0