1

I found this 2 filters for WooCommerce to extend the membership plan list:

add_filter( 'manage_edit-wc_user_membership_columns', array( $this, 'customize_columns' ) );
add_filter( 'manage_edit-wc_user_membership_sortable_columns', array( $this, 'customize_sortable_columns' ) );

I want to add a new column with the memberships plan id to show. any suggestion on how to use that in the functions.php

mujuonly
  • 11,370
  • 5
  • 45
  • 75
web-e
  • 21
  • 2

1 Answers1

0

You found the correct filter manage_edit-wc_user_membership_columns – it allows to add a column in membership plans, example:

add_filter( 'manage_edit-wc_user_membership_columns', 'my_add' );
function my_add( $columns ) {

    $columns['id_of_the_plan'] = 'Memberships plan id';

    return $columns;

}

Once you insert this code in your current theme functions.php file or in a custom plugin, the column will appear. Now it is time to add the data to it. manage_posts_custom_column will help with it.

add_action( 'manage_posts_custom_column', 'my_id' );
function my_id( $column ) {
    if( $column == 'id_of_the_plan' ) {
        $m = wc_memberships_get_user_membership( get_the_ID() );
        echo $m->plan_id;
    }
}

The original code is taken from this example.

Misha Rudrastyh
  • 866
  • 10
  • 16