Skip to content

Instantly share code, notes, and snippets.

@victormattosvm
Last active May 24, 2021 23:29
Show Gist options
  • Save victormattosvm/b14fc275017cfdc43af6b09a383f476f to your computer and use it in GitHub Desktop.
Save victormattosvm/b14fc275017cfdc43af6b09a383f476f to your computer and use it in GitHub Desktop.
Sync order status to suborder WCMP
<?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