Last active
May 24, 2021 23:29
-
-
Save victormattosvm/b14fc275017cfdc43af6b09a383f476f to your computer and use it in GitHub Desktop.
Sync order status to suborder WCMP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Sync order status to suborder WCMp | |
*/ | |
add_action( 'woocommerce_order_status_changed', 'wcmp_sync_suborder_status', 10, 3 ); | |
function wcmp_sync_suborder_status( $order_id, $old_status, $new_status ) { | |
$statuses_to_sync = array( | |
'processing', | |
'cancelled', | |
'completed' | |
); | |
if ( in_array( $new_status, $statuses_to_sync ) ){ | |
$suborders = get_wcmp_suborders($order_id); | |
if ( ! $suborders || ( is_array( $suborders ) && count( $suborders ) <= 0 ) ) return; | |
foreach ($suborders as $key => $suborder) { | |
$suborder->update_status( $new_status ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment