DEV Community

Jack Harner 🚀
Jack Harner 🚀

Posted on • Originally published at harnerdesigns.com

Make WooCommerce Custom Order Status Payable

Do you have a custom WooCommerce Order Status that you want to be able to take payments on? Look no further than the woocommerce_valid_order_statuses_for_payment filter. I spent an ungodly amount of time looking for this filter today. I knew what I needed, but I didn't know what it was called. I knew there was a wc_order_is_editable filter that you could add statuses too, so I figured there had to be one to be able to require payment on a custom order status.

Make WooCommerce Custom Order Status Payable

After many trials and tribulations, I present to you my findings:

function filter_woocommerce_valid_order_statuses_for_payment($array, $instance)
    {
        $my_order_status = array('cancelled', '<custom_order_status>');
        return array_merge($array, $my_order_status);
    }

    // add the filter
    add_filter('woocommerce_valid_order_statuses_for_payment', 'filter_woocommerce_valid_order_statuses_for_payment', 10, 2);
Enter fullscreen mode Exit fullscreen mode

This beautifully simple piece of code will add the list of order statuses to the statuses that can access the checkout or Form Pay.

Why I Figured This Out

I developed a workflow that would allow a client to take deposits on custom orders. It involves programatically setting the order status to deposit_paid but the customer needs to still be able to pay the rest of the balance. By adding deposit_paid to the list of valid order statuses for payment, the customer can come back and pay the rest of the invoice when the order is ready to ship.

This took me forever to figure out. I have no idea why.

What's the latest thing that's taken you the longest to figure out?

Recent Posts

Top comments (0)