在 woocommerce 订单中编辑产品的价格和名称 -WORDPRESS
Edit the price and name of the product in woocommerce order -WORDPRESS
我正在尝试创建一个订单,然后向其中添加产品,效果非常好。
现在我想在添加产品之前编辑产品的价格和名称。但是出于某种原因我做不到
以下是我正在尝试做的事情:
$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订单产品的价格和名称。
这是如何完成的
$prices = array( 'totals' => array(
'subtotal' => $custom_price,
'total' => $custom_price
) );
$order->add_product($product, $quantity, $prices);
我正在尝试创建一个订单,然后向其中添加产品,效果非常好。 现在我想在添加产品之前编辑产品的价格和名称。但是出于某种原因我做不到
以下是我正在尝试做的事情:
$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订单产品的价格和名称。
这是如何完成的
$prices = array( 'totals' => array(
'subtotal' => $custom_price,
'total' => $custom_price
) );
$order->add_product($product, $quantity, $prices);