CheckoutWoocommerce

Disable payment methods in checkout for specific country & show custom message. Woocommerce

Disable payment methods in checkout for specific country & show custom message. Woocommerce

In woocommerce, we disable all payment methods and we show a custom message instead of the default “Sorry, it seems that there are no available payment methods. Please contact us if you require assistance or wish to make alternate arrangements.”

  1. Filter Hook: The woocommerce_no_available_payment_methods_message filter allows you to modify the message that shows up when no payment gateways are available.
  2. Custom Function: The custom_no_payment_methods_message function checks if the shipping country is the UK (GB). If it is, it changes the message to your custom one. If not, it leaves the message as it is.
    
//disable all payment methods function disable_uk_checkout($available_gateways) { if (is_admin()) return $available_gateways; // Check if in admin if (WC()->customer->get_shipping_country() != 'GB') return $available_gateways; // GB is the country code for the UK // Disable checkout by unsetting all payment gateways $available_gateways = array(); return $available_gateways; } add_filter('woocommerce_available_payment_gateways', 'disable_uk_checkout', 10, 1); //custom message add_filter( 'woocommerce_no_available_payment_methods_message', 'custom_no_payment_methods_message', 10, 1 ); function custom_no_payment_methods_message( $message ) { if ( WC()->customer->get_shipping_country() == 'GB' ) { return 'My custom message'; } return $message; }

Leave a Reply

Your email address will not be published. Required fields are marked *