Select Woocommerce payment method conditionally in PHP
<p>I want to programmatically set a default payment method (radio is checked) in woocommerce checkout page based on a condition using php (not jquery).</p>

<p>Lets say I have two payment methods:</p>

<pre><code>'pay_method1' and 'pay_method2'
</code></pre>

<p>Most solutions suggest removing a method in order to select the other:</p>

<pre><code>unset($gateways['pay_method1']) //auto selects pay_method2 naturally
</code></pre>

<p>But I don't want to remove the method. I only want to set a default when the checkout page loads / reloads, so the the user can still switch methods if needed.</p>

<p>I plan on having the following action in <code>functions.php</code>:</p>

<pre><code>add_action("woocommerce_before_checkout_form", "custom_before_checkout_action");
function custom_before_checkout_action() {

if ($my_condition) {
   //default to pay_method1 - how??
}
else {
   //default to pay_method2 - how??
}
</code></pre>

<p>}</p>

<p>Is this possible to tell woocommerce which payment method should be checked this way?</p>