Bacs activated
<?php
namespace App;
function s7_activate_bacs($order) {
return ($order->get_payment_method() == 'bacs' || $order->get_payment_method() == 'cheque') ? true : false;
}
add_filter( 'woocommerce_available_payment_gateways', function ( $available_gateways ) {
$hide_bacs = true;
$hide_cheque = true;
$currentuserID = get_current_user_id();
if($currentuserID) {
$currentuser = 'user_'.$currentuserID;
$hide_bacs = !get_field('bacs_activated', $currentuser);
$hide_cheque = !get_field('cheque_activated', $currentuser);
}
if($hide_bacs) {
unset($available_gateways['bacs']);
}
if($hide_cheque) {
unset($available_gateways['cheque']);
}
return $available_gateways;
});
add_action('woocommerce_thankyou', function( $order_id ) {
if ( ! $order_id ) {return;}
$order = wc_get_order( $order_id );
if( s7_activate_bacs($order) && ($order->get_status() == 'wc-pending' || $order->get_status() == 'on-hold') ) {
$order->update_status( 'wc-processing' );
}
});