Modify WooCommerce product columns

2019-08-08 12:18发布

I'm trying to override, or simply customize, the admin orders list view.

I understood the method to customize is render_shop_order_columns in includes/admin/class-wc-admin-post-types.php but I cannot remove the action (method) from theme functions.php neither by a custom plugin in the plugins_loaded hook: always get bool(false) on

var_dump(remove_action( 'manage_shop_order_posts_custom_column', array( $GLOBALS['wc_admin_post_type'], 'render_shop_order_columns' ) ));

I see there is the woocommerce_order_item_name filter, but if I add a picture there (that's what I need), I get a wrong output since it is used in the title attribute of link to product too.

Could anyone please advice? Thank you!

1条回答
Fickle 薄情
2楼-- · 2019-08-08 13:00

I was getting a wrong way... Maybe the right one is to unset the column and add your own. See here: https://wordpress.org/support/topic/hooking-and-adding-new-column-on-woocommerce-order-admin-page

basically:

add_filter('manage_edit-shop_order_columns', 'show_custom_product_column', 15);

function show_custom_column($columns) {

    $new_columns = (is_array($columns)) ? $columns : array();

    //remove column
    unset($new_columns['column_to_unset']);

    //add custom column
    $new_columns['custom_column'] = __( 'Translation', 'woocommerce' );

    return $new_columns;
}

add_action('manage_shop_order_posts_custom_column', 'my_custom_column', 10, 2);

function my_custom_column($column) {

    global $post, $woocommerce, $the_order;

    switch ($column) {

        case 'custom_column' :
        // Custom code
        break;
    }
}
查看更多
登录 后发表回答