DEV Community

Jack Harner 🚀
Jack Harner 🚀

Posted on • Originally published at harnerdesigns.com

2

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

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay