Adding suffix and prefix to WooCommerce order number without using a plugin

*爱你&永不变心* 提交于 2020-02-02 11:57:33

问题


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?


回答1:


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;
}

Refernce: https://docs.woocommerce.com/wc-apidocs/source-class-WC_Order.html#379



来源:https://stackoverflow.com/questions/38783349/adding-suffix-and-prefix-to-woocommerce-order-number-without-using-a-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!