0

I used to have code to display column with order SKUs in admin order list page. After introducing WooCommerce HPOS I changed the hooks accordingly (because of admin list page change) but it looks like there is a new global order object now. This is what I have - it does not work:

add_filter('manage_woocommerce_page_wc-orders_columns', 'order_items_column' );
function order_items_column( $order_columns )
{
    $order_columns['order_products'] = 'Produkty';
    return $order_columns;
}
add_action( 'manage_woocommerce_page_wc-orders_custom_column' , 'order_items_column_cnt' );
function order_items_column_cnt( $colname )
{
    global $the_order; // the global order object
    if ( $colname == 'order_products' ) {
        // 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 ) {
                $product = $order_item->get_product();
                // product checking
                if ( is_object($product ) ) {
                    $sku =  $product->get_sku()  ;
                    echo $order_item['quantity'] .'×' . $sku . ' ';
                }
                else
                {
                    echo $order_item['quantity'];
                }               
            }
        }
    }
}

This is the error: Uncaught Error: Call to a member function get_items() on null I could not find in HPOS reference to the new global order object. Any idea how to replace it?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.