Home Woocommerce Hooks Woocommerce Hook – Remove Payment Gateway if Coupon applied

Woocommerce Hook – Remove Payment Gateway if Coupon applied

by therichpost
0 comment
woocommerce

Hello, welcome to therichpost.com. In this post, I will tell you, Woocommerce Hook – Remove Payment Gateway if Coupon applied.  WordPress is the best cms and Woocommerce is the best Ecommerce plugin. Woocommerce hooks(add_action, add_filter) give us the power to edit or change the code without interruption into the files and this is the best thing about wordpress. Now I am going to tell you how the hooks work.

Here is the working Images:

woocommerce-hook-remove-payment-gateway-if-coupon-applied

 

woocommerce-hook-remove-payment-gateway-if-coupon-applied

Here is the working and tested code and you need to add this code into your theme’s functions.php file:

add_filter('woocommerce_available_payment_gateways', 'applied_coupons_hide_payment_gateways', 20, 1 );
function applied_coupons_hide_payment_gateways( $available_gateways){
    // If at least a coupon is applied
    if( sizeof( WC()->cart->get_applied_coupons() ) > 0 ){
        // Loop through payment gateways
        foreach ( $available_gateways as $gateway_id => $gateway ) {
            // Remove all payment gateways except BACS (Bank Wire)
            if( $gateway_id != 'bacs' )
                unset($available_gateways[$gateway_id]);
        }
    }

    return $available_gateways;
}

 There are so many hooks in wordpress and i will let you know all. If you have any query related to this post then do   ask questions or comment below. Thank you.

 

You may also like

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.