How to add order status class to the body tag?

do you know how can we add CSS class into the body tag when a user has an (any) order which is on pending payment status?

I tried this one but no luck

add_filter( 'body_class', 'order_class');

function order_class($orderclasses) {

$order = wc_get_order( $order_id );
$order_status  = $order-get_status();

    if( is_page( 30 ))  {
        $orderclasses[] = $order_status;
    }
    return $orderclasses;
}

Thank you

Topic body-class woocommerce-offtopic filters Wordpress

Category Web


This does the trick

add_filter( 'body_class', 'order_class');

function order_class( $orderclasses ) {

    $user_id = get_current_user_id(); // The current user ID
    
    // Get the WC_Customer instance Object for the current user
    $customer = new WC_Customer( $user_id );
    
    // Get the last WC_Order Object instance from current customer
    $last_order = $customer->get_last_order();
    
    $order_id     = $last_order->get_id(); // Get the order id
    $order_data   = $last_order->get_data(); // Get the order unprotected data in an array
    $order_status = $last_order->get_status(); // Get the order status
    
    if( is_page( 30 ))  {
        $orderclasses[] = $order_status;
    }
    return $orderclasses;
}

Remember, 30 is my page ID where I wanted to run the filter and action.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.