【问题标题】:Edit the price and name of the product in woocommerce order -WORDPRESS在 woocommerce 订单中编辑产品的价格和名称 -WORDPRESS
【发布时间】:2017-03-31 07:23:35
【问题描述】:

我正在尝试创建一个订单,然后将产品添加到其中,效果很好。 现在我正在尝试在添加产品之前编辑产品的价格和名称。但是由于某种原因,我无法做到这一点

以下是我想要做的:

     $order = wc_create_order();

    $item = wc_get_product( $components[$comp]['component_product_id_2'] );
    //var_dump($item); exit;

   /*_____BELOW IS WHAT I HAVE TRIED NEW_________*/                                 
    $item_args = array(
             'name'         => 'Product A',
             'total'        => wc_get_price_excluding_tax( $item, array( 'qty' => 1, 'price' => 245 ) ),
             );

    /*_____ABOVE IS WHAT I HAVE TRIED NEW_________*/ 

    $order->add_product(  $item, $components[$comp]['quantity'], $item_args );

我已经参考add_product 信息尝试了上述方法

没有$item_args,一切都会完美运行。项目在 woocommerce 订单中添加。所以这意味着其余的代码都可以,除了$item_args。所以我认为没有必要放$components代码。

我想编辑woocom订单产品的价格和名称。

【问题讨论】:

    标签: php wordpress woocommerce orders


    【解决方案1】:

    这是怎么做的

    $prices = array( 'totals' => array( 
                    'subtotal' => $custom_price, 
                    'total' => $custom_price
                ) );
    
    
    $order->add_product($product, $quantity, $prices);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-25
      • 1970-01-01
      • 1970-01-01
      • 2021-05-09
      • 2019-03-31
      • 2016-02-19
      • 2018-06-17
      • 1970-01-01
      相关资源
      最近更新 更多