customization – manage_shop_order_posts_custom_column() hook is Not working In Functions.php file in my WordPress active theme

Question

As I added the manage_shop_order_posts_custom_column() hook in the functions.php file But the custom column post data not showing on the shop_order page.

manage_edit-shop_order_columns Filter is working fine. But the manage_shop_order_posts_custom_column hook is Not working Can you please help. I don’t Find the reason also Don’t show Any Errors.

Below Is my Code:

//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_column2', 20 );
function custom_shop_order_column2($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'] = __( 'Title1','theme_domain');
            $reordered_columns['my-column2'] = __( 'Title2','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_content2',  100, 2 );
function custom_orders_list_column_content2( $column, $post_id )
{
    switch ( $column )
    {
        case 'my-column1' :
            // Get custom post meta data
            $my_var_one = get_post_meta( $post_id, '_the_meta_key1', 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, '_the_meta_key2', 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;
    }
}

0
Netizens Dev 6 months 2022-06-15T01:27:59-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse