• Hello,
    I am using WooCommerce plugin for my online marketplace site.
    My site is multi-vendor marketplace for digital products.

    I have add one custom field on product submission in back-end, and it is work fine in back-end product submission.
    But I want to add same custom field in front-end product submission form.
    Here is the code I have added in themes functions.php file to display custom field in back-end.

    // Display Fields
    add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
    
    function woo_add_custom_general_fields() {
    
    		global $woocommerce, $post;
    		// Text Field
                    $playstore_url_text_field = woocommerce_wp_text_input(
            	                          array(
            		'id'          => 'playstore_url',
            		'label'       => __( 'App Play store URL', 'woocommerce' ),
            		'placeholder' => 'http://',
            		'desc_tip'    => 'true',
            		'description' => __( 'App Google Play store URL', 'woocommerce' )
            	)
            );
    }
    
    // Save Fields
    add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );
    function woo_add_custom_general_fields_save( $post_id ){
    
        // Text Field
    	$playstore_url_text_field = $_POST['playstore_url'];
    	if( !empty( $playstore_url_text_field ) ) {
    		update_post_meta( $post_id, 'playstore_url', esc_attr( $playstore_url_text_field ) );
        } else {
            update_post_meta( $post_id, 'playstore_url', '' );
    	}
    }

    Using above code, I have add one custom text field in back-end and it is work perfect with add, update and delete functionality.

    How can I add same custom text field in front-end?
    Here is my code for front-end text field.
    <input class="" type="text" name="playstore_url" value="<?php echo esc_attr( get_post_meta( get_the_ID(), 'playstore_url', $playstore_url_text_field ) ); ?>" />

    One thing, If I will add this custom field value from front-end then value should be added to that custom field in back-end and vice versa.

    Thanks in advance.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘WooCommerce product custom field on backend as well frontend’ is closed to new replies.