【问题标题】:WordPress WooCommerce Membership plan add column to listWordPress WooCommerce 会员计划将列添加到列表
【发布时间】:2017-11-29 09:36:30
【问题描述】:

我为 WooCommerce 找到了这 2 个过滤器来扩展会员计划列表:

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' ) );

我想添加一个带有要显示的会员计划 ID 的新列。 关于如何在functions.php中使用它的任何建议

【问题讨论】:

    标签: wordpress woocommerce hook-woocommerce add-filter woocommerce-memberships


    【解决方案1】:

    您找到了正确的过滤器manage_edit-wc_user_membership_columns - 它允许在会员计划中添加一列,例如:

    add_filter( 'manage_edit-wc_user_membership_columns', 'my_add' );
    function my_add( $columns ) {
    
        $columns['id_of_the_plan'] = 'Memberships plan id';
    
        return $columns;
    
    }
    

    在您当前的主题functions.php 文件或自定义插件中插入此代码后,该列就会出现。现在是时候向其中添加数据了。 manage_posts_custom_column 会帮忙的。

    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;
        }
    }
    

    原代码取自this example

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-03
      • 1970-01-01
      • 2018-06-08
      • 1970-01-01
      • 2014-12-20
      • 2016-07-26
      • 2020-06-18
      • 1970-01-01
      相关资源
      最近更新 更多