问题
This is question have already been asked here How Add Custom Meta Fields to Dokan in New Product
But no one answered that question. What I am trying to achieve is following:
Need to display custom field in Dokan Vendor Dashboard, plugin author have answer with this "You have to customize Dokan plugin to add an extra field on the product upload form. Please open dokan-lite/templates/products/new-product.php and in this file, you have to add an extra field. As we do not provide support to customize our plugin for that reason, I am unable to provide more specific instruction :)"
I have created custom field already using Fields Factory Plugin and it's displaying fine in Add Single Product page.
But I am unable to add that field in Dokan Plugin screenshot below for the location.
回答1:
He had the same problem and he solved it in the following way.
In wp-content/plugins/dokan-pro/templates/products/product-edit.php
:
<div class="dokan-form-group">
<div class="dokan-input-group">
<span class="dokan-input-group-addon">Precio por: <?php echo get_post_meta( $post->ID, "wccaf_precio_por_", true ); ?></span>
<div class="dokan-w4">
<select class="wccaf-field " name="wccaf_precio_por_" wccaf-type="select" wccaf-pattern="mandatory" wccaf-mandatory="yes">
<option value="wccpf_none">Precio corresponde a :</option>
<option value="Caja">Caja</option>
<option value="mt2">mt2</option>
<option value="c/u">c/u</option>
<option value="Galón">Galón</option>
</select>
</div>
</div>
</div>
Then in wp-content/themes/you-template/funtions.php
add this:
add_action( 'woocommerce_process_product_meta', 'x_add_fields_save' );
add_action( 'dokan_process_product_meta', 'x_add_fields_save' );
add_action( 'dokan_new_product_added', 'x_add_fields_save' );
function x_add_fields_save( $post_id ){
// Number Field
$woocommerce_wccaf_precio_por_ = $_POST['wccaf_precio_por_'];
if( !empty( $woocommerce_wccaf_precio_por_) )
update_post_meta( $post_id, 'wccaf_precio_por_', esc_attr( $woocommerce_wccaf_precio_por_ ) );
}
I'm using another plugin to control the fields that is the wc field factory https://wordpress.org/plugins/wc-fields-factory/ that's why I take the abbreviation wccaf_ if you want to customize the select to not use another plugin this is another solution that I base https://wedevs.com/support/topic/adding-metadata-to-product-form/
回答2:
You need to override your dokan plugin templates. First, you need to create 'dokan' folder in the root of your active theme, after that, you need to find dokan template file in /plugins/dokan/templates/ and recreate it in your theme folder and add additional field. After that you need to save your new variable via update_user_meta function in functions.php
回答3:
By default, it is not possible but you can modify the Dokan product upload form to add custom taxonomies. You can override dokan-lite/templates/products
folder via child theme and then edit the necessary file :)
Now the rest of the process needs to be done by you. However, After adding the input filed you have to save the value of the field. On that place you have to use do_action( 'dokan_new_product_added', $product_id, $post_data );
this hook to save the field data.
When you will edit the product that time you have to use do_action( 'dokan_product_updated', $post_id );
to re-save.
来源:https://stackoverflow.com/questions/46630600/displaying-custom-select-field-in-dokan-vendor-dashboard