I am using dokan plugin for a multivendor website, I want to add image upload custom field in the template
new-product.php, I used CMB2 plugin to create image upload custom field with WooCommerce like this
function themebox_metaboxes() {
// Start with an underscore to hide fields from custom fields list
$prefix = 'themebox_met_';
// Product Settings
$header_settings = new_cmb2_box( array(
'id' => 'Extra_settings',
'title' => esc_html__( 'Extra Settings', 'themebox' ),
'object_types' => array( 'product'), // Post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
) );
$header_settings->add_field( array(
'name' => esc_html__( 'Add Image Detail size 590x300 px', 'themebox' ),
'id' => $prefix . 'img_detail',
'type' => 'file'
) );
}
I want to add this custom image upload field in template form new-product.php and when save form in dokan
the image upload custom field update with an image added in dokan …..exactly like featured product image in WooCommerce
2
Answers
You can override the
new-product.php
andnew-product-single.php
file and then add your field on the product upload/edit file. To add new field for product edit/add the template you will have to add a new field in this template (Override via child-theme) – dokan-lite/templates/products/new-product-single.php. However, there are some other steps required to successfully save them.You need to modify the Dokan product upload template and then you have to add an extra field by overriding the template. 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.Thanks 🙂