Woocommerce Hooks

Woocommerce Hook – Remove Payment Gateway if Coupon applied

Woocommerce Hook - Remove Payment Gateway if Coupon applied - The Rich Post

woocommerce
203Views

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.

 

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

Leave a Reply

Positive SSL