As long as you follow requirements of the license (https://stackoverflow.com/help/licensing) you should be fine* from legal point of view.
To your actual question: One answer on that post worked for me. Should I copy it?
The answer is basically always NO. You should understand it and write your own version that fits into your code - read official documentation (which in a large number of cases - including the one linked in this question - will have the code from the answer under even more permissive license anyway), add logging, error handling, update style, variable names and so on.
If you decide to copy the code as-is make sure to understand whether what you provide to customers considered "source code" or not. With compiled languages like C++/Java/C# compiled program will not have source, but in cases of JavaScript for example you likely "ship" the source code - in some cases license/attribution is needed even for minified versions and definitely should be present in non-minified files.
Even if you rewrite the same code yourself consider to add a reference to the SO question - it will likely save you days later when you try to figure out what this code is doing.
And if you think "no one will ever find out" - please take a moment and decompile the program you plan to give to customers. It is pretty much guaranteed that at least function names would be there - if the code your copied had "Bamboozle13" as a function name it is extremly unlikely you'd come up with such exact name yourself (especially if this one would stick out from all other names your code uses). As a side effect this may also save you from embarrassment of using swear words in method/class names.
*Please note that this is not an actual legal advice and if you are really concerned about it contact lawyer.