【问题标题】:Change Order item prices in Woocommerce 3在 Woocommerce 3 中更改订单商品价格
【发布时间】:2018-10-14 06:28:38
【问题描述】:

我需要更改 woocommerce 订单中的商品价格,但我发现的只是更改购物车中的价格,但这不是我需要的,因为我需要在结帐流程后进行更改。

有人可以告诉我如何做到这一点吗?

【问题讨论】:

  • 你究竟什么时候需要这样做以及如何(或上下文是什么)......实际上你的问题还不清楚。
  • 嗨,对不起,这个想法是当客户下订单时,送货员去购买产品但价格是可变的,所以,这个人需要添加一个具有特定价格的通用产品,所以现在是在客户下订单之后和收到付款之前(货到付款),因为我建立了一个页面,其中显示了当前订单,并且我需要在文本字段中填写价格并添加具有此特定价格的通用产品。
  • 我终于回答了……我们将不胜感激。谢谢。

标签: php wordpress woocommerce orders price


【解决方案1】:

@LoicTheAztec

通过手动输入标识符来完成自动 woo-commerce 支付

The shopper goes online, creates an account , adds a payment method, and fills their cart .

We hold the amount plus 15% when they check out.

woocommerce sends order details to the delivery team that takes the gig .

They go to the store and shop

After checking out at the physical store, the new invoice total is uploaded to woo-commerce via the shopping app .

This manually entered amount will be the IDENTIFIER in the stripe that TRIGGERS the order completion

【讨论】:

    【解决方案2】:

    非常感谢,我花了4个小时寻找如何更改订单中的产品数量,并根据您的代码(我重写了必要的部分)我终于明白了!那就是如果有人需要更改订单中的产品数量`

    $order = wc_get_order( $_POST['orderID'] );
    
    foreach( $order->get_items() as $item_id => $item ){
        $product = $item->get_product();
        $product_price = (int) $product->get_price(); // A static replacement product price
        $new_quantity = (int) $_POST['productQty'] // product Quantity
        
        // The new line item price
        $new_line_item_price = $product_price * $new_quantity;
        
        // Set the new price
        $item->set_quantity($_POST['orderQty']);
        $item->set_subtotal( $new_line_item_price ); 
        $item->set_total( $new_line_item_price );
    
        // Make new taxes calculations
        $item->calculate_taxes();
    
        $item->save(); // Save line item data
    }
    // Make the calculations  for the order and SAVE
    $order->calculate_totals();`
    

    【讨论】:

      【解决方案3】:

      您需要使用 Woocommerce 3 中引入的新 CRUD setters methods

      这是一个具有静态价格和静态订单 ID 的基本示例:

      $order_id = 809; // Static order Id (can be removed to get a dynamic order ID from $order_id variable)
      
      $order = wc_get_order( $order_id ); // The WC_Order object instance
      
      // Loop through Order items ("line_item" type)
      foreach( $order->get_items() as $item_id => $item ){
          $new_product_price = 50; // A static replacement product price
          $product_quantity = (int) $item->get_quantity(); // product Quantity
          
          // The new line item price
          $new_line_item_price = $new_product_price * $product_quantity;
          
          // Set the new price
          $item->set_subtotal( $new_line_item_price ); 
          $item->set_total( $new_line_item_price );
      
          // Make new taxes calculations
          $item->calculate_taxes();
      
          $item->save(); // Save line item data
      }
      // Make the calculations  for the order and SAVE
      $order->calculate_totals();
      

      然后您必须在自定义页面中用您提交的新价格替换静态价格,这并不简单,因为您需要定位正确的$item_id...

      【讨论】:

      • 谢谢你!它为我节省了一天。我试图使用带有您的价格插件名称的自定义捐赠表格。由于自定义形式,当有人捐赠超过最低捐赠时,捐赠价格和总数会有所不同。这帮助我更改了捐赠的价格,并将其正确反映在他们通过电子邮件发送的收据上。谢谢!!!
      • 谢谢,这对我也很有效。我只想问热排除来计算小计只改变产品价格而不是别的吗?
      • 想知道是否可以设置总含税?
      猜你喜欢
      • 2017-04-04
      • 2018-11-24
      • 2018-01-24
      • 1970-01-01
      • 2018-08-31
      • 2020-05-20
      • 2017-12-10
      • 2018-01-30
      • 1970-01-01
      相关资源
      最近更新 更多