Restrict payment methods when buying a gift card

There are paid plugins available that will allow you to restrict the payment methods by product, however you can also do this yourself for the gift cards in a few steps.

1. Download the free Code Snippets plugin:
2. Create a Snippet with the following code:

function pw_gift_card_payment_methods( $available_gateways ) {
    global $pw_gift_cards_redeeming;

    if ( is_admin() ) {
        return $available_gateways;

    if ( isset( $pw_gift_cards_redeeming ) && $pw_gift_cards_redeeming->cart_contains_gift_card() ) {
        // Cash on Delivery
        unset( $available_gateways['cod'] );

        // Direct Bank Transfer
        unset( $available_gateways['bacs'] );

    return $available_gateways;
add_filter( 'woocommerce_available_payment_gateways', 'pw_gift_card_payment_methods' );

If you are more comfortable editing your functions.php file that works, too.

The key used in the $available_gateways array can be found by going to WooCommerce -> Settings -> Payments -> Look for the “section=” in the URL for the payment method.

Skip to content