WCMp bundle is available at a slashed price

Grab It Now

Custom Product Data ( General Tab )

Custom Product Data ( General Tab )2019-02-22T04:29:15+00:00

General Marketplace Discussion (User’s interaction forum)

Custom Product Data ( General Tab ) Resolved

  • Author
    Posts
  • Ahmad
    Participant
    Post count: 5

    Hi, I’m trying to add a few field for product under general tab. Here is my code:

    In html-product-data-general.php :
    do_action('end_wcmp_fpm_products_manage', $product_id);

    In functions.php:

    function deluxe_field() {?>
    	<div>&nbsp;</div>
        <div class="form-group-row"> 
            <div class="form-group">
                <label class="control-label col-sm-3 col-md-3" for="deluxe_type"><?php echo __( 'Deluxe Image', 'woocommerce' ); ?></label>
                <div class="col-md-6 col-sm-9">
                    <div class="featured-img upload_image">
                        <a href="#" class="upload_image_button tips <?php echo $deluxe_img ? 'remove' : ''; ?>" <?php echo current_user_can( 'upload_files' ) ? '' : 'data-nocaps="true" '; ?>data-title="<?php esc_attr_e( 'Deluxe image', 'woocommerce' ); ?>" data-button="<?php esc_attr_e( 'Set deluxe image', 'woocommerce' ); ?>" rel="<?php echo esc_attr( $post->ID ); ?>">
                            <div class="upload-placeholder pos-middle">
                                <i class="wcmp-font ico-image-icon"></i>
                                <p><?php _e( 'Click to upload Image', 'dc-woocommerce-multi-vendor' );?></p>
                            </div>
                            <img src="<?php echo $deluxe_img ? esc_url( wp_get_attachment_image_src( $deluxe_img, 'medium' )[0] ) : esc_url( wc_placeholder_img_src() ); ?>" />
                            <input type="hidden" name="deluxe_img" class="upload_image_id" value="<?php echo esc_attr( $deluxe_img ); ?>" />
                        </a>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group-row"> 
            <div class="form-group">
                <label class="control-label col-sm-3 col-md-3" for="deluxe_price"><?php echo __( 'Deluxe Price', 'woocommerce' ); ?></label>
                <div class="col-md-6 col-sm-9">
                    <input type="text" id="deluxe_price" name="deluxe_price" class="form-control">
                </div>
            </div>
        </div>
    	<?php
    }

    and I add do_action('after_wcmp_fpm_meta_save', $new_product_id, $product_manager_form_data); in html-product-data-general.php. But those data didn’t save.

  • Tech Tycoon Debleena
    Keymaster
    Post count: 402

    Hi @ahmad, as per above code, it’s not clear means there is no function callback hook.So please share full code snippet or follow our code snippet to add new custom field in add product page.

  • Ahmad
    Participant
    Post count: 5

    Hi,
    I add code below in html-product-data-general.php
    do_action('end_wcmp_fpm_products_manage', $product_id);
    do_action('after_wcmp_fpm_meta_save', $new_product_id, $product_manager_form_data);

    and code below in my function.php

    add_action( 'end_wcmp_fpm_products_manage', 'deluxe_field' );
    function deluxe_field() {?>
    	<div>&nbsp;</div>
        <div class="form-group-row"> 
            <div class="form-group">
                <label class="control-label col-sm-3 col-md-3" for="deluxe_type"><?php echo __( 'Deluxe Image', 'woocommerce' ); ?></label>
                <div class="col-md-6 col-sm-9">
                    <div class="featured-img upload_image">
                        <a href="#" class="upload_image_button tips <?php echo $deluxe_img ? 'remove' : ''; ?>" <?php echo current_user_can( 'upload_files' ) ? '' : 'data-nocaps="true" '; ?>data-title="<?php esc_attr_e( 'Deluxe image', 'woocommerce' ); ?>" data-button="<?php esc_attr_e( 'Set deluxe image', 'woocommerce' ); ?>" rel="<?php echo esc_attr( $post->ID ); ?>">
                            <div class="upload-placeholder pos-middle">
                                <i class="wcmp-font ico-image-icon"></i>
                                <p><?php _e( 'Click to upload Image', 'dc-woocommerce-multi-vendor' );?></p>
                            </div>
                            <img src="<?php echo $deluxe_img ? esc_url( wp_get_attachment_image_src( $deluxe_img, 'medium' )[0] ) : esc_url( wc_placeholder_img_src() ); ?>" />
                            <input type="hidden" name="deluxe_img" class="upload_image_id" value="<?php echo esc_attr( $deluxe_img ); ?>" />
                        </a>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group-row"> 
            <div class="form-group">
                <label class="control-label col-sm-3 col-md-3" for="deluxe_price"><?php echo __( 'Deluxe Price', 'woocommerce' ); ?></label>
                <div class="col-md-6 col-sm-9">
                    <input type="text" id="deluxe_price" name="deluxe_price" class="form-control">
                </div>
            </div>
        </div>
    	<?php
    } 

    Vendor view

    Field I add was Deluxe Image and Deluxe price.
    The field is there but when I submit those field data not save.

    How do I save it? Please show me detailthe correct way.

  • Tech Tycoon Debleena
    Keymaster
    Post count: 402

    Hi @ahmad, as per above code, first of all, the above do_action is not core hook, you added it.

    Just use do_action( 'wcmp_afm_after_general_product_data' ) to addyour fields. and using do_action( 'wcmp_process_product_object', $product ); hook you can saved your values from $_POST data

  • Ahmad
    Participant
    Post count: 5

    Hi,

    Can I get more detail? I tried but $_POST data is empty.

  • Tech Tycoon Debleena
    Keymaster
    Post count: 402

    Hi @ahmad, can you please share a temporary admin, vendor and ftp access, so we can look into this.

    While sharing the access don’t forget to mark the response as private.

  • NerdySupportExpert Moumita
    Keymaster
    Post count: 2114

    Kindly reffer to this code snippet to save your data like this in your child theme. :

    function new_page22($product, $post)
    {
    if(!empty($post['deluxe_price']) && !empty($post['deluxe_img']))
        {
    
            $deluxe_price = $post['deluxe_price'];
            $product->update_meta_data( 'deluxe_price', $deluxe_price );
    
            $deluxe_img = $post['deluxe_img'];
            $product->update_meta_data( 'deluxe_img', $deluxe_img );
        }
    }
    add_action('wcmp_process_product_object','new_page22', 10, 2);
  • Ahmad
    Participant
    Post count: 5

    Hi,

    Thanks a lot. Now its working 🙂

  • NerdySupportExpert Moumita
    Keymaster
    Post count: 2114

    Great to know that @ahmad

The topic ‘Custom Product Data ( General Tab )’ is closed to new replies.