[英]Add product attribute or custom field in woocommerce admin order page
[英]How do you add custom field to woocommerce product attribute
我想在编辑属性表单中包含一个简单的。 (/wp-admin/edit.php?post_type=product&page=product_attributes&edit=55)
这可能吗? 我在 SO 上找到的所有内容都与向产品或分类法添加字段有关,如果我没记错的话,产品属性与分类法不同。
我想为我的“品牌”产品属性添加一个自定义表单。
这是我尝试过的(有和没有 pa_):
add_action('pa_brand_edit_form_fields','msp_pa_brand_form_fields');
add_action('pa_brand_add_form_fields','msp_pa_brand_form_fields');
function msp_pa_brand_form_fields () {
?>
<tr class="form-field">
<th valign="top" scope="row">
<label for="display"><?php _e('Display Type', ''); ?></label>
</th>
<td>
<select name="display_type">
<option value="select">Select</option>
<option value="variation_image">Variation Image w/ label</option>
</select>
</td>
</tr>
<?php
}
我只需要帮助让一些 html 出现在这个编辑屏幕上。 我的总体计划是在每个属性中添加这个 select 标签,然后在变量中添加一段代码。php 检查属性是如何显示的。
任何帮助是极大的赞赏。
使用以下钩子,您可以根据自己的意愿在之前或之后添加一个字段
function action_woocommerce_before_edit_attribute_fields( ) {
?>
<tr class="form-field">
<th valign="top" scope="row">
<label for="display"><?php _e('Display Type', ''); ?></label>
</th>
<td>
<select name="display_type">
<option value="select">Select</option>
<option value="variation_image">Variation Image w/ label</option>
</select>
</td>
</tr>
<?php
}
add_action( 'woocommerce_before_edit_attribute_fields', 'action_woocommerce_before_edit_attribute_fields', 10, 0 );
function action_woocommerce_after_edit_attribute_fields( ) {
?>
<tr class="form-field">
<th valign="top" scope="row">
<label for="display"><?php _e('Display Type', ''); ?></label>
</th>
<td>
<select name="display_type">
<option value="select">Select</option>
<option value="variation_image">Variation Image w/ label</option>
</select>
</td>
</tr>
<?php
}
add_action( 'woocommerce_after_edit_attribute_fields', 'action_woocommerce_after_edit_attribute_fields', 10, 0 );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.