• Resolved SolutionsDEV

    (@solutionsdev)


    I need to customize order numbers in the format like (year-month-dayofthemonth-orderID), without using any additional plugin.

    I have got a code and made changes to it with additional text like this:
    add_filter( ‘woocommerce_order_number’, ‘custom_woocommerce_order_number’, 1, 2 );
    function custom_woocommerce_order_number( $oldnumber, $order ) {
    return ‘Hello-‘ . date(“Ymd”) . ‘-‘ . $order->id;
    }

    This works fine, except that the date is set to current date, what I want is to set it to the date when the order is filled ensuring that once the order number is set, it wouldn’t be changed by the code.

    Would someone help me in this?

    Thanks,

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello,

    I am not super proficient with PHP but I believe since you are using date() you will get the current date and it will not match the order date. Since WooCommerce orders are custom post types in WordPress, you may have better luck using the get_the_date() function. You can learn more about that here:

    https://developer.wordpress.org/reference/functions/get_the_date/

    It is configured to retrieve the date on which a post was written. I hope that helps!

    Thanks!

    We haven’t heard back from you on this. I am going to mark this as Resolved at this time. If you have another issue please feel free to open a new post. 🙂

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custmizing Order Numbers’ is closed to new replies.