To have a prefixed order number with manager initials from an array of manager initials sequentially, use the following:
// Save prefixed order number as order meta data
add_action( 'woocommerce_checkout_update_order_meta', 'save_the_order_number', 10, 2 );
function save_the_order_number( $order_id, $data ) {
// Here set the managers initials
$initials = array('JKI', 'FGR', 'LFA', 'OPI', 'TME');
$count = count($initials); // Get the length of the array (manager initials count)
$previous = get_option('last_assigned_manager'); // Load previous assigned manager initials value
$prev_key = array_search($previous, $initials); // Get the array key for previous manager initials value
$now_key = ($previous + 1) == $count ? 0 : $previous + 1; // Get the next array key (the current manager to be assigned)
update_post_meta( $order_id, '_order_number', $initials[$now_key] . '-' . $order_id ); // Save prefixed order number
update_option( 'last_assigned_manager', $initials[$now_key] ); // Save current assigned manager initials value
}
// Assign order number meta data to get_orde_number method
add_filter( 'woocommerce_order_number', 'assign_order_number_from_meta_data', 10, 2 );
function assign_order_number_from_meta_data( $order_id, $order ) {
// Get the order number (custom meta data)
$order_number = $order->get_meta('_order_number');
return $order_number ? $order_number : $order_id;
}
Code goes in functions.php file of the active child theme (or active theme). It should works.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…