woocommerce - 为 woocommerce 产品选项卡上的自定义字段设置优先级
问题描述
当产品很简单时,我想在常规数据选项卡中添加两个自定义字段。但是,我希望这些自定义字段出现在列表顶部。
我已经尝试在钩子中设置优先级,但这不起作用。
所以我有以下内容:
function add_options_simple() {
global $woocommerce, $post;
$id = $post->ID;
$product = wc_get_product($id)->get_type();
if ($product == 'simple'){
woocommerce_wp_text_input(
array(
'id' => '_brand',
'label' => 'Brand',
'type' => 'text',
)
);
woocommerce_wp_text_input(
array(
'id' => '_EAN',
'label' => 'EAN:',
'type' => 'text',
)
);
}
}
add_action( 'woocommerce_product_options_general_product_data', 'add_options_simple',1,3 );
但没有成功。有什么建议么?
解决方案
无法将这些字段添加到顶部。正如你在这里看到的
但是您可以尝试使用 jQuery。试试下面的代码。
function add_options_simple() {
global $woocommerce, $post;
$id = $post->ID;
$product = wc_get_product($id)->get_type();
if ($product == 'simple'){ ?>
<div class="options_group brand_ean show_if_simple hidden">
<?php
woocommerce_wp_text_input(
array(
'id' => '_brand',
'label' => 'Brand',
'type' => 'text',
)
);
woocommerce_wp_text_input(
array(
'id' => '_EAN',
'label' => 'EAN:',
'type' => 'text',
)
);
?>
</div>
<script type="text/javascript">
var brand_ean = jQuery('.brand_ean')[0].outerHTML;
jQuery('.brand_ean').remove();
jQuery( brand_ean ).insertBefore('.options_group.pricing');
</script>
<?php }
}
add_action( 'woocommerce_product_options_general_product_data', 'add_options_simple', 1, 3 );
测试和工作
推荐阅读
- reactjs - react-native 中未触发方法
- azure - 如何使用我们添加到 Azure 函数中的 HTML 中的图像?
- java - 有没有办法在一个线程中通过 websocket 同步发送和接收消息
- python - 用于基于方面的情感分析的乌尔都语语言数据集
- azure - 如何在 Azure DevOps 发布管道中保存测试结果
- reactjs - Thunk 动作创建者派出另一个 thunk 动作创建者,但 typescript 抛出错误。我应该添加什么类型?
- java - 文件未上传到 Google 存储桶
- xpath - 排除某些特定元素的 xpath
- linux - 在 awk 命令行中使用 unix 命令处理字段
- python - 通过网络服务(例如 FLASK)在命令上运行 python gui