Support » Plugin: WooCommerce » woocommerce product addon input – display in orders

  • I’ve got a tiny riddle / question. Using woocommerce and additional plugin called ‘WooCommerce Product Add-ons’ im adding additional values to the product order. Let’s say its called ‘author-value’.

    Additionaly i’m using below code to add new column in woocommerce order table:

    add_filter( 'manage_edit-shop_order_columns', 'MY_COLUMNS_FUNCTION' );
    function MY_COLUMNS_FUNCTION($columns){
        $new_columns = (is_array($columns)) ? $columns : array();
        unset( $new_columns['order_actions'] );
    
        //edit this for you column(s)
        //all of your columns will be added before the actions column
        $new_columns['for-author-value'] = 'Dla autora';
        //stop editing
    
        $new_columns['order_actions'] = $columns['order_actions'];
        return $new_columns;
    }
    
    add_action( 'manage_shop_order_posts_custom_column', 'MY_COLUMNS_VALUES_FUNCTION', 2 );
    function MY_COLUMNS_VALUES_FUNCTION($column){
        global $post;
        $data = get_post_meta( $post->ID );
    
        //start editing, I was saving my fields for the orders as custom post meta
        //if you did the same, follow this code
        if ( $column == 'for-author-value' ) {
            echo (isset($data['author-value']) ? $data['author-value'] : '');
        }
    
    }
    
    add_filter( "manage_edit-shop_order_sortable_columns", 'MY_COLUMNS_SORT_FUNCTION' );
    function MY_COLUMNS_SORT_FUNCTION( $columns ) {
        $custom = array(
            //start editing
    
            'for-author-value'    => 'MY_COLUMN_1_POST_META_ID'
    
            //stop editing
        );
        return wp_parse_args( $custom, $columns );
    }

    How to display properly value of my custom input (author-value) in that new column? I know for that purpose i need to change following line:

    ‘ if ( $column == ‘for-author-value’ ) {
    echo (isset($data[‘author-value’]) ? $data[‘author-value’] : ”);
    }’

    but i dont know how.. any ideas?

    https://wordpress.org/plugins/woocommerce/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘woocommerce product addon input – display in orders’ is closed to new replies.