Waqas

I hope you enjoy reading this blog post. If you want my team to do WooCommerce Maintenance for you, click here.

How to display a specific payment method for logged in users only in Woocommerce?

In this tutorial we’ll learn how to display a specific payment option for logged in users only.

First of all let’s have a look at our checkout page, what payment methods are being displayed initially.

Our team at Themelocation is comprised of WordPress developers of high expertise

  • We can maintain, support and manage your single, or all your clients, website with dedication
  • Our skills are at your disposal.

Book a Call

To do this add some items in cart and go to cart then proceed to checkout.

Here is the default checkout screen:

woocommerce

Here you can see three payment methods enabled. Now let’s say we want to display cheque payment method only for logged in users.

To do this add the following lines of code at the end of your theme’s functions.php file:

function rp_filter_gateways( $args ) {

if( !is_user_logged_in() && isset($args['cheque']) ) {

unset( $args['cheque'] );

}

return $args;

}

add_action( 'woocommerce_available_payment_gateways', 'rp_filter_gateways' );

You can access functions.php file here:

woocommerce

Save the file after that.

Now if you go to checkout page again and if you are not logged in, you’ll not see cheque payment option.

woocommerce

But the cheque payment option will still be displayed for logged in customers.

woocommerce

In the same way you can remove other payment methods as well.

CHEERS J

Waqas

I hope you enjoy reading this blog post. If you want my team to do WooCommerce Maintenance for you, click here.

Leave a Comment

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