WCMp Core
-
AuthorPosts
-
-
December 23, 2021 at 7:22 PM #132386raoulParticipant
Hi, I have some code in my functions.php file that allows customers to edit orders. All this actually does is allow a customer to place a new order that overrides an existing order.
When a customer completes the new order at checkout, the code creates a new order and cancels the previous existing order by changing the order status from ‘processing’ to ‘cancelled’. The issue is that the order status is changed to cancelled in the wordpress admin dashboard, however the order status in the vendor dashboard is still showing as ‘processing’.
The issue is this code cancels the order but not the vendor suborders that are shown to the vendor on the vendor dashboard. Therefore I think I just need to add a line to the code below to ensure all suborders are also changed to ‘cancelled’ status when the parent order is. Would it be possible for you to update the snippet below so that the suborders of the ‘oldorder’ are also changed to cancelled. This would be hugely appreciated!!
Thank you
add_action( ‘woocommerce_checkout_update_order_meta’, ‘bbloomer_save_edit_order’ );
function bbloomer_save_edit_order( $order_id ) {
$edited = WC()->session->get( ‘edit_order’ );
if ( ! empty( $edited ) ) {
// update this new order
update_post_meta( $order_id, ‘_edit_order’, $edited );
$neworder = new WC_Order( $order_id );
$oldorder_edit = get_edit_post_link( $edited );
$neworder->add_order_note( ‘Order placed after editing. Old order number: ‘ . $edited . ‘‘ );
// cancel previous order
$oldorder = new WC_Order( $edited );
$neworder_edit = get_edit_post_link( $order_id );
$oldorder->update_status( ‘cancelled’, ‘Order cancelled after editing. New order number: ‘ . $order_id . ‘ -‘ );
WC()->session->set( ‘edit_order’, null );
}
} -
December 23, 2021 at 9:53 PM #132397MVX Support NinjaKeymaster
Hi, thank you for getting in touch with us. Our team will get back to you. Kindly provide us some time.
-
December 27, 2021 at 7:05 PM #132468NerdySupportExpert MoumitaKeymaster
Hi, let me help you out with the flow :
– When an order is created on the woocommerce end, we create the corresponding sub-order.
– Now, we check the initial order status of the order from woocommerce’s main order and set the same order status for suborders too
– After that, each vendor/admin needs to change the order status for each sub-order
– Therefore, apart from initial order status, if you change the status of an order, this will not affect the sub order’s status
Now, you need to add some custom code to sync the parent order status with the suborders:add_action( 'woocommerce_order_status_cancelled', 'wcmp_suborder_status_change_to_cancel' ); function wcmp_suborder_status_change_to_cancel( $order_id ) { global $WCMp; $suborder_details = get_wcmp_suborders($order_id); foreach ($suborder_details as $key => $value) { $suborder_fetch = array( 'ID' => $value->get_id(), 'post_status' => 'wc-cancelled', ); wp_update_post( $suborder_fetch ); } }
Copy
-
-
AuthorPosts
The topic ‘Set vendor suborder to ‘cancelled’ when parent order is cancelled’ is closed to new replies.