You can try the following for Cash on delivery (COD) payment method, replacing in the code both 'my_variable'
with the correct slug:
add_filter( 'woocommerce_cod_process_payment_order_status', 'conditionally_change_cod_order_status_to_pending', 10, 2 );
function conditionally_change_cod_order_status_to_pending( $status, $order ) {
$global_var = $GLOBALS;
if ( isset($global_var['my_variable']) && $global_var['my_variable'] ) {
return 'pending';
}
return $status;
}
Code goes in functions.php file of your child theme (or in a plugin). It should work.