You can't check that in the method you wrote here, you don't have access to the attacker there.
If you trace that method, you will arrive in the 'attack' method found in the 'Game_Event' class (it's in the main SAS IV script).
That is where you can check if the event is facing the player or not by using this condition:
if @direction == reverse_dir($game_player.direction)
This would return true if they are facing towards each other.
As for where to put this in the method I mentioned, that depends on what you want to achieve with it, because there is a lot of thing going on in that method, not just the damage execution (some movements and animations are triggered there too).
But if you just want to avoid taking damage (with keeping all the other stuff happening in that method), you can wrap the whole damage triggering lines in this condition (this will not show any damage pop ups, I guess), or you can set the damage to 0 (or whatever value you want) when they are facing each other and the player is holding the shield (this will show the popup, because the damage is executed, but it is not the default damage).
I haven't tried this, but it should work like that, in theory.