P粉9856865572023-08-16 09:41:30
There is no need to use a heavier query to check if a customer has a paying order because there is already a lightweight built-in function in the WC_Customer
class using get_is_paying_customer()
Method, which uses custom user metadata, is available since WooCommerce version 5.8.
You can disable "Check" payments for new customers using the following methods:
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; }
Place the code in your child theme’s functions.php file (or in a plugin). Tested and available.