If the defendant give such bond, or be committed to jail for want of it, the court in which the case is pending, or the judge thereof in vacation, may, after reasonable notice to the plaintiff, or his attorney, quash the order and discharge the defendant from custody, or discharge the bond, on being satisfied that the order was wrongfully obtained; and, whether the order was so obtained or not, may discharge him from custody when the plaintiff is cast in the action, proceeding or suit.
W. Va. Code § 53-7-6