Pre-Fix Order Numbers by User Role

Question

I currently have orders set with the pre-fix “W” for Wholesale orders to differentiate them from Retail orders. However, we have a few different wholesale roles and I would like to be able to differentiate those orders with a pre-fix as well. Is there a way to code a special pre-fix based on user role? The role in particular would be for a wholesale role labeled as employee. Since Employee falls under the Wholesale Role, it is getting the W prefix to their orders. I would like all other wholesale orders to have the W prefix, Employee orders to have an E prefix, and all retail orders to have no prefix (remain as-is).

Here is the snippet that works for wholesale orders to have the W prefix:

add_filter( ‘woocommerce_order_number’, ‘change_woocommerce_order_number’ );
function change_woocommerce_order_number( $order_id ) {

$prefix = 'W'; //The Prefix 
$order_type = get_post_meta( $order_id, '_wwpp_order_type',true); //get Wholesale Order Type

 if ($order_type == 'wholesale') {
    $new_order_id = $prefix . $order_id;
    return $new_order_id;
}
 
return $order_id;

}

0
jj123 3 weeks 2021-04-26T18:37:24-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse