如何将自定义字段添加到 woocommerce 产品属性

How do you add custom field to woocommerce product attribute

我想在编辑属性表单中包含一个简单的。 (/wp-admin/edit.php?post_type=产品&页面=product_attributes&edit=55)

这可能吗?我在 SO 上发现的所有内容都与向产品或分类法添加字段有关,如果我没记错的话,产品属性与分类法不同。

我想在我的 "Brand" 产品属性中添加自定义表单。

这是我尝试过的方法(有和没有 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标签添加到每个属性中,然后在variable.php中添加一段代码来检查属性的显示方式。

非常感谢任何帮助。

With the following hooks you can add a field before or after, depending on your wishes

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 );