All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
Whoever fears Allah in everything he does in order to get closer to Him, (i.e. in all forms of worship like prayer, Zakat, Hajj, …etc.), while performing such acts in the appropriate way and with a pure intention that complies with the Sunnah of the Prophet Allah will accept such deeds from him even if he commits sins otherwise. He might, for instance, be someone who shaves his beard or smokes, …etc. But this does not change the ruling. On the other hand, the person who does not fear Allah in his deeds, and performs them in a way different from the one prescribed, then Allah does not accept anything from him/her even if he abides by Allah's Orders otherwise. Nevertheless, one should know that shaving the beard is prohibited unless the person is in dire necessity. For more benefit about shaving the beard, please refer to Fataawa 365356, 93756 81533 and 82143.
Allah knows best.