• Resolved jakaerc

    (@jakaerc)


    I’m trying to add a column with custom meta data to my woocommerce admin order list and be able to sort them by name. So far I have found a code that adds the columns but they are not sortable. Can anyone help? Thanks!

    Code that I found:

    // ADDING 2 NEW COLUMNS WITH THEIR TITLES (keeping "Total" and "Actions" columns at the end)
    add_filter( 'manage_edit-shop_order_columns', 'custom_shop_order_column', 20 );
    function custom_shop_order_column($columns)
    {
        $reordered_columns = array();
    
        // Inserting columns to a specific location
        foreach( $columns as $key => $column){
            $reordered_columns[$key] = $column;
            if( $key ==  'order_status' ){
                // Inserting after "Status" column
                $reordered_columns['my-column1'] = __( 'Razred','theme_domain');
                $reordered_columns['my-column2'] = __( '?ola','theme_domain');
            }
        }
        return $reordered_columns;
    }
    
    // Adding custom fields meta data for each new column (example)
    add_action( 'manage_shop_order_posts_custom_column' , 'custom_orders_list_column_content', 20, 2 );
    function custom_orders_list_column_content( $column, $post_id )
    {
        switch ( $column )
        {
            case 'my-column1' :
                // Get custom post meta data
                $my_var_one = get_post_meta( $post_id, 'child_class', true );
                if(!empty($my_var_one))
                    echo $my_var_one;
    
                // Testing (to be removed) - Empty value case
                else
                    echo '<small>(<em>no value</em>)</small>';
    
                break;
    
            case 'my-column2' :
                // Get custom post meta data
                $my_var_two = get_post_meta( $post_id, 'child_school', true );
                if(!empty($my_var_two))
                    echo $my_var_two;
    
                // Testing (to be removed) - Empty value case
                else
                    echo '<small>(<em>no value</em>)</small>';
    
                break;
        }
    }
    woocommerce-offtopic
Viewing 1 replies (of 1 total)
  • Hi @jakaerc

    I understand that you want to add a column with custom meta data to the Orders page at the admin end. You need to be able to sort the list by name.

    Kindly be informed that support for custom coding is beyond the scope of support we are able to provide in this forum. This particular forum is for questions that are related to the WooCommerce core features.

    For help with custom code we recommend the WooCommerce Developer Resources Portal.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Lastly, for direct assistance with code customizations, we recommend consulting with the WooCommerce Customizations Partners. https://woocommerce.com/customizations/

    Nevertheless, I’m going to leave this thread open for a bit to see if anyone is able to chime in to help you out here.

Viewing 1 replies (of 1 total)
  • The topic ‘Adding a column to woocomerce admin order page that can be sorted’ is closed to new replies.