自定义 WooCommerce 简短描述 Metabox 标题
Customizing WooCommerce Short Description Metabox title
有人可以指导我如何 customize/change Wordpress 中的文本标签 - 我最近在我的 wordpress 上安装了 WooCommerce,需要更改 [=14= 上的标签 "Product Short Description" ] 页到别的东西。有没有办法完成这项工作?请参阅此图片以供参考:

借用 here
基本前提是您删除现有的 metabox,然后用新标题将其添加回来,但回调相同,这(碰巧)类似于 WooCommerce 对通常 "excerpt" 所做的元数据盒。 :
remove_meta_box( 'METABOX_ID', 'POST_TYPE', 'normal' );
add_meta_box('METABOX_ID', __('META BOX TITLE'), 'METABOX_CALLBACK', 'POST_TYPE', 'normal', 'high');
所以在这种情况下,您需要执行以下操作:
add_action( 'add_meta_boxes', 'so_39797888_rename_meta_boxes', 40 );
function so_39797888_rename_meta_boxes(){
remove_meta_box( 'postexcerpt', 'product', 'normal' );
add_meta_box( 'postexcerpt', __( 'This metabox is awesome', 'your-plugin' ), 'WC_Meta_Box_Product_Short_Description::output', 'product', 'normal' );
}
您需要优先级为 40,这样您的函数才会在 WooCommerce 添加其元数据框后出现。
To answer to your question: YES there is a working filter hook that can translate text by the internationalization functions (__()
,
_e()
, etc.)
这是这段代码:
add_filter( 'gettext', 'theme_domain_change_excerpt_label', 10, 2 );
function theme_domain_change_excerpt_label( $translation, $original )
{
if ( 'Product Short Description' == $original ) {
return 'My Product label';
}
return $translation;
}
此代码位于您的活动子主题(或主题)的 function.php 文件中或任何插件文件中。
代码已经过测试并且功能齐全。
参考文献:
有人可以指导我如何 customize/change Wordpress 中的文本标签 - 我最近在我的 wordpress 上安装了 WooCommerce,需要更改 [=14= 上的标签 "Product Short Description" ] 页到别的东西。有没有办法完成这项工作?请参阅此图片以供参考:
借用 here
基本前提是您删除现有的 metabox,然后用新标题将其添加回来,但回调相同,这(碰巧)类似于 WooCommerce 对通常 "excerpt" 所做的元数据盒。 :
remove_meta_box( 'METABOX_ID', 'POST_TYPE', 'normal' );
add_meta_box('METABOX_ID', __('META BOX TITLE'), 'METABOX_CALLBACK', 'POST_TYPE', 'normal', 'high');
所以在这种情况下,您需要执行以下操作:
add_action( 'add_meta_boxes', 'so_39797888_rename_meta_boxes', 40 );
function so_39797888_rename_meta_boxes(){
remove_meta_box( 'postexcerpt', 'product', 'normal' );
add_meta_box( 'postexcerpt', __( 'This metabox is awesome', 'your-plugin' ), 'WC_Meta_Box_Product_Short_Description::output', 'product', 'normal' );
}
您需要优先级为 40,这样您的函数才会在 WooCommerce 添加其元数据框后出现。
To answer to your question: YES there is a working filter hook that can translate text by the internationalization functions (
__()
,_e()
, etc.)
这是这段代码:
add_filter( 'gettext', 'theme_domain_change_excerpt_label', 10, 2 );
function theme_domain_change_excerpt_label( $translation, $original )
{
if ( 'Product Short Description' == $original ) {
return 'My Product label';
}
return $translation;
}
此代码位于您的活动子主题(或主题)的 function.php 文件中或任何插件文件中。
代码已经过测试并且功能齐全。
参考文献: