• Resolved vato

    (@vatanbytyqi)


    I create orders from backend and let customers complete them from their frontend using the link:
    https://myshop.mydomain/checkout/order-pay/189?pay_for_order=true&key=wc_order_XXXXXXX

    However, if the total order value is $0.00 then it’s not possible for them to complete the order. It just shows a warning with the text:
    This order’s status is “Pending payment”—it cannot be paid for. Please contact us if you need assistance.

    If the order contains products that have a price more than $0.00 then it works as intended.

    Any idea of how to make it possible to complete an order that has “free”-products?

Viewing 9 replies - 16 through 24 (of 24 total)
  • Stef

    (@serafinnyc)

    Yeah didn’t have an issue on mine.

    View post on imgur.com

    Stef

    (@serafinnyc)

    In my test my payment gateways didn’t show. obviously because it’s free.

    Thread Starter vato

    (@vatanbytyqi)

    Here is an image that shows my issue, payment isn’t possible from orders page

    View post on imgur.com

    Stef

    (@serafinnyc)

    Yeah sorry. It’s really hard to troubleshoot requests like these without a URL.

    Thread Starter vato

    (@vatanbytyqi)

    @serafinnyc you are involved in my other post as well. I have the link and credentials there to test, it’s the same site 😛

    Stef

    (@serafinnyc)

    Got it

    Thread Starter vato

    (@vatanbytyqi)

    @serafinnyc could you verify the same behaviour on your site?

    Thread Starter vato

    (@vatanbytyqi)

    So the issue here is that the order needs to be completed from My Orders page, thus it’s not a bug in WooCommerce but a customization. Here is how to solve it.

    The code that causes the problem is located here:

    
    # includes/wc-class-order.php
    
            /**
    	 * Checks if an order needs payment, based on status and order total.
    	 *
    	 * @return bool
    	 */
    	public function needs_payment() {
    		$valid_order_statuses = apply_filters( 'woocommerce_valid_order_statuses_for_payment', array( 'pending', 'failed' ), $this );
    		return apply_filters( 'woocommerce_order_needs_payment', ( $this->has_status( $valid_order_statuses ) && $this->get_total() > 0 ), $this, $valid_order_statuses );
    	}
    

    More specifically this causes the problem $this->get_total() > 0

    So to override this filter, add this to your functions.php

    
    //Allow pay for order when the total price is $0.00 in frontend
    function check_order_payment($th, $order, $valid_order_statuses) {
      return $order->has_status( $valid_order_statuses );
    }
    remove_filter('woocommerce_order_needs_payment', WC_Order);
    add_filter( 'woocommerce_order_needs_payment', 'check_order_payment', 10, 3 );
    
    Plugin Support EtienneP a11n

    (@etiennep)

    Hi @vatanbytyqi!

    Nice solution!

    I agree with you that this is not technically a bug, but expected behavior since the product is actually free and therefore wouldn’t need payment. But I also understand that you need this in your case 😉

    I’m going to mark this as resolved now – if you have any further questions, you can start a new thread.

Viewing 9 replies - 16 through 24 (of 24 total)
  • The topic ‘Not possible to complete order with free products’ is closed to new replies.