nguyenminh

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

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 .  sprintf("%02d", $order->id) . $suffix;
}

Categorised in: Tổng hợp

0 Comments for "Adding suffix and prefix to WooCommerce order number without using a plugin"

One thought on “Adding suffix and prefix to WooCommerce order number without using a plugin”

  1. admin says:

    You can try str_pad($month, 2, ‘0’, STR_PAD_LEFT);

Leave a Reply

Your email address will not be published. Required fields are marked *