我想使用 Wordpress/PHP add_filter 命令在 Woocommerce/Wordpress 管理中的“属性添加/编辑”页面上的“属性”表中添加一个新列。
作为参考,要将 WordPress admin 中的列添加到 Woocommerce All Products add / adit 表,以下过滤器有效:
add_filter( 'manage_edit-product_columns', 'add_product_column', 10, 1 )
所有产品页面是:
wp-admin/edit.php?post_type=product
我看到 add_filter 遵循以下模式:
manage_edit-{POST_TYPE}_columns
我无法在 Woocommerce 属性添加/编辑页面上找到或计算出过滤器应该是什么来做同样的事情。该页面的 URL 是:
wp-admin/edit.php?post_type=product&page=product_attributes
我已经使用“所有产品”页面的工作过滤器尝试了各种组合,但是当 URL 包含帖子类型和页面时,我不清楚如何使用 add_filter。
我希望我已经解释清楚了。我在这里和谷歌中搜索了很多答案,所以如果有重复,我真的没有看到任何接近我正在寻找的东西。
提前致谢!
答案 0 :(得分:1)
我不认为这是可能的,我快速浏览了 woocommerce 的源代码。输出你所说的列表的函数位于includes/admin/class-wc-admin-attributes.php的第296行,输出的是静态列布局。
答案 1 :(得分:1)
你可以,但我不推荐它,为此滥用获取文本过滤器
类似的东西
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;
}
只能以这种方式将列放在“Order By”列的前面或后面,我不知道代码中有哪些信息可用于输出,因为这是一个非常我不推荐使用这种方法的hacky方式