简体   繁体   中英

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.

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:

$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 ?

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
}

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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