Woo Snippet: Set Default Gateway for Woocommerce

updated: 02.08.2021
add_action( 'template_redirect', 'define_default_payment_gateway' );
function define_default_payment_gateway(){
    if( is_checkout() && ! is_wc_endpoint_url() ) {
        $default_payment_id = 'essl_webpay_gateway';

        WC()->session->set( 'chosen_payment_method', $default_payment_id );
    }
}