Search code examples
wordpresswoocommercehook-woocommercewordpress-rest-apiwoocommerce-rest-api

Woocommerce - let customer pay for order when order column value is late payment


I have a difficult problem which i'm trying to solve for some time now.. We are using plugin called admin customer order fields, which let's to create a new column for order. For this part I have made second order status which is called "Payment status" - it can be not paid, paid, or late payment. And these statuses work depending on payment type. For example if customer pays via bank, status becomes "pending" and second column becomes "not paid". But the problem is that we are using Partial Payments plugin, which let's customer to pay for order after some time, for example 30 days. But during these 30 days the product will be shipped to his address and he can pay for order later. The logic is like this:

Customer orders product with option to pay after 30 days. Order status becomes processing / payment status becomes not paid

And administrator can change the order status - if he ships it it becomes completed. So the statuses would be:

Order status - completed / payment status - not paid. And it should still let user to pay for the order even if order status is completed

Is it possible to make, that it customer could pay for order depending on payment status, not default order statuses? As the best what I have found is this hook:

woocommerce_valid_order_statuses_for_payment

But you can only make that the order statuses could be valid for payments, but I need to make it on payment status which is made with custom plugin. Attaching screenshot to be clear as possible.

The idea is to make that if payment status is "APMOKĖTA" you couldn't pay anymore, and if it's "ATIDĖTAS MOKĖJIMAS" you could pay for your order.


Solution

  • You can try using the woocommerce_order_needs_payment hook like this

    add_filter( 'woocommerce_order_needs_payment', 'custom_needs_payment', 10, 2 );
    
    function custom_needs_payment( $needs_payment, $order ){
        $payment_status = get_post_meta( $order->get_id(), 'payment_status', true );
        if($payment_status == 'APMOKĖTA'){
            return false;
        }
        return true;
    }
    

    You might need to change the names of the post meta to whatever it's named on your end