0
votes

I'm at wits end with this now and could really use a hand.

I've added a form on the front end that asks the customer to register with their IRL user account number, I've managed to get that to store in the back end as "morello_account_number". Now I want to echo that account number on the order page in Woocommerce so that I can process orders easier without searching the customers username etc manually. I'm not really a PHP programmer, but here's my code so far:

    add_filter('manage_edit-shop_order_columns', 'morello_account_number_column' );
function morello_account_number_column( $order_columns ) {
    $order_columns['morello_account_number'] = "Morello Account Number";
    return $order_columns;
}



add_action( 'manage_shop_order_posts_custom_column' , 'morello_placeholder' );
function morello_placeholder( $colname ) {
    global $the_order; // the global order object

    if( $colname == 'morello_account_number' ) {
        $morello_account_number = $order->get_morello_account_number();

        echo morello_account_number;

    }

}

Apologies if this is super trivial - still learning. And thanks so much in advance.

1

1 Answers

0
votes

Assuming you've used update_post_meta before in your previous code?

Then you could apply the following

/**
 * Add columns
 */
function morello_account_number_column( $columns ) {
    $columns['morello_account_number'] = "Morello Account Number";
    return $columns;
}
add_filter('manage_edit-shop_order_columns', 'morello_account_number_column', 10, 1 );

/**
 * Populate columns
 */
function morello_placeholder( $column, $post_id ) {
    if( $column == 'morello_account_number' ) {
        // https://developer.wordpress.org/reference/functions/get_post_meta/
        $m_a_n = get_post_meta( $post_id, 'morello_account_number', true );

        // Value is found
        if ( !empty($m_a_n) ) {
            echo $m_a_n;    
        } else {
            echo 'something else';
        }
    }
}
add_filter( 'manage_shop_order_posts_custom_column', 'morello_placeholder', 10, 2 );