How to set the first order status as a custom status for newly created orders from Woocommerce Rest API?

28 Views Asked by At

We use a platform called BaseLinker, which sends orders from other marketplaces to our WooCommerce store through Rest API. The problem is that initially the orders have a status of "Payment Pending," then "Processing," and the final status remains "Processing," triggering automated emails and SMS messages. However, our contracts with other marketplaces clearly specify that we cannot contact external customers except directly through them.

We created a custom status with the slug "baselinker," and from their platform, we had the option to set which status new orders should receive. Currently, it is as follows: "Payment Pending" -> "Processing" -> "BaseLinker." Once it reaches the "Processing" status, the emails and SMS messages are automatically sent. How can we prevent new orders created through Rest API from receiving the "Processing" status at all?

I've tried this code:

add_action('woocommerce_new_order', 'custom_set_order_status', 10, 1);

function custom_set_order_status($order_id) {
    if (!$order_id) return;

    $order = wc_get_order($order_id);

    if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '/wp-json/wc/') !== false) {
        // Set the order status
        $order->update_status('baselinker', 'Order status changed to BaseLinker automatically by custom code.', true);
    }
}

Unfortunately, not much is happening. It was doing exactly what the platform does, changing the status from "Processing" to "BaseLinker." This code doesn't make sense because their platform already does this.
However, the action of this code was faster than the action in the respective platform. In the sense that the first status was "BaseLinker," then "Pending," then "Processing."

0

There are 0 best solutions below