Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I modified the woocommerce_custom_order_columns function to make some changes to the WooCommerce Admin Order page. Everything works great, except that Order Status shows up twice (but only for the latest (top) order). I've attached an image and the code that could be causing this. I have no idea what would make this happen.

enter image description here

My Code:

add_action('manage_shop_order_posts_custom_column', 'match_order_woocommerce_custom_order_columns', 2);

function match_order_woocommerce_custom_order_columns( $column ) {

remove_action('manage_shop_order_posts_custom_column', 'woocommerce_custom_order_columns', 2);

global $post, $woocommerce;
$order = new WC_Order( $post->ID );

switch ($column) {
    case "order_status" :

        printf( '<mark class="%s">%s</mark>', sanitize_title($order->status), __($order->status, 'woocommerce') );

    break;
    case "order_title" :

        if ($order->user_id) $user_info = get_userdata($order->user_id);

        if (isset($user_info) && $user_info) :

            $user = '<a href="user-edit.php?user_id=' . esc_attr( $user_info->ID ) . '">';

            if ($user_info->first_name || $user_info->last_name) $user .= $user_info->first_name.' '.$user_info->last_name;
            else $user .= esc_html( $user_info->display_name );

            $user .= '</a>';

        else :
            $user = __('Guest', 'woocommerce');
        endif;

        echo '<a href="'.admin_url('post.php?post='.$post->ID.'&action=edit').'"><strong>'.sprintf( __('Order %s', 'woocommerce'), $order->get_order_number() ).'</strong></a> ' . __('made by', 'woocommerce') . ' ' . $user;

        if ($order->billing_email) :
            echo '<small class="meta">'.__('Email:', 'woocommerce') . ' ' . '<a href="' . esc_url( 'mailto:'.$order->billing_email ).'">'.esc_html( $order->billing_email ).'</a></small>';
        endif;
        if ($order->billing_phone) :
            echo '<small class="meta">'.__('Tel:', 'woocommerce') . ' ' . esc_html( $order->billing_phone ) . '</small>';
        endif;

    break;
    case "billing_address" :
        if ($order->get_formatted_billing_address()) :

            echo '<a target="_blank" href="' . esc_url( 'http://maps.google.com/maps?&q='.urlencode( $order->get_billing_address() ).'&z=16' ) . '">'. preg_replace('#<br\s*/?>#i', ', ', $order->get_formatted_billing_address()) .'</a>';
        else :
            echo '&ndash;';
        endif;

        if ($order->payment_method_title) :
            echo '<small class="meta">' . __('Via', 'woocommerce') . ' ' . esc_html( $order->payment_method_title ) . '</small>';
        endif;

    break;
    case "shipping_address" :
        if ($order->get_formatted_shipping_address()) :

            echo '<a target="_blank" href="' . esc_url( 'http://maps.google.com/maps?&q='.urlencode( $order->get_shipping_address() ).'&z=16' ) .'">'. preg_replace('#<br\s*/?>#i', ', ', $order->get_formatted_shipping_address()) .'</a>';
        else :
            echo '&ndash;';
        endif;

        if ($order->shipping_method_title) :
            echo '<small class="meta">' . __('Via', 'woocommerce') . ' ' . esc_html( $order->shipping_method_title ) . '</small>';
        endif;
    break;
    case "total_cost" :
        echo $order->get_formatted_order_total();
    break;
    case "order_date" :

        if ( '0000-00-00 00:00:00' == $post->post_date ) :
            $t_time = $h_time = __( 'Unpublished', 'woocommerce' );
        else :
            $t_time = get_the_time( __( 'Y/m/d g:i:s A', 'woocommerce' ), $post );

            $gmt_time = strtotime($post->post_date_gmt);
            $time_diff = current_time('timestamp', 1) - $gmt_time;

            if ( $time_diff > 0 && $time_diff < 24*60*60 )
                $h_time = sprintf( __( '%s ago', 'woocommerce' ), human_time_diff( $gmt_time, current_time('timestamp', 1) ) );
            else
                $h_time = get_the_time( __( 'Y/m/d', 'woocommerce' ), $post );
        endif;

        echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post ) . '</abbr>';

    break;
    case "order_actions" :

        ?><p>
            <?php
                do_action( 'woocommerce_admin_order_actions_start', $order );

                $actions = array();

                if ( in_array( $order->status, array( 'pending', 'on-hold' ) ) )
                    $actions[] = array(
                        'url'       => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce-mark-order-processing&order_id=' . $post->ID ), 'woocommerce-mark-order-processing' ),
                        'name'      => __( 'Processing', 'woocommerce' ),
                        'action'    => "processing"
                    );

                if ( in_array( $order->status, array( 'pending', 'on-hold', 'processing' ) ) )
                    $actions[] = array(
                        'url'       => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce-mark-order-complete&order_id=' . $post->ID ), 'woocommerce-mark-order-complete' ),
                        'name'      => __( 'Complete', 'woocommerce' ),
                        'action'    => "complete"
                    );

                $actions[] = array(
                        'url'       => admin_url( 'post.php?post=' . $post->ID . '&action=edit' ),
                        'name'      => __( 'View', 'woocommerce' ),
                        'action'    => "view"
                    );

                $actions = apply_filters( 'woocommerce_admin_order_actions', $actions, $order );

                foreach ( $actions as $action )
                    printf( '<a class="button tips" href="%s" data-tip="%s"><img src="%s" alt="%s" width="14" /></a>', $action['url'], $action['name'], $woocommerce->plugin_url() . '/assets/images/icons/' . $action['action'] . '.png', $action['name'] );

                do_action( 'woocommerce_admin_order_actions_end', $order );
            ?>
        </p><?php

    break;
    case "note" :
        if ( get_post_meta( $post->ID , 'match_order' , TRUE) == 1 ) {
            echo '<img src="' . WP_PLUGIN_URL . '/match_previous_order/note-red.png" alt="Match Previous Order" class="tips" data-tip="'. __('Match Previous Order', 'woocommerce') .'" width="14" height="14" />';
        }
        else if ($order->customer_note) {
            echo '<img src="'.$woocommerce->plugin_url().'/assets/images/note.png" alt="yes" class="tips" data-tip="'. __('Yes', 'woocommerce') .'" width="14" height="14" />';
        }
        else {
            echo '<img src="'.$woocommerce->plugin_url().'/assets/images/note-off.png" alt="no" class="tips" data-tip="'. __('No', 'woocommerce') .'" width="14" height="14" />';
        }
    break;
    case "order_comments" :

        echo '<div class="post-com-count-wrapper">
            <a href="'. admin_url('post.php?post='.$post->ID.'&action=edit') .'" class="post-com-count"><span class="comment-count">'. $post->comment_count .'</span></a>
            </div>';
    break;
}
}

