• Resolved _Sascha_

    (@_sascha_)


    Greetings,

    I build a plugin for WooCommerce and something seems really strange with one Action Hook and Filter in it. The Plugin itselfs is a product_configurator, and uses all Hooks and Filters without problems.

    Then I became the idea to alter the Admin Columns for the Products. (post-type: product) and doesn’t found the reason why a correct code doesnt work.

    add_filter('manage_product_posts_columns', 'my_table_head', 11, 2 );
    
    function my_table_head($columns) {
    	$columns['my_type']  = 'My Type';
        return $columns;
    }
    
    add_action( 'manage_product_posts_custom_column', 'my_table_content', 11, 2 );
    
    function my_table_content($column_name, $post_id) {
        if( $column_name == 'my_type' ) {
            echo 'test'
        }
    }

    This sample-code doesn’t have any effect there… and I searched myself half-insane for a solution. And then, just for fun i copied it to the functions.php of my themes and boommm…. it’s loaded.

    I can’t understand why. Why could it work in a theme functions.php, but not in a plugin? Do WooCommerce Plugins need a special permission or other code for this task? I’m really confused, because all other filter working wihout problems.

    Problem solved: While I build the plugin I followed a tip/rule to split frontend and backend hooks and actions. I forgot that, and so my mad-function couldn’t load because these hooks and files are only loaded for frontend tasks. Sometimes… You can’t see the forest for the trees.

  • The topic ‘Filter and Hook for Collumns only work with functions.php of theme, why?’ is closed to new replies.