Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing payment gateways from WooCommerce

I have a WooCommerce shop (running local) but I want to remove the payment gateways. The customer should be able to place an order without paying any cent, I will send them an invoice manually.

I can not really find where to disable this, it seems not to be standard in WooCommerce.

Have tried disabling all the payment gateways in the backend, but you have to leave one payment gateway enabled.

Thanks in advance!

like image 400
Arko Elsenaar Avatar asked May 24 '13 07:05

Arko Elsenaar


People also ask

How do I remove a payment gateway in WooCommerce?

All you have to do is Just copy and paste the code snippet written below in your theme's functions. php file. // Disable all payment gateways on the checkout page and replace the "Pay" button by "Place order" add_filter( 'woocommerce_cart_needs_payment', '__return_false' );

How do I remove a payment gateway from my website?

Go to PR menu > Payment Gateways to check if payment method is enabled. Also, Membership field needs to be added when payment gateway is enable on registration form. By looking into your form, payment gateway is disable in your website.

How do I remove a payment method from Wordpress?

To delete a credit card from your account, go to Purchases → Payment Methods in your profile settings. Under the Manage Your Credit Cards section, click Delete next to any card to delete it.

How do I change the default payment gateway in WooCommerce?

You can define the default payment gateway by moving it to the top of the list of payment gateways via WooCommerce → Settings → Payments.


3 Answers

Just add this line in functions.php in your theme: add_filter('woocommerce_cart_needs_payment', '__return_false');

like image 107
Mateusz Paulski Avatar answered Oct 17 '22 17:10

Mateusz Paulski


Leave 'Cash on Delivery' enabled, and it won't take a payment at the checkout. You can easily change the 'Cash on Delivery' titles and labels to something like 'No Payment Required' or similar.

like image 26
crdunst Avatar answered Oct 17 '22 18:10

crdunst


Something that the other answers to this question haven't addressed is the fact that you need a way for the customer to eventually pay the invoice. Using Cash on Delivery (renamed to suit your needs) perfectly accomplishes not having the user actually pay at checkout, but the problem is that if Cash on Delivery was your only payment method, it will still be the only payment method when you send them the invoice.

I think in most cases you're going to want only cash on delivery during the cart checkout, and a different payment method (like Stripe) for the invoice payment method.

Here's the full workflow to create a deferred payment setup.

  1. Like @crdunst mentions, you should use Cash on Delivery and rename it to "Wait for Invoice" or something.
  2. Enable all of the payment gateways that you ever want to use (in this example, we'll just use Cash on Delivery and Stripe. Cash on Delivery will be our "checkout" payment gateway, and Stripe will be our invoice payment gateway.
  3. Use the following filter to turn on and off gateways based on whether or not you're on the order-pay endpoint (the page used for invoice payments).

    /**
     * Only show Cash on Delivery for checkout, and only Stripe for order-pay
     *
     * @param   array   $available_gateways    an array of the enabled gateways
     * @return  array                          the processed array of enabled gateways
     */
    function so1809762_set_gateways_by_context($available_gateways) {
        global $woocommerce;
    
        $endpoint = $woocommerce->query->get_current_endpoint();
    
        if ($endpoint == 'order-pay') {
            unset($available_gateways['cod']);
        } else {
            unset($available_gateways['stripe']);
        }
    
        return $available_gateways;
    }
    add_filter( 'woocommerce_available_payment_gateways', 'so1809762_set_gateways_by_context');
    

Of course, if you're using a gateway other than stripe for the order-pay page, you'll want to make sure that you update unset($available_gateways['stripe']); to the proper array key.

After that, you should be good to go! Your site will now display different gateways based on whether or not you're on the invoice pay page!

like image 4
Pete Avatar answered Oct 17 '22 17:10

Pete