Over 400 years ago, the kabbalists of Tzefat began accepting Shabbat by reciting psalms and liturgical poems. Because the Jewish people wished to give expression to the neshama yeteira (the extra soul that one receives when observing Shabbat), this custom was accepted by all Israel and became Kabbalat Shabbat. At that time lived R. Shlomo Alkabetz, who composed the wonderful poem Lekha Dodi that is used to welcome the Shabbat in all synagogues.
It was Arizal’s custom to welcome the Shabbat in a field, facing west toward the setting sun (the Sages say [BB 25a] that the Shekhina is manifest primarily in the west). This custom was accepted in most synagogues; when reciting the last stanza of Lekha Dodi, in which Shabbat is welcomed like a bride, the congregation faces west. Accordingly, even when the entrance to the synagogue faced a different direction, the congregation faces west. Some have the custom to face the entrance to the synagogue, even if it is not to the west, as an expression of the idea that Shabbat is a guest that enters through the door (some Sephardic communities face west throughout the recitation of Mizmor Le-David and Lekha Dodi).
In many synagogues, Friday night services begin relatively late, and the congregation reaches Lekha Dodi after sunset. In order to fulfill the mitzva of tosefet Shabbat (adding on to Shabbat), they must accept Shabbat before sunset by saying “Bo’i kalla Shabbat ha-malka” (“Come, o bride, o Shabbat queen”). Thus, it is best if after Minĥa, before sunset, the gabbai makes this declaration.
Women generally accept Shabbat at candle lighting, thereby fulfilling tosefet Shabbat in an outstanding manner. A woman who regularly prays Minĥa should make every effort to pray Minĥa on Friday before candle lighting, for in the opinion of many poskim, after she accepts Shabbat by lighting the candles, she is unable to pray a weekday Minĥa (MB 263:43). Be-di’avad, if she did pray Minĥa before she lit the candles, she may rely on the lenient opinion. The lenient poskim maintain that even though she accepted Shabbat and is forbidden from doing melakha (labors forbidden on Shabbat), still, she may still pray a weekday Amida (Tzitz Eliezer 13:42; also see Peninei Halakha: Shabbat, ch. 2 n. 6).