简体   繁体   English

将自定义字段添加到“编辑供应商”页面 - Woocommerce 产品供应商

[英]Add custom fields to "Edit vendor" page - Woocommerce product vendors

I'm trying to add fields to the “Edit Vendor” page of the product Vendors plugin of Woocommerce.我正在尝试将字段添加到 Woocommerce 的产品供应商插件的“编辑供应商”页面。

For a product I used:对于我使用的产品:

add_action('woocommerce_product_options_general_product_data','woocommerce_product_custom_fields');

function woocommerce_product_custom_fields()
{
    global $product_object;

    echo '<div class=" product_custom_field ">';

    // Custom Product Text Field
    woocommerce_wp_text_input(array(
        'id'          => 'data',
        'label'       => __('data:', 'woocommerce'),
        'placeholder' => '',
        'desc_tip'    => 'true'
    ));

}

To add custom woocommerce_wp_text_input, and then:添加自定义 woocommerce_wp_text_input,然后:

$product->update_meta_data("customField", sanitize_text_field($_POST['data']));

To set it.设置它。

Is there something similar for the Vendor edit page ?供应商编辑页面有类似的东西吗? Thanks for your help.谢谢你的帮助。

Are you referring to Woocommerce Product Vendor plugin ?您指的是Woocommerce 产品供应商插件吗?

Then you can add Custom Field to Edit Vendor page, by add following code.然后您可以通过添加以下代码将自定义字段添加到编辑供应商页面。

add_action('wcpv_product_vendors_edit_form_fields', 'edit_vendor_custom_fields', 10);

function edit_vendor_custom_fields($term) {
    $vendor_data = get_term_meta( $term->term_id, 'vendor_data', true );
    $custom_field = isset( $vendor_data['custom_field'] ) ? $vendor_data['custom_field'] : '';
    ?>
    <tr class="form-field">
        <th scope="row" valign="top"><label for="custom_field">Custom Field</label></th>
        <td>
            <input type="text" name="vendor_data[custom_field]" id="custom_field" value="<?php echo esc_attr($custom_field); ?>" />
        </td>
    </tr>
    <?php
}

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM