Change Price products woocommerce in order
Question
I have custom status “Backordered”. Iwan to change price in order with status backordered to 50.
here my code
add_filter( 'woocommerce_order_status_backordered', 'change_backordered_to_processing', 100, 1 );
function change_backordered_to_processing( $order_id ){
if( ! $order_id ) return;
$order = wc_get_order( $order_id );
if( $order->get_status() == 'backordered' ){
$order->update_status( 'processing' );
$order->set_status( 'processing' );
foreach ($order->get_items() as $item_key => $item ){
$item_id = $item->get_id();
$new_product_price = 50
$quantity = (int)$item->get_quantity();
// The new line item price
$new_line_item_price = $new_product_price * $quantity;
// Set the new price
$item->set_subtotal( $new_line_item_price );
$item->set_total( $new_line_item_price );
$item->save(); // Save line item data
}
$order->calculate_totals();
$order->save();
}
return $order_id;
}
but it does not work. I change backordered to processing but cannot change price in order
0
customization, woocommerce
3 years
2020-04-01T04:51:03-05:00
2020-04-01T04:51:03-05:00 0 Answers
88 views
0
Leave an answer