Skip to content
Advertisement

Add_filter to add new column to Woocommerce product attributes table (Attributes add / edit page)

I would like to add a new column to the Attributes table on the Attributes add / edit page within Woocommerce / WordPress admin, using the WordPress / PHP add_filter command.

As a reference, to add columns in WordPress admin to the Woocommerce All Products add / adit table, the following filter works:

add_filter( 'manage_edit-product_columns', 'add_product_column', 10, 1 )

The All Products page is:

wp-admin/edit.php?post_type=product

and I see the add_filter follows the pattern:

manage_edit-{POST_TYPE}_columns

I cannot find or work out what the filter should be to do the same on the Woocommerce Attributes add / edit page. The page URL for that is:

wp-admin/edit.php?post_type=product&page=product_attributes

I’ve experimented with various combinations using the working filter for the All Products page, but I am not clear how to use add_filter when URL contains both Post Type and Page.

I hope I have explained it clearly. I have searched a lot for the answer, both here and in Google, so if there is a duplicate, I genuinely have not seen anything close to what I’m looking for.

Thanks in advance!

Advertisement

Answer

You could, but i don’t recommend it, abuse the get text filter for this

something like this

add_filter('gettext', 'my_custom_column_function', 1, 2);

function my_custom_column_function($text, $domain=""){
 if($domain === 'woocommerce' && $text === 'Order by'){
   $text = $text . "</th><th>My Column Name";
 } else if($domain === 'woocommerce' && ($text === 'Name' || $text === 'Name (numeric)' || 
 $text === 'Term ID' || $text === 'Custom ordering')){
   // Some code here to create the output as text string
   $example = 1 + 2;
   $text = $text . "</td><td>" . $example;
 }
 return $text;
}

It is only possible to either put the column in front of or after the “Order By” column in this way and I don’t know what information is available in the code for using in the output, as this is a very hacky way to do thing I don’t recommend using this method

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement