Created
May 31, 2017 06:38
-
-
Save neltseng/af3744868b54f4ae16c8ea201066b37a to your computer and use it in GitHub Desktop.
增加購買商品欄位至訂單列表 for Woo v3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 增加購買商品欄位至訂單列表 for Woo v3 | |
add_filter('manage_edit-shop_order_columns', 'wc_custom_purchased_column'); | |
function wc_custom_purchased_column($columns) | |
{ | |
$new_array = array(); | |
foreach ($columns as $key => $title) { | |
if ($key == 'billing_address') { | |
$new_array['order_items'] = __('購買商品'); | |
} | |
$new_array[$key] = $title; | |
} | |
return $new_array; | |
} | |
add_action('manage_shop_order_posts_custom_column', 'wc_shop_custom_column', 10, 2); | |
function wc_shop_custom_column($column) | |
{ | |
global $post, $woocommerce, $the_order; | |
switch ($column) { | |
case 'order_items': | |
$terms = $the_order->get_items(); | |
echo '<a href="#" class="show_order_items">' . apply_filters( 'woocommerce_admin_order_item_count', sprintf( _n( '%d item', '%d items', $the_order->get_item_count(), 'woocommerce' ), $the_order->get_item_count() ), $the_order ) . '</a>'; | |
if ( sizeof( $the_order->get_items() ) > 0 ) { | |
echo '<table class="order_items" cellspacing="0">'; | |
foreach ( $the_order->get_items() as $item ) { | |
$product = apply_filters( 'woocommerce_order_item_product', $item->get_product(), $item ); | |
$item_meta = new WC_Order_Item_Meta( $item, $product ); | |
$item_meta_html = $item_meta->display( true, true ); | |
?> | |
<tr class="<?php echo apply_filters( 'woocommerce_admin_order_item_class', '', $item, $the_order ); ?>"> | |
<td class="qty"><?php echo esc_html( $item->get_quantity() ); ?></td> | |
<td class="name"> | |
<?php if ( $product ) : ?> | |
<?php echo ( wc_product_sku_enabled() && $product->get_sku() ) ? $product->get_sku() . ' - ' : ''; ?><a href="<?php echo get_edit_post_link( $product->get_id() ); ?>"><?php echo apply_filters( 'woocommerce_order_item_name', $item->get_name(), $item, false ); ?></a> | |
<?php else : ?> | |
<?php echo apply_filters( 'woocommerce_order_item_name', $item->get_name(), $item, false ); ?> | |
<?php endif; ?> | |
<?php if ( ! empty( $item_meta_html ) ) : ?> | |
<?php echo wc_help_tip( $item_meta_html ); ?> | |
<?php endif; ?> | |
</td> | |
</tr> | |
<?php | |
} | |
echo '</table>'; | |
} else echo '–'; | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment