Dokan-lite: Repetable fields compatibility
-
Hello and thanks
I am building a multivendor site with Dokan-lite for 4 small teaching cooperatives. I have found this code for adding custom fields to the edit product form. It works well with simple fields, but with the pods repeatable one I don’t get the button to repeat, nor the date and time selection. Could you please tell to me how to solve it? I think that I have to load to the page some javascript, don’t I? Or maybe something else that you use with the fields to repeat them. Thanks
/*
* Adding extra field on New product popup/without popup form
*/
add_action( 'dokan_new_product_after_product_tags','new_product_field',10 );
function new_product_field(){ ?>
<div class="dokan-form-group custom-fields">
<!-- field format: date/time, repetable. name: horari -->
<input type="text" id="pods-form-ui-pods-meta-horari" name="pods-form-ui-pods-meta-horari" class="pods-form-ui-field pods-form-ui-field-type-datetime pods-form-ui-field pods-form-ui-field-type-time pods-form-ui-field-name-pods-meta-horari pods-validate pods-validate-required" value="">
</div>
<?php
}
/*
* Saving product field data for edit and update
*/
add_action( 'dokan_new_product_added','save_add_product_meta', 10, 2 );
add_action( 'dokan_product_updated', 'save_add_product_meta', 10, 2 );
function save_add_product_meta($product_id, $postdata){
if ( ! dokan_is_user_seller( get_current_user_id() ) ) {
return;
}
//field format: format: date/time, repetable. name: horari
if ( ! empty( $postdata['pods-form-ui-pods-meta-horari'] ) ) {
update_post_meta( $product_id, 'pods-form-ui-pods-meta-horari', $postdata['pods-form-ui-pods-meta-horari'] );
}
}
/*
* Showing field data on product edit page
*/
add_action('dokan_product_edit_after_product_tags','show_on_edit_page',99,2);
function show_on_edit_page($post, $post_id){
?>
<!-- field format: date/time, repetable. name: horari -->
<?php $new_field = get_post_meta( $post_id, 'pods-form-ui-pods-meta-horari', true ); ?>
<input type="hidden" name="pods-form-ui-pods-meta-horari" id="dokan-edit-product-id" value="<?php echo esc_attr( $post_id ); ?>"/>
<label for="pods-form-ui-pods-meta-horari" class="form-label">Horari</label>
<?php dokan_post_input_box( $post_id, 'pods-form-ui-pods-meta-horari', array( 'placeholder' => __( 'Text per horari', 'dokan-lite' ), 'value' => $new_field ) ); ?>
</div> <?php
}
// showing on single product page
add_action('woocommerce_single_product_summary','show_product_code',13);
function show_product_code(){
global $product;
if ( empty( $product ) ) {
return;
}
//field format: date/time, repetable. name: horari
$new_field = get_post_meta( $product->get_id(), 'pods-form-ui-pods-meta-horari', true );
if ( ! empty( $new_field ) ) {
?>
<span class="details"><?php echo esc_attr__( 'Horari:', 'dokan-lite' ); ?> <strong><?php echo esc_attr( $new_field ); ?></strong></span>
<?php
}
}Have a good day
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Dokan-lite: Repetable fields compatibility’ is closed to new replies.