按顺序将分配的经理首字母添加到 WooCommerce 订单号
Add assigned manager initials sequentially to WooCommerce order numbers
使用以下代码,我可以为 WooCommerce 订单号添加前缀和后缀:
add_filter( 'woocommerce_order_number', 'change_woocommerce_order_number' );
function change_woocommerce_order_number( $order_id ) {
$prefix = 'VK/';
$suffix = '/TS';
$new_order_id = $prefix . $order_id . $suffix;
return $new_order_id;
}
How we can prefix the order number with shop manager initials sequentially from an array of shop managers initials?
This way we can assign equally WooCommerce orders to each one of them.
Any help?
要从经理首字母数组中按顺序获得带有经理首字母的前缀订单号,请使用以下命令:
// 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;
}
代码进入活动子主题(或活动主题)的 functions.php 文件。它应该有效。
使用以下代码,我可以为 WooCommerce 订单号添加前缀和后缀:
add_filter( 'woocommerce_order_number', 'change_woocommerce_order_number' );
function change_woocommerce_order_number( $order_id ) {
$prefix = 'VK/';
$suffix = '/TS';
$new_order_id = $prefix . $order_id . $suffix;
return $new_order_id;
}
How we can prefix the order number with shop manager initials sequentially from an array of shop managers initials?
This way we can assign equally WooCommerce orders to each one of them.
Any help?
要从经理首字母数组中按顺序获得带有经理首字母的前缀订单号,请使用以下命令:
// 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;
}
代码进入活动子主题(或活动主题)的 functions.php 文件。它应该有效。