The WooCommerce Code:

function woocommerce_custom_order_columns( $column ) {

global $post, $woocommerce;
$order = new WC_Order( $post->ID );

switch ($column) {
    case "order_status" :

        printf( '<mark class="%s">%s</mark>', sanitize_title($order->status), __($order->status, 'woocommerce') );

    break;
    case "order_title" :

        if ($order->user_id) $user_info = get_userdata($order->user_id);

        if (isset($user_info) && $user_info) :

            $user = '<a href="user-edit.php?user_id=' . esc_attr( $user_info->ID ) . '">';

            if ($user_info->first_name || $user_info->last_name) $user .= $user_info->first_name.' '.$user_info->last_name;
            else $user .= esc_html( $user_info->display_name );

            $user .= '</a>';

        else :
            $user = __('Guest', 'woocommerce');
        endif;

        echo '<a href="'.admin_url('post.php?post='.$post->ID.'&action=edit').'"><strong>'.sprintf( __('Order %s', 'woocommerce'), $order->get_order_number() ).'</strong></a> ' . __('made by', 'woocommerce') . ' ' . $user;

        if ($order->billing_email) :
            echo '<small class="meta">'.__('Email:', 'woocommerce') . ' ' . '<a href="' . esc_url( 'mailto:'.$order->billing_email ).'">'.esc_html( $order->billing_email ).'</a></small>';
        endif;
        if ($order->billing_phone) :
            echo '<small class="meta">'.__('Tel:', 'woocommerce') . ' ' . esc_html( $order->billing_phone ) . '</small>';
        endif;

    break;
    case "billing_address" :
        if ($order->get_formatted_billing_address()) :

            echo '<a target="_blank" href="' . esc_url( 'http://maps.google.com/maps?&q='.urlencode( $order->get_billing_address() ).'&z=16' ) . '">'. preg_replace('#<br\s*/?>#i', ', ', $order->get_formatted_billing_address()) .'</a>';
        else :
            echo '&ndash;';
        endif;

        if ($order->payment_method_title) :
            echo '<small class="meta">' . __('Via', 'woocommerce') . ' ' . esc_html( $order->payment_method_title ) . '</small>';
        endif;

    break;
    case "shipping_address" :
        if ($order->get_formatted_shipping_address()) :

            echo '<a target="_blank" href="' . esc_url( 'http://maps.google.com/maps?&q='.urlencode( $order->get_shipping_address() ).'&z=16' ) .'">'. preg_replace('#<br\s*/?>#i', ', ', $order->get_formatted_shipping_address()) .'</a>';
        else :
            echo '&ndash;';
        endif;

        if ($order->shipping_method_title) :
            echo '<small class="meta">' . __('Via', 'woocommerce') . ' ' . esc_html( $order->shipping_method_title ) . '</small>';
        endif;
    break;
    case "total_cost" :
        echo $order->get_formatted_order_total();
    break;
    case "order_date" :

        if ( '0000-00-00 00:00:00' == $post->post_date ) :
            $t_time = $h_time = __( 'Unpublished', 'woocommerce' );
        else :
            $t_time = get_the_time( __( 'Y/m/d g:i:s A', 'woocommerce' ), $post );

            $gmt_time = strtotime($post->post_date_gmt);
            $time_diff = current_time('timestamp', 1) - $gmt_time;

            if ( $time_diff > 0 && $time_diff < 24*60*60 )
                $h_time = sprintf( __( '%s ago', 'woocommerce' ), human_time_diff( $gmt_time, current_time('timestamp', 1) ) );
            else
                $h_time = get_the_time( __( 'Y/m/d', 'woocommerce' ), $post );
        endif;

        echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post ) . '</abbr>';

    break;
    case "order_actions" :

        ?><p>
            <?php
                do_action( 'woocommerce_admin_order_actions_start', $order );

                $actions = array();

                if ( in_array( $order->status, array( 'pending', 'on-hold' ) ) )
                    $actions[] = array(
                        'url'       => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce-mark-order-processing&order_id=' . $post->ID ), 'woocommerce-mark-order-processing' ),
                        'name'      => __( 'Processing', 'woocommerce' ),
                        'action'    => "processing"
                    );

                if ( in_array( $order->status, array( 'pending', 'on-hold', 'processing' ) ) )
                    $actions[] = array(
                        'url'       => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce-mark-order-complete&order_id=' . $post->ID ), 'woocommerce-mark-order-complete' ),
                        'name'      => __( 'Complete', 'woocommerce' ),
                        'action'    => "complete"
                    );

                $actions[] = array(
                        'url'       => admin_url( 'post.php?post=' . $post->ID . '&action=edit' ),
                        'name'      => __( 'View', 'woocommerce' ),
                        'action'    => "view"
                    );

                $actions = apply_filters( 'woocommerce_admin_order_actions', $actions, $order );

                foreach ( $actions as $action )
                    printf( '<a class="button tips" href="%s" data-tip="%s"><img src="%s" alt="%s" width="14" /></a>', $action['url'], $action['name'], $woocommerce->plugin_url() . '/assets/images/icons/' . $action['action'] . '.png', $action['name'] );

                do_action( 'woocommerce_admin_order_actions_end', $order );
            ?>
        </p><?php

    break;
    case "note" :
        if ($order->customer_note)
            echo '<img src="'.$woocommerce->plugin_url().'/assets/images/note.png" alt="yes" class="tips" data-tip="'. __('Yes', 'woocommerce') .'" width="14" height="14" />';
        else
            echo '<img src="'.$woocommerce->plugin_url().'/assets/images/note-off.png" alt="no" class="tips" data-tip="'. __('No', 'woocommerce') .'" width="14" height="14" />';

    break;
    case "order_comments" :

        echo '<div class="post-com-count-wrapper">
            <a href="'. admin_url('post.php?post='.$post->ID.'&action=edit') .'" class="post-com-count"><span class="comment-count">'. $post->comment_count .'</span></a>
            </div>';
    break;
}
}

add_action('manage_shop_order_posts_custom_column', 'woocommerce_custom_order_columns', 2);

As you can see, the only thing I've done here is remove the default woocommerce_custom_order_columns function and replaced it with the match_order_woocommerce_custom_order_columns function. Everything else is the same.

share|improve this question
    
In your code, you should do remove_action outside of the function. Just before the add_action, for example. –  brasofilo Feb 9 '13 at 4:39
    
I did that, but it doesn't work. It crashes the plugin. –  Jeremiah Prummer Feb 9 '13 at 5:03
    
Do you think that's why it's doing this, though? –  Jeremiah Prummer Feb 9 '13 at 5:03
    
You should show your full code for that custom column... –  brasofilo Feb 9 '13 at 5:06
    
I've updated it to include the full functions. Thanks for your help! –  Jeremiah Prummer Feb 9 '13 at 15:33

1 Answer 1

up vote 0 down vote accepted

Solved it. I used the plugins_loaded hook, like this:

add_action('plugins_loaded','example_function'); 

function example_function(){

remove_action('manage_shop_order_posts_custom_column', 'woocommerce_custom_order_columns', 2);
add_action('manage_shop_order_posts_custom_column', 'match_order_woocommerce_custom_order_columns', 2);

}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.