Categories

Wednesday, December 4, 2024
#919814419350 therichposts@gmail.com
Woocommerce Hooks

Woocommerce Hook – Remove Payment Gateway if Coupon applied

How to add download pdf link in woocommerce single product page?

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

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.

 

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

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