The status code is only known when the process terminates. So the only way to do what you are asking, is to run the process having redirected its stdout to a temporary file, and then when it terminates, examine its status code. If it is nonzero, just delete the temporary file, if it is zero, just output the contents of the temporary file to stdout.
Here's a bash script that automates that:
#!/bin/bash
temp_file=$(mktemp)
"$@" > temp_file
if [[ $? == 0 ]]; then
cat "$temp_file"
fi
rm "$temp_file"
If you call this script mute then you can the command foo --bar as follows
mute foo --bar