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