Removing payment gateways from WooCommerce

2019-01-21 18:07发布

问题:

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!

回答1:

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



回答2:

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.



回答3:

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!



回答4:

Other option would be using BACS payment method, where you could explain the client that he will be invoiced later.

You can even add some info at the email that is sent when BACS is used.