Around April this year, we have to move our business 100% online due to the pandemic. Physical store hardly get one customer per day.
after 5 months, we recognizes pattern; almost all failed COD delivery are customers with no previous purchase and any successful COD for the value below $15 will result in loss.
We have moved all customer with successful purchase to "verified_customer" and due to massive number of account, all test account need to move to "test_customer" to reduce possibility of error but must retain all "customer" function.
I search the internet for the php and tried this
add_filter('woocommerce_available_payment_gateways','filter_gateways',1);
function filter_gateways($gateways){
global $woocommerce, $cart_subtotal, $current_user;
if ( $cart_subtotal >= 15 ) {
$userRole = implode(',',$current_user->roles);
if($userRole == 'customer'){
//-- Remove COD if cart >=$15 belongs to a customer
unset($gateways['cod']);
}
}else{
//-- Hide COD if Subtotal is less than 15
unset($gateways['cod']);
}
return $gateways;
}
This function manage to disable COD payment method for "customer" but not "test_customer". Our test acccount did not experience what an actual customer is experiencing for now and also cart value limit of $15 is somehow doesn't work using this.
Is this even possible?