【发布时间】:2021-09-08 21:31:09
【问题描述】:
我想在 woocommerce 中的属性条款中创建一个自定义字段,使用 add_action(),我在网上搜索过,但在这个地方找不到任何钩子。
在这里我想添加我的自定义字段:
Woocommerce / 属性 / 配置术语 / 编辑术语
您知道我可以在这里使用哪些钩子来添加我的自定义字段吗? 还有一个钩子可以在表单发布后检查自定义字段?
这是我想要自定义字段的屏幕截图:
这里是我想要你使用的代码(我只需要正确的钩子(钩子1和钩子2):
function custom_field_categorie($term)
{
$term_id = $term->term_id;
$args = array
(
'id' => 'GRE_ID',
'label' => __('ID genre'),
'class' => '',
'desc_tip' => true,
'value' => get_term_meta($term_id, 'GRE_ID', true),
'custom_attributes' => array('readonly' => 'readonly'),
);
woocommerce_wp_text_input($args);
}
add_action('hook1', 'custom_field_categorie', 10, 1);
function custom_field_categorie_save($term_id)
{
if(!empty($_POST['GRE_ID']))
{
update_term_meta($term_id, 'GRE_ID', sanitize_text_field($_POST['GRE_ID']));
}
}
add_action('hook2', 'custom_field_categorie_save', 10, 1);
感谢您的帮助
【问题讨论】:
-
您好,请添加一些我们可以粘贴的内容,例如图片或描述您的问题的内容,而不仅仅是文字。另请向我们展示(代码)您已经尝试过的内容。
-
@Mr.Jo 感谢您的回答,我已经编辑了更多详细信息
标签: wordpress woocommerce hook