简体   繁体   中英

Echo Woocommerce order date (plus dispatch days) in admin order list

I am trying to add order date + a number of working days (not in current code) in the admin order list. But I can´t get it to work with order date. It works with $order_item['quantity'] .

The current code:

add_action ( 'manage_shop_order_posts_custom_column', 'dispatch');

function dispatch( $colname ) { 
global $the_order; // the global order object

  if( $colname == 'dispatch' ) {
    // get items from the order global object
    $order_items = $the_order->get_items();
    
    if ( !is_wp_error( $order_items ) ) {
        foreach( $order_items as $order_item ) {
            echo $order_item['get_date_created'];
           
        }
    }
  }
}

Got it figured out.Since I'm not a programmer I have no idea if this is a good solution.

// start dispatch
if( $colname == 'dispatch' ) {
    // get items from the order global object
    $order_itemss = $the_order->get_items();

    // The orders date
    $order_date = $the_order->order_date;

    // The order date + 8-10 days
    $order_date_8d = date_i18n( 'D j M', strtotime( $order_date ) + ( 8 * 24 * 60 * 60 ) );
    $order_date_10d = date_i18n( 'D j M', strtotime( $order_date ) + ( 10 * 24 * 60 * 60 ) );

    
    if ( !is_wp_error( $order_itemss ) ) {
        foreach( $order_itemss as $order_itemm ) {
            
            echo $order_date_8d .' - '. $order_date_10d;
        }
        // end foreach
    }
    // end if
}
// end dispatch

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM