P粉1564156962023-08-16 12:23:45
No need to repeat the query to check if the customer has a paid order, there is already a lightweight built-in function in the WC_Customer
class, use get_is_paying_customer()
Method, which uses a metadata specific to the user.
You can use it like this to disable the "Check" payment method for new customers:
add_filter('woocommerce_available_payment_gateways', 'cheque_payment_gateway_only_for_paying_customers'); function cheque_payment_gateway_only_for_paying_customers($gateways) { if ( ! WC()->customer->get_is_paying_customer() && isset($gateways['cheque']) ) { unset($gateways['cheque']); // 取消“支票”付款选项 } return $gateways; }
Put the code into your child theme’s functions.php file (or into a plugin). Tested and working fine.