在不使用插件的情况下为 WooCommerce 订单号添加后缀和前缀 [英] Adding suffix and prefix to WooCommerce order number without using a plugin
本文介绍了在不使用插件的情况下为 WooCommerce 订单号添加后缀和前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在不使用插件的情况下为 Woo Commerce 订单号添加后缀和前缀.
I want to add a suffix and a prefix to a Woo Commerce order number without using a plugin.
我尝试使用这个不起作用的钩子:
I tried to use this hook which is not working:
add_filter( 'woocommerce_order_number','my_woocommerce_order_number', 1, 2);
function my_woocommerce_order_number( $oldnumber, $order ) {
return 'VC'.$order->id;
}
我怎样才能做到这一点?
How can I achieve this?
推荐答案
add_filter( 'woocommerce_order_number', 'change_woocommerce_order_number', 1, 2);
function change_woocommerce_order_number( $order_id, $order ) {
$prefix = '#SAM-';
$suffix = '-' . date(Y);
// You can use either one of $order->id (or) $order_id
// Both will work
return $prefix . $order->id . $suffix;
}
参考:https://docs.woocommerce.com/wc-apidocs/source-class-WC_Order.html#379
这篇关于在不使用插件的情况下为 WooCommerce 订单号添加后缀和前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文