我修改了woocommerce\\u custom\\u order\\u columns函数,对woocommerce管理订单页面进行了一些更改。一切都很好,除了订单状态显示两次(但仅针对最新(顶级)订单)。我附上了一张图片和可能导致这种情况的代码。我不知道会发生什么。
我的代码:
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 \'–\';
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 \'–\';
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;
}
}
WooCommerce代码:
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 \'–\';
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 \'–\';
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);
如您所见,我在这里所做的唯一一件事就是删除默认值
woocommerce_custom_order_columns
函数,并将其替换为
match_order_woocommerce_custom_order_columns
作用其他一切都一样。