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

时间:2020-04-24 17:58:11

标签: php wordpress woocommerce wp-admin

我想在edit属性表单中包含一个简单的内容。 (/wp-admin/edit.php?post_type=product&page=product_attributes&edit=55)

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

我想向“品牌”产品属性添加自定义表单。

这是我尝试过的(有和没有pa_的情况):

+

我只需要获取一些html才能显示在此编辑屏幕上的帮助。我的总体计划是将select标签添加到每个属性中,然后将一部分代码添加到variable.php中,检查属性的显示方式。

非常感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

使用以下挂钩,您可以根据自己的意愿在之前之后添加字段

https://github.com/woocommerce/woocommerce/blob/master/includes/admin/class-wc-admin-attributes.php#L200

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 );
相关问题