It is reported from Sayyiduna Ibn Abbas (may Allah be pleased with them both) that a man came to him and said: Should I begin with Safa or with Marwah? Should I pray before performing tawaf or after it? And should I shave my head before slaughtering or after it? Sayyiduna Ibn Abbas (may Allah be pleased with them both) said: Act upon the Book of Allah, for it is more worthy of being retained (that is, of its commands being acted upon). Allah Almighty says: "Indeed, Safa and Marwah are among the symbols of Allah" [Surah al-Baqarah: 158], so Safa comes before Marwah. And Allah Almighty said: "And do not shave your heads until the sacrificial animal reaches its place of slaughter" [Surah al-Baqarah: 196], so slaughtering comes before shaving. And Allah Almighty said: "And purify My House for those who perform tawaf, those who stand, and those who bow and prostrate" [Surah al-Hajj: 26], so tawaf comes before prayer (halq: shaving the head).
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الطهارة / 401