Posting from the frontend mostly working - wordpress

I'm using this front end code to create a post. At the moment it does create a post but the only thing that works is the title.
I also have a custom metabox with some fields (more_info, priority and duedate and ) in my post as well but I'm not sure if I'm putting them in the array correctly. Note that in the backend those additional fields work just fine.
Here's my code:
<?php
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] )) {
if (isset ($_POST['title'])) {
$title = $_POST['title'];
} else {
echo 'Please enter a title';
}
if (isset ($_POST['description'])) {
$description = $_POST['description'];
}
// Add the content of the form to $post as an array
$post = array(
'post_title' => $title,
'post_content' => $description,
'more_info' => $more_info,
'priority' => $priority,
'duedate' => $duedate,
'post_category' => $_POST['cat'],
'post_status' => 'publish',
'post_type' => $_POST['post']
);
wp_insert_post($post);
}
do_action('wp_insert_post', 'wp_insert_post');
?>
<form action="" id="new_post" method="post">
<label for="title">Task Name </label>
<input type="text" id="title" name="title" value="" />
<label for="minfo">Additional information</label>
<textarea name="minfo" id="minfo" value=""></textarea>
<label>Due date</label>
<input type="text" id="duedate" name="duedate" />
<strong>Priority</strong>
<label><input type="radio" name="priority" value="low" id="low">Low</label>
<label><input type="radio" name="priority" value="normal" id="normal" checked>Normal</label>
<label><input type="radio" name="priority" value="high" id="high">High</label>
<label><input type="radio" name="priority" value="urgent" id="urgent">Urgent</label>
<input type="submit" name="submit" value="Add" />
<input type="hidden" name="cat" id="cat" value="<?php echo $cat_id = get_query_var('cat'); ?>" />
<input type="hidden" name="post_type" id="post_type" value="post" />
<input type="hidden" name="action" value="post" />
<?php wp_nonce_field( 'new-post' ); ?>
</form>
Any assistance would be awesome.

Okay, couple things:
It's not clear to me what you're trying to do here. Do you need users to have the ability to add the values submitted in this meta box to any post? If not, why not create a custom post type that you can tweak to your heart's content?
If the answer to #1 is yes, then you're still going to want to attach your save methods differently. Something like:
add_meta_box(
'my-custom-meta', // Unique ID
esc_html__('Custom Attributes', 'my_scope'), // Title
'my_custom_meta_box', // Callback function
'post', // Admin page (or post type)
'normal', // Context
'high' // Priority
);
function my_custom_meta_box( $object ) { ?>
<?php wp_nonce_field( 'my_custom_inner', 'my_custom_inner_nonce' ); ?>
<p>
<label for="minfo">Additional information</label>
<textarea name="minfo" id="minfo" value="<?php echo esc_attr( get_post_meta( $object->ID, 'minfo', true ) ); ?>"></textarea>
</p>
<p>
<label>Due date</label>
<input type="text" id="duedate" name="duedate" value="<?php echo esc_attr( get_post_meta( $object->ID, 'duedate', true ) ); ?>" />
</p>
<p>
<strong>Priority</strong>
<label><input type="radio" name="priority" value="low" id="low"<?php if ( get_post_meta( $object->ID, 'priority', true ) == 'low' ) { echo ' checked'; }?>>Low</label>
<label><input type="radio" name="priority" value="normal" id="normal"<?php if ( get_post_meta( $object->ID, 'priority', true ) == 'normal' ) { echo ' checked'; }?>>Normal</label>
<label><input type="radio" name="priority" value="high" id="high"<?php if ( get_post_meta( $object->ID, 'priority', true ) == 'high' ) { echo ' checked'; }?>>High</label>
<label><input type="radio" name="priority" value="urgent" id="urgent"<?php if ( get_post_meta( $object->ID, 'priority', true ) == 'urgent' ) { echo ' checked'; }?>>Urgent</label>
</p>
<?php }
function save_my_meta( $post_id ) {
// Check if our nonce is set.
if ( ! isset( $_POST['my_custom_inner_nonce'] ) )
return $post_id;
$nonce = $_POST['my_custom_inner_nonce'];
// Verify that the nonce is valid.
if ( ! wp_verify_nonce( $nonce, 'my_custom_inner' ) )
return $post_id;
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return $post_id;
// Check the user's permissions.
if ( $_REQUEST['post_type'] == 'post' ) {
if ( ! current_user_can( 'edit_post', $post_id ) )
return $post_id;
}
/* Cast the returned vaiables to an array for processing */
$my_meta['minfo'] = $_REQUEST['minfo'];
$my_meta['duedate'] = $_REQUEST['duedate'];
$my_meta['priority'] = $_REQUEST['priority'];
foreach ( $my_meta as $key => $value ) { // Cycle through the $events_meta array!
if(get_post_meta( $post_id, $key ) ) { // If the custom field already has a value
update_post_meta( $post_id, $key, sanitize_text_field( $value ) );
} else {
add_post_meta( $post_id, $key, sanitize_text_field ( $value ) );
}
if( !$value ) delete_post_meta( $post_id, $key ); // Delete if blank
}
}
add_action( 'save_post', 'save_my_meta' );

Related

Code for woocommerce terms and conditions checkbox in registration form appears inverted

I have copied the php code to display a 'terms and conditions' checkbox on the registration page but it appears inverted and I don't know why.
// Add term and conditions check box on registration form
add_action( 'woocommerce_register_form', 'add_terms_and_conditions_to_registration', 20);
function add_terms_and_conditions_to_registration() {
if ( wc_get_page_id( 'terms' ) > 0 && is_account_page() ) {
?>
<p class="form-row terms wc-terms-and-conditions">
<label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox">
<input type="checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" name="terms" <?php checked( apply_filters( 'woocommerce_terms_is_checked_default', isset( $_POST['terms'] ) ), true ); ?> id="terms" /> <span><?php printf( __( 'I’ve read and accept the terms & conditions', 'woocommerce' ), esc_url( wc_get_page_permalink( 'terms' ) ) ); ?></span> <span class="required">*</span>
</label>
<input type="hidden" name="terms-field" value="1" />
</p>
<?php
}
}
// Validate required term and conditions check box
add_action( 'woocommerce_register_post', 'terms_and_conditions_validation', 20, 3 );
function terms_and_conditions_validation( $username, $email, $validation_errors ) {
if ( ! isset( $_POST['terms'] ) )
$validation_errors->add( 'terms_error', __( 'Terms and condition are not checked!',
'woocommerce' ) );
return $validation_errors;
}
inverted text

WordPress Media library not showing old images in Gridview, list view shows images

I have create one script to insert custom field image for all categories and database entry is fine.
Now, when I go to Media library it only loads my latest images, old images are not showing. Spinner continue rotation and Ajax call goes infinite.
There are many reasons to fail older image loads. Please turn on Debug Mode and check Debug Log and share the information here so we can help you.
<?php
add_action( 'business_add_form_fields', 'add_category_image', 10, 2 );
add_action( 'created_business', 'save_category_image', 10, 2 );
add_action( 'business_edit_form_fields','update_category_image', 10, 2 );
add_action( 'edited_business','updated_category_image', 10, 2 );
add_action( 'admin_enqueue_scripts', 'load_media');
add_action( 'admin_footer', 'add_script');
function load_media() {
if( ! isset( $_GET['taxonomy'] ) || $_GET['taxonomy'] != 'business' ) {
return;
}
wp_enqueue_media();
}
function add_category_image( $taxonomy ) { ?>
<div class="form-field term-group">
<label for="showcase-taxonomy-extra-detail-id"><?php _e( 'Business Extra Details', 'launchpm' ); ?></label>
<input type="text" id="showcase-taxonomy-extra-detail-id" name="showcase-taxonomy-extra-detail-id" class="" value="">
</div>
<div class="form-field term-group">
<label for="showcase-taxonomy-image-id"><?php _e( 'Image', 'launchpm' ); ?></label>
<input type="hidden" id="showcase-taxonomy-image-id" name="showcase-taxonomy-image-id" class="custom_media_url" value="">
<div id="category-image-wrapper"></div>
<p>
<input type="button" class="button button-secondary showcase_tax_media_button" id="showcase_tax_media_button" name="showcase_tax_media_button" value="<?php _e( 'Add Image', 'launchpm' ); ?>" />
<input type="button" class="button button-secondary showcase_tax_media_remove" id="showcase_tax_media_remove" name="showcase_tax_media_remove" value="<?php _e( 'Remove Image', 'launchpm' ); ?>" />
</p>
</div>
<?php }
/**
* Edit the form field
* #since 1.0.0
*/
function update_category_image( $term, $taxonomy ) { ?>
<tr class="form-field term-group-wrap">
<th scope="row">
<label for="showcase-taxonomy-extra-detail-id"><?php _e( 'Business Extra Details', 'launchpm' ); ?></label>
</th>
<td>
<?php $extra_detail = get_term_meta( $term->term_id, 'showcase-taxonomy-extra-detail-id', true ); ?>
<input type="text" id="showcase-taxonomy-extra-detail-id" name="showcase-taxonomy-extra-detail-id" value="<?php echo $extra_detail ; ?>">
</td>
</tr>
<tr class="form-field term-group-wrap">
<th scope="row">
<label for="showcase-taxonomy-image-id"><?php _e( 'Image', 'launchpm' ); ?></label>
</th>
<td>
<?php $image_id = get_term_meta( $term->term_id, 'showcase-taxonomy-image-id', true ); ?>
<input type="hidden" id="showcase-taxonomy-image-id" name="showcase-taxonomy-image-id" value="<?php echo esc_attr( $image_id ); ?>">
<div id="category-image-wrapper">
<?php if( $image_id ) { ?>
<?php echo wp_get_attachment_image( $image_id, 'thumbnail' ); ?>
<?php } ?>
</div>
<p>
<input type="button" class="button button-secondary showcase_tax_media_button" id="showcase_tax_media_button" name="showcase_tax_media_button" value="<?php _e( 'Add Image', 'showcase' ); ?>" />
<input type="button" class="button button-secondary showcase_tax_media_remove" id="showcase_tax_media_remove" name="showcase_tax_media_remove" value="<?php _e( 'Remove Image', 'showcase' ); ?>" />
</p>
</td>
</tr>
<?php }
/**
* Save the form field
* #since 1.0.0
*/
function save_category_image( $term_id, $tt_id ) {
if( isset( $_POST['showcase-taxonomy-image-id'] ) && '' !== $_POST['showcase-taxonomy-image-id'] ){
add_term_meta( $term_id, 'showcase-taxonomy-image-id', absint( $_POST['showcase-taxonomy-image-id'] ), true );
}
if( isset( $_POST['showcase-taxonomy-extra-detail-id'] ) && '' !== $_POST['showcase-taxonomy-extra-detail-id'] ){
add_term_meta( $term_id, 'showcase-taxonomy-extra-detail-id', $_POST['showcase-taxonomy-extra-detail-id'] , true );
}
}
/**
* Update the form field value
* #since 1.0.0
*/
function updated_category_image( $term_id, $tt_id ) {
if( isset( $_POST['showcase-taxonomy-image-id'] ) && '' !== $_POST['showcase-taxonomy-image-id'] ){
update_term_meta( $term_id, 'showcase-taxonomy-image-id', absint( $_POST['showcase-taxonomy-image-id'] ) );
} else {
update_term_meta( $term_id, 'showcase-taxonomy-image-id', '' );
}
if( isset( $_POST['showcase-taxonomy-extra-detail-id'] ) && '' !== $_POST['showcase-taxonomy-extra-detail-id'] ){
update_term_meta( $term_id, 'showcase-taxonomy-extra-detail-id', $_POST['showcase-taxonomy-extra-detail-id'] );
} else {
update_term_meta( $term_id, 'showcase-taxonomy-extra-detail-id', '' );
}
}
/**
* Enqueue styles and scripts
* #since 1.0.0
*/
function add_script() {
if( ! isset( $_GET['taxonomy'] ) || $_GET['taxonomy'] != 'business' ) {
return;
} ?>
<script> jQuery(document).ready( function($) {
_wpMediaViewsL10n.insertIntoPost = '<?php _e( "Insert", "showcase" ); ?>';
function ct_media_upload(button_class) {
var _custom_media = true, _orig_send_attachment = wp.media.editor.send.attachment;
$('body').on('click', button_class, function(e) {
var button_id = '#'+$(this).attr('id');
var send_attachment_bkp = wp.media.editor.send.attachment;
var button = $(button_id);
_custom_media = true;
wp.media.editor.send.attachment = function(props, attachment){
if( _custom_media ) {
$('#showcase-taxonomy-image-id').val(attachment.id);
$('#category-image-wrapper').html('<img class="custom_media_image" src="" style="margin:0;padding:0;max-height:100px;float:none;" />');
$( '#category-image-wrapper .custom_media_image' ).attr( 'src',attachment.url ).css( 'display','block' );
} else {
return _orig_send_attachment.apply( button_id, [props, attachment] );
}
}
wp.media.editor.open(button); return false;
});
}
ct_media_upload('.showcase_tax_media_button.button');
$('body').on('click','.showcase_tax_media_remove',function(){
$('#showcase-taxonomy-image-id').val('');
$('#category-image-wrapper').html('<img class="custom_media_image" src="" style="margin:0;padding:0;max-height:100px;float:none;" />');
});
$(document).ajaxComplete(function(event, xhr, settings) {
var queryStringArr = settings.data.split('&');
if( $.inArray('action=add-tag', queryStringArr) !== -1 ){
var xml = xhr.responseXML;
$response = $(xml).find('term_id').text();
if($response!=""){
// Clear the thumb image
$('#category-image-wrapper').html('');
}
}
});
});
</script>
<?php }

How to add table to custom post type as custom field in wordpress

Hi I have tried Tablepress, wp_table_reloaded plugins. I feel that it will be really complicated for naive user to add table by adding shortcode to each custom post's content also there are so many custom posts in the websiste. Actually I want that table should be added to each custom post type as we add custom fields to each custom post type,then simply adding value to each field. Please help me!!!
Take a look at the add_meta_box function:
http://codex.wordpress.org/Function_Reference/add_meta_box
Here's the code I used in a recent project, I believe you should be able to adapt the meta box to add a table.
add_action( 'admin_menu', 'create_meta_boxes' );
function create_meta_boxes() {
add_meta_box( 'author_info', 'Auteur info', 'author_info_meta_box', 'portfolio', 'normal');
}
function author_info_meta_box( $object, $box ) { ?>
<p>
<label for="auteur-meta">Auteur</label><br />
<input type="text" name="auteur-meta" id="auteur-meta" style="width:100%;" value="<?php echo wp_specialchars( get_post_meta( $object->ID, 'Auteur', true ), 1 ); ?>" />
</p>
<p>
<label for="auteur-quote-meta">Quote auteur</label><br />
<input type="text" name="auteur-quote-meta" id="auteur-quote-meta" style="width:100%;" value="<?php echo wp_specialchars( get_post_meta( $object->ID, 'Auteur Quote', true ), 1 ); ?>" />
</p>
<p>
<label for="auteurBioMeta">Biografie auteur</label><br />
<?php $settings = array(
'media_buttons' => false,
'textarea_rows' => 6
); ?>
<?php wp_editor( wp_specialchars( get_post_meta( $object->ID, 'Auteur Biografie', true ), 1 ), 'auteurBioMeta' , $settings); ?>
</p>
<p>
<label for="order-mail-meta">E-mail voor bestellingen</label><br />
<input type="text" name="order-mail-meta" id="order-mail-meta" style="width:100%;" value="<?php echo wp_specialchars( get_post_meta( $object->ID, 'Order Mail', true ), 1 ); ?>" />
</p>
<?php }
//Insert values on save
add_action( 'save_post', 'save_post', 10, 2 );
function save_post( $post_id, $post ) {
if ( !current_user_can( 'edit_post', $post_id ) )
return $post_id;
update_post_meta( $post_id, 'Auteur', stripslashes( $_POST['auteur-meta'] ) );
update_post_meta( $post_id, 'Auteur Biografie', stripslashes( $_POST['auteurBioMeta'] ) );
update_post_meta( $post_id, 'Auteur Quote', stripslashes( $_POST['auteur-quote-meta'] ) );
update_post_meta( $post_id, 'Order Mail', stripslashes( $_POST['order-mail-meta'] ) );
}

Custom Post Type ID Issue - When Querying Other Post Types

I have quite a complex problem to solve which has baffled me for the last day or so.
Basically, I have two custom post types 'Sessions' and 'Recipes'. These are showing fine in the backend of WordPress.
Attached to the session are several meta boxes, 'Introduction Video', 'Session video', 'Goals', 'Fitness Level' and 'Featured Recipes'.
The 'Featured Recipes' meta box is special, as in it queries the WordPress database to get all posts within the 'recipe' custom post type and then use these values to populate a select box.
Now as you can see from the screen shot attached, the select box for the recipe custom post type is pulling through the correct items and ID's, and it also saves the data and pulls back the correct selection and associates it with the correct post ID for the 'session' post type. Great!
The problem arises with the other fields within the post, they seem to be using the first recipe ID as the value for pulling through the data for each field, rather than the 'session' custom post type ID.
Now I can get this to work by writing various while loops based on specific query arguments but that creates another issue. The data is saved in the correct place but it uses the first 'session' cpt ID to pull back the data for all posts.
Now, I believe it is something to do with the 'recipe' meta box creation, as as soon as you remove this function and it's related functions from the functions.php file, everything works as it should.
I think I should be using for loops instead of while loops, I'm going to try this now.
Hopefully some of you PHP gurus out there will be able to point me in the right direction. I've included both my functions.php file and a screen shot from the admin. Cheers.
<?php
add_action( 'init', 'tfp_session_cpt' );
function tfp_session_cpt() {
register_post_type( 'session',
array(
'labels' => array(
'name' => __( 'Sessions' ),
'singular_name' => __( 'Session' )
),
'public' => true,
'has_archive' => true,
)
);
}
add_action( 'init', 'tfp_recipe_cpt' );
function tfp_recipe_cpt() {
register_post_type( 'recipe',
array(
'labels' => array(
'name' => __( 'Recipes' ),
'singular_name' => __( 'Recipe' )
),
'public' => true,
'has_archive' => true,
)
);
}
/*add_action( 'init', 'tfp_tip_cpt' );
function tfp_tip_cpt() {
register_post_type( 'tip',
array(
'labels' => array(
'name' => __( 'Tips' ),
'singular_name' => __( 'Tip' )
),
'public' => true,
'has_archive' => true,
)
);
}*/
add_action( 'add_meta_boxes', 'tfp_add_introduction_video' );
add_action( 'add_meta_boxes', 'tfp_add_session_video' );
add_action( 'add_meta_boxes', 'tfp_add_goals' );
add_action( 'add_meta_boxes', 'tfp_add_levels' );
add_action( 'add_meta_boxes', 'tfp_add_recipes' );
/*add_action( 'add_meta_boxes', 'tfp_add_tips' );*/
add_action( 'save_post', 'tfp_save_introduction_video');
add_action( 'save_post', 'tfp_save_session_video');
add_action( 'save_post', 'tfp_save_goals');
add_action( 'save_post', 'tfp_save_levels');
add_action( 'save_post', 'tfp_save_recipes');
/*add_action( 'save_post', 'tfp_save_tips');*/
function tfp_add_introduction_video() {
add_meta_box('tfp_introduction_video', 'Introduction Video', 'tfp_introduction_video_html', 'session');
}
function tfp_add_session_video() {
add_meta_box('tfp_session_video', 'Session Video', 'tfp_session_video_html', 'session');
}
function tfp_add_goals() {
$types = array ('session');
foreach ($types as $type) {
add_meta_box('tfp_goals', 'Goals', 'tfp_goals_html', $type);
}
}
function tfp_add_levels() {
add_meta_box('tfp_levels', 'Fitness Levels', 'tfp_levels_html', 'session');
}
function tfp_add_recipes() {
add_meta_box('tfp_recipes', 'Select a Featured Recipe', 'tfp_recipes_html', 'session', 'side');
}
function tfp_add_tips() {
add_meta_box('tfp_tips', 'Tips', 'tfp_tips_html', 'session', 'side');
}
function tfp_introduction_video_html($post) {
// Nonce field for some validation
wp_nonce_field( plugin_basename( __FILE__ ), 'session' );
global $post;
$introductionVideo = get_post_meta( $postID, 'introduction_video_embed_code', true );
echo $post->ID;
?>
<label for="introduction_video_embed_code">YouTube Embed Code</label>
<textarea class="large-text code" id="introduction_video_embed_code" name="introduction_video_embed_code" value="<?php echo $introductionVideo; ?>"><?php echo get_post_meta( $post->ID, 'introduction_video_embed_code', true ); ?></textarea>
<?php }
function tfp_session_video_html($post) {
// Nonce field for some validation
wp_nonce_field( plugin_basename( __FILE__ ), 'session' );
global $post;
$sessionVideo = get_post_meta( $post->ID, 'session_video_embed_code', true ); ?>
<?php echo $post->ID; ?>
<label for="session_video_embed_code">YouTube Embed Code</label>
<textarea class="large-text code" id="session_video_embed_code" name="session_video_embed_code" value="<?php echo $sessionVideo; ?>"><?php echo $sessionVideo; ?></textarea>
<?php }
function tfp_goals_html($post) {
// Nonce field for some validation
wp_nonce_field( plugin_basename( __FILE__ ), 'session' );
$goals = get_post_meta( $post->ID, 'goals', true ); ?>
<?php echo $post->ID; ?>
<label for="weight_loss">
<input type="checkbox" name="goal[]" id="weight_loss" value="Weight Loss" <?php if (in_array('Weight Loss', $goals)) echo "checked='checked'"; ?> />
<?php _e("Weight Loss"); ?>
</label>
<br />
<label for="improve_fitness">
<input type="checkbox" name="goal[]" id="improve_fitness" value="Improve Fitness" <?php if (in_array('Improve Fitness', $goals)) echo "checked='checked'"; ?> />
<?php _e("Improve Fitness"); ?>
</label>
<br />
<label for="improve_health">
<input type="checkbox" name="goal[]" id="improve_health" value="Improve Health" <?php if (in_array('Improve Health', $goals)) echo "checked='checked'"; ?> />
<?php _e("Improve Health"); ?>
</label>
<br />
<?php }
function tfp_levels_html($post) {
// Nonce field for some validation
wp_nonce_field( plugin_basename( __FILE__ ), 'session' );
$levels = get_post_meta( $post->ID, 'levels', true ); ?>
<?php echo $post->ID; ?>
<label for="beginner">
<input type="checkbox" name="level[]" id="beginner" value="Beginner" <?php if (in_array('Beginner', $levels)) echo "checked='checked'"; ?> />
<?php _e("Beginner"); ?>
</label>
<br />
<label for="advanced">
<input type="checkbox" name="level[]" id="advanced" value="Advanced" <?php if (in_array('Advanced', $levels)) echo "checked='checked'"; ?> />
<?php _e("Advanced"); ?>
</label>
<br />
<?php }
function tfp_recipes_html($post) {
// Nonce field for some validation
wp_nonce_field( plugin_basename( __FILE__ ), 'session' );
global $post;
$recipes = get_post_meta( $post->ID, 'recipe_name', true );
$recipeArgs = array(
'post_type' => 'recipe'
);
$recipeQuery = new WP_Query($recipeArgs); ?>
<?php echo $post->ID; ?>
<select name="recipe_names" id="recipes">
<option value="null">Select a Featured Recipe</option>
<?php while ( $recipeQuery->have_posts() ) : $recipeQuery->the_post(); ?>
<option id="<?php echo $post->ID; ?>" value="<?php the_title(); ?>" <?php $title = get_the_title(); if($recipes == $title) echo "selected='selected'";?>><?php the_title(); ?></option>
<?php endwhile; ?>
</select>
<?php }
/*function tfp_tips_html($post) {
// Nonce field for some validation
wp_nonce_field( plugin_basename( __FILE__ ), 'session' );
global $post;
$tipArgs = array(
'post_type' => 'tip'
);
$tipQuery = new WP_Query($tipArgs); ?>
<?php echo $post->ID; ?>
<?php while ( $tipQuery->have_posts() ) : $tipQuery->the_post();
$tipID = 'tip_' . $post->ID;
$tips = get_post_meta( $post->ID, $tipID, true );?>
<?php echo $tipID; ?>
<label for="<?php echo $tipID; ?>">
<input type="checkbox" name="<?php echo $tipID; ?>" id="<?php echo $tipID; ?>" value="1" <?php if ($tips == 1) echo "checked='checked'"; ?> />
<?php the_title(); ?>
</label>
<br />
<?php endwhile;
}*/
function tfp_save_introduction_video($post_id) {
if ( !current_user_can( 'edit_post', $post_id ) ) { return false; }
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post_id;
}
update_post_meta($post_id, 'introduction_video_embed_code', $_POST['introduction_video_embed_code']);
}
function tfp_save_session_video($post_id) {
if ( !current_user_can( 'edit_post', $post_id ) ) { return false; }
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post_id;
}
update_post_meta($post_id, 'session_video_embed_code', $_POST['session_video_embed_code']);
}
function tfp_save_goals($post_id) {
if ( !current_user_can( 'edit_post', $post_id ) ) { return false; }
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post_id;
}
update_post_meta($post_id, 'goals', $_POST['goal']);
}
function tfp_save_levels($post_id) {
if ( !current_user_can( 'edit_post', $post_id ) ) { return false; }
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post_id;
}
update_post_meta($post_id, 'levels', $_POST['level']);
}
function tfp_save_recipes($post_id) {
if ( !current_user_can( 'edit_post', $post_id ) ) { return false; }
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post_id;
}
update_post_meta($post_id, 'recipe_name', $_POST['recipe_names']);
}
/*function tfp_save_tips($post) {
if ( !current_user_can( 'edit_post', $post_id ) ) { return false; }
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post_id;
}
if ( ! wp_verify_nonce( $_POST['custom_post_type'], plugin_basename(__FILE__) ) ) return;
global $post;
$tipArgs = array(
'post_type' => 'tip'
);
$tipQuery = new WP_Query($tipArgs);
while ( $tipQuery->have_posts() ) : $tipQuery->the_post();
$tipID = 'tip_' . $post->ID;
update_post_meta($post->ID, $tipID, $_POST[$tipID]);
endwhile;
}*/
// Extra user profile fields, specifically goal and fitness level checkboxes and radio buttons
add_action( 'show_user_profile', 'gaf_user_profile_fields' );
add_action( 'edit_user_profile', 'gaf_user_profile_fields' );
// Function to generate field HTML
function gaf_user_profile_fields( $user ) { ?>
<h3><?php _e("Goals and Fiteness Level", "blank"); ?></h3>
<table class="form-table">
<tr>
<th scope="row"><?php _e("Goals"); ?></th>
<td>
<fieldset>
<legend class="screen-reader-text">
<span><?php _e("Goals"); ?></span>
</legend>
<?php $single = true; ?>
<?php $goals = get_user_meta( $user->ID, 'goals', $single ); ?>
<label for="weight_loss">
<input type="checkbox" name="goal[]" id="weight_loss" value="Weight Loss" <?php if (in_array('Weight Loss', $goals)) echo "checked='checked'"; ?> />
<?php _e("Weight Loss"); ?>
</label>
<br />
<label for="improve_fitness">
<input type="checkbox" name="goal[]" id="improve_fitness" value="Improve Fitness" <?php if (in_array('Improve Fitness', $goals)) echo "checked='checked'"; ?> />
<?php _e("Improve Fitness"); ?>
</label>
<br />
<label for="improve_health">
<input type="checkbox" name="goal[]" id="improve_health" value="Improve Health" <?php if (in_array('Improve Health', $goals)) echo "checked='checked'"; ?> />
<?php _e("Improve Health"); ?>
</label>
<br />
</fieldset>
</td>
</tr>
<tr>
<?php $fitnessLevel = get_the_author_meta('fitness_level', $user->ID); ?>
<th scope="row"><?php _e("Fitness Level"); ?></th>
<td>
<fieldset>
<legend class="screen-reader-text">
<span><?php _e("Fitness Level"); ?></span>
</legend>
<input class="tog" type="radio" name="fitness_level" value="beginner" <?php if ($fitnessLevel == 'beginner') { ?>checked="checked"<?php } ?> /><label>Beginner</label>
<br />
<input class="tog" type="radio" name="fitness_level" value="advanced" <?php if ($fitnessLevel == 'advanced') { ?>checked="checked"<?php } ?> /><label>Advanced</label>
<br />
</fieldset>
</td>
</tr>
</table>
<?php }
// Function and actions to save the data from the fields
add_action( 'personal_options_update', 'save_gaf_user_profile_fields' );
add_action( 'edit_user_profile_update', 'save_gaf_user_profile_fields' );
function save_gaf_user_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }
update_user_meta( $user_id, 'goals', $_POST['goal'] );
update_user_meta( $user_id, 'fitness_level', $_POST['fitness_level'] );
}
?>
[EDIT]
I'm certainly getting closer with this function but it's not quite right as it's pulling through the same title.
function tfp_recipes_html($post) {
// Nonce field for some validation
wp_nonce_field( plugin_basename( __FILE__ ), 'session' );
$recipeArgs = array(
'post_type' => 'recipe'
);
$recipeQuery = get_posts($recipeArgs);
$recipeName = get_post_meta( $post->ID, 'recipe_name', true );
$recipeTitle[] = get_query_var('name');
echo $recipeTitle;
?>
<select name="recipe_names" id="recipes">
<option value="null">Select a Featured Recipe</option>
<?php foreach ( $recipeQuery as $recipe ) : setup_postdata($recipeQuery); ?>
<option id="<?php echo $recipe->ID; ?>" value="<?php echo $recipeTitle; ?>" <?php if($recipeName == $recipeTitle) echo "selected='selected'";?>><?php echo $recipeName; ?></option>
<?php endforeach; ?>
</select>
<?php }
OK Guys, I solved my issue using the following function.
function tfp_recipes_html($post) {
// Nonce field for some validation
wp_nonce_field( plugin_basename( __FILE__ ), 'session' );
global $post;
$recipeArgs = array(
'post_type' => 'recipe'
);
$recipes = get_posts($recipeArgs);
$recipeName = get_post_meta( $post->ID, 'recipe_name', true );
?>
<select name="recipe_names" id="recipes">
<option value="null">Select a Featured Recipe</option>
<?php foreach ( $recipes as $recipe ) : setup_postdata($recipe); ?>
<option id="<?php echo $recipe->ID; ?>" value="<?php $recipeTitle = $recipe->post_title; echo $recipeTitle; ?>" <?php if($recipeName == $recipeTitle) echo "selected='selected'";?>><?php echo $recipeTitle; ?></option>
<?php endforeach; ?>
</select>
<?php }
Though now I'm having another issue saving another custom metabox. The function to add the metabox is:
function tfp_tips_html($post) {
// Nonce field for some validation
wp_nonce_field( plugin_basename( __FILE__ ), 'session' );
global $post;
echo $post->ID;
$tipArgs = array(
'post_type' => 'tip'
);
$tips = get_posts($tipArgs);
$tipData = get_post_meta( $post->ID, $tipID, true );
foreach ( $tips as $tip ) : setup_postdata($tip);
$tipID = 'tip_' . $tip->ID; ?>
<label for="<?php echo $tipID; ?>">
<input type="checkbox" name="<?php echo $tipID; ?>" id="<?php echo $tipID; ?>" value="1" <?php if ($tipData == 1) echo "checked='checked'"; ?> />
<?php $tipTitle = $tip->post_title; echo $tipTitle; ?>
</label>
<br />
<?php endforeach;
}
Similar to the recipe function except this adds checkboxes each with a specific ID. Now the function to save it is:
function tfp_save_tips($post_id) {
if ( !current_user_can( 'edit_post', $post_id ) ) { return false; }
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post_id;
}
if ( ! wp_verify_nonce( $_POST['custom_post_type'], plugin_basename(__FILE__) ) ) return;
global $tipID;
add_post_meta($post->ID, $tipID, $_POST[$tipID], true) or update_post_meta($post->ID, $tipID, $_POST[$tipID]);
}
The problem is it's not saving the data, and is going to a blank page.
[EDIT]
OK, I have the data saving, as well as the checkboxes being checked correctly when you go back to the post. The only issue is it's posting to a blank page, which is no good. Needs to refresh the editor.
The function 'm now using is:
function tfp_save_tips($post_id) {
if ( !current_user_can( 'edit_post', $post_id ) ) { return false; }
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post_id;
}
if ( ! wp_verify_nonce( $_POST['session'], plugin_basename(__FILE__) ) ) return;
$tipArgs = array(
'post_type' => 'tip'
);
$tips = get_posts($tipArgs);
foreach ( $tips as $tip ) : setup_postdata($tip);
$tipID = 'tip_' . $tip->ID;
endforeach;
add_post_meta($post_id, $tipID, $_POST[$tipID], true) or update_post_meta($post_id, $tipID, $_POST[$tipID]);
}

How to create a woocommerce product from frontend form submission with form validation

Help Needed: I'm trying to create a form that will publish a wooCommerce product from front-end after following this question (Add Woocommerce Temporary product). The issue i'm facing now is that each time i submit the form i get this error (if i don't validate the form) Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\WOOstores\wp-includes\class.wp-styles.php:225) in C:\xampp\htdocs\WOOstores\wp-includes\pluggable.php on line 1219. I really would like to validate the form before submission and all i have been trying throws error related to WP_Error() below is the error i get when i try validating the form fields;
Warning: A non-numeric value encountered in C:\xampp\htdocs\WOOstores\wp-content\themes\adrianstores\woocommerce\myaccount\custom-orders.php on line 73 // Will indicate this line in my below code
Notice: Object of class WP_Error could not be converted to int in C:\xampp\htdocs\WOOstores\wp-includes\taxonomy.php on line 2297
Notice: Object of class WP_Error could not be converted to int in C:\xampp\htdocs\WOOstores\wp-includes\taxonomy.php on line 2297
Notice: Object of class WP_Error could not be converted to int in C:\xampp\htdocs\WOOstores\wp-includes\functions.php on line 3843
The product is being created with no problem, exactly how it should work ( if i don't validate the field), But i really want to validate the form but i'm having problems doing that. Below is the full code
<form method="post" action="">
<div class="form-group">
<div class="co-message"></div> <!--I want the validation message to show up here. Error & Success Validation-->
<label for="co_currency"><?php _e('Select Currency', 'text-domain'); ?></label>
<select class="form-control" id="co_currency" name="co_currency">
<option value="USD">USD</option>
<option value="RMB">RMB</option>
</select>
</div>
<div id="is_amazon" class="form-group is_amazon">
<label class="disInBlk" for="co_isAmazon"><?php _e('Is this an Amazon Product?','text-domain').':'; ?></label>
<input type="checkbox" name="co_isAmazon" id="co-isAmazon">
</div>
<div class="form-group">
<label for="co_productTitle"><?php _e('Product Name/Title','text-domain').':'; ?></label>
<input type="text" name="co_productTitle" class="form-control" id="co-productTitle" value="">
</div>
<div class="form-group">
<label for="co_productLink"><?php _e('Product Link','text-domain').':'; ?></label>
<input type="url" name="co_productLink" class="form-control" id="co-productLink" value="" placeholder="<?php _e('http://...', 'text-domain'); ?>">
</div>
<div class="form-group">
<label for="co_productPriceUSD"><?php _e('Product Price (USD)','text-domain').':'; ?></label>
<input type="number" name="co_productPriceUSD" class="form-control" id="co-productPriceUSD" value="0" step="0.01">
</div>
<div class="form-group">
<label for="co_productPriceNGN"><?php _e('Price Converted to NGN','text-domain').':'; ?></label>
<input type="number" name="co_productPriceNGN" class="form-control" id="co-productPriceNGN" value="0" readonly>
</div>
<div class="form-group">
<label for="co_productWeightKG"><?php _e('Weight (in KG)','text-domain').':'; ?></label>
<input type="number" name="co_productWeightKG" class="form-control" id="co-productWeightKG" value="" step="0.01">
</div>
<div class="form-group-btn">
<input type="submit" name="co_submit" class="form-control" id="co-submit" value="<?php echo _e('Place Your Order', 'text-domain'); ?>">
<input type="hidden" name="amountNGNUpdated" value="<?php echo $ExhangeRateUSD; ?>" id="CurrencyEX">
<input type="hidden" name="productCategoryUpdate" value="<?php echo $product_CO_terms; ?>">
</div>
</form>
PHP CODE which lives on the same page as the HTML form
function get_product_category_by_id( $category_id ) {
$term = get_term_by( 'id', $category_id, 'product_cat', 'ARRAY_A' );
return $term['name'];
}
$product_CO_terms = get_product_category_by_id( 15 );
$ProductTitle = $ProductURL = $ProductPriceValue = $ProductWeight = $ExchangeRate = "";
$errorpTitle = $errorpUrl= $errorpPrice = $errorpWeight = "";
if ( 'POST' == $_SERVER['REQUEST_METHOD'] ) {
$ExchangeRate = test_input($_POST['amountNGNUpdated']);
$ProductCategory = test_input($_POST['productCategoryUpdate']);
$ProductTitle = test_input($_POST['co_productTitle']);
$ProductURL = test_input($_POST['co_productLink']);
$ProductPriceValue = test_input($_POST['co_productPriceUSD']);
$ProductWeight = test_input($_POST['co_productWeightKG']);
/* THIS IS THE VALIDATION I DID, Which i dont know why it giving me the WP_Error() error
if ( empty($ProductTitle) ) {
$errorpTitle = __('Product Title is required. e.g. iPhone XS Max 16GB Silver', 'text-domain');
} else {
$ProductTitle = test_input($_POST['co_productTitle']);
}
if ( empty($ProductURL) ) {
$errorpUrl = __('Product URL is required. e.g. http://amazon.com/.../', 'text-domain');
} else {
$ProductURL = test_input($_POST['co_productLink']);
}
if ( empty($ProductPriceValue) || $ProductPriceValue == 0 ) {
$errorpPrice = __('Product Price is required.', 'text-domain');
} else {
$ProductPriceValue = test_input($_POST['co_productPriceUSD']);
}
if ( empty($ProductWeight) ) {
$errorpWeight = __('Product Weight is required. Weight unit should be in KG. You can use the Weight converter to convert your weight from lbs to kg.', 'text-domain');
} else {
$ProductWeight = test_input($_POST['co_productWeightKG']);
}*/
$NewProductPrice = $ProductPriceValue * $ExchangeRate; //This is the line 73 in which i was getting "A non-numeric value encountered"
//add them in an array
$post = array(
'post_status' => "publish",
'post_title' => $ProductTitle,
'post_type' => "product",
);
//create product for product ID
$product_id = wp_insert_post( $post, __('Cannot create product', 'izzycart-function-code') );
//type of product
wp_set_object_terms($product_id, 'simple', 'product_type');
//Which Category
wp_set_object_terms( $product_id, $product_CO_terms, 'product_cat' );
//add product meta
update_post_meta( $product_id, '_regular_price', $NewProductPrice );
update_post_meta( $product_id, '_price', $NewProductPrice );
update_post_meta( $product_id, '_weight', $ProductWeight );
update_post_meta( $product_id, '_store_product_uri', $ProductURL );
update_post_meta( $product_id, '_visibility', 'visible' );
update_post_meta( $product_id, '_stock_status', 'instock' );
//Add product to Cart
return WC()->cart->add_to_cart( $product_id );
What i would like to achieve with the above line return WC()->cart->add_to_cart( $product_id ); is to the add product to cart and redirect to cart. (using return give me a blank page but adds the product to get which makes the line not the best approach)
HELP I NEED;
1. How to make the form validate the field. If any field is empty, it should throw an error message at the top of the form. Where we have <div class="co-message"></div> and if all field passes the validation, it should throw a success message and proceed to creating the product.
2. After creating the product, it should add the product to cart and redirect to cart.
Thanks
I have been able to validate the form and create product has i wanted it to work. Just incase someone out there is facing similar issue and would want the answer to this question.
PHP CODE:
$ProductTitle = $ProductURL = $ProductPriceValue = $ProductShippingFee = $ProductWeight = "";
$error_pTitle = $error_pLink = $error_pPrice = $error_pShipping = $error_pweight = $success_call = "";
$productPrice_converted = "";
if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_REQUEST['co_submit']) ) {
$ExchangeRate = test_input($_POST['amountNGNUpdated']);
$ProductCategory = test_input($_POST['productCategoryUpdate']);
//Validate Product Title
if( empty( test_input($_POST['co_productTitle']) ) ) {
$error_pTitle = __('Product Title is required.', 'izzycart-function-code');
} else {
$ProductTitle = test_input($_POST['co_productTitle']);
}
//Validate Product URL
if( empty( test_input($_POST['co_productLink']) ) ) {
$error_pLink = __('Product Link is required.', 'izzycart-function-code');
} elseif ( !preg_match("#^https?://#", test_input($_POST['co_productLink']) ) ) {
$error_pLink = __('Please enter a url that starts with http:// or https://', 'izzycart-function-code');
} elseif ( isset($_POST['co_isAmazon']) == 1 && strpos($_POST['co_productLink'], 'amazon') === false ) {
$error_pLink = __('This is not an Amazon product. Please enter a valid amazon product.', 'izzycart-function-code');
} else {
$ProductURL = test_input($_POST['co_productLink']);
}
//Validate Product Price
if( empty( test_input($_POST['co_productPriceUSD']) ) || test_input($_POST['co_productPriceUSD']) == 0 ) {
$error_pPrice = __('Product Price is required.', 'izzycart-function-code');
} else {
$ProductPriceValue = test_input($_POST['co_productPriceUSD']);
}
//Validate Product Shipping
if( empty( test_input($_POST['co_productShippingFee']) ) ) {
$error_pShipping = __('Product Shipping fee is required.', 'izzycart-function-code');
} else {
$ProductShippingFee = test_input($_POST['co_productShippingFee']);
}
//Validate Product Weight
if( empty( test_input($_POST['co_productWeightKG']) ) || test_input($_POST['co_productWeightKG']) == 0 ) {
$error_pweight = __('Product Weight is required. Weight are in KG, use the weight converter to covert your lbs item to KG', 'izzycart-function-code');
} else {
$ProductWeight = round(test_input($_POST['co_productWeightKG']), 2);
}
if ($ProductPriceValue && $ExchangeRate ) {
$productPrice_converted = $ProductPriceValue * $ExchangeRate;
}
//No Errors Found
if ( $error_pTitle == "" && $error_pLink == "" && $error_pPrice == "" && $error_pShipping = "" $error_pweight == "" ) {
//add them in an array
$post = array(
'post_status' => "publish",
'post_title' => $ProductTitle,
'post_type' => "product",
);
//create product for product ID
$product_id = wp_insert_post( $post, __('Cannot create product', 'izzycart-function-code') );
//type of product
wp_set_object_terms($product_id, 'simple', 'product_type');
//Which Category
wp_set_object_terms( $product_id, $product_CO_terms, 'product_cat' );
//add product meta
update_post_meta( $product_id, '_regular_price', $productPrice_converted );
update_post_meta( $product_id, '_price', $productPrice_converted );
update_post_meta( $product_id, '_weight', $ProductWeight );
update_post_meta( $product_id, '_store_product_uri', $ProductURL );
update_post_meta( $product_id, '_visibility', 'visible' );
update_post_meta( $product_id, '_stock_status', 'instock' );
//Add Product To cart
$found = false;
if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
if ( $_product->get_id() == $product_id )
$found = true;
}
// if product not found, add it
if ( ! $found )
WC()->cart->add_to_cart( $product_id );
} else {
// if no products in cart, add it
WC()->cart->add_to_cart( $product_id );
}
//Sending Mail to Admin
//I installed an application hMailServer on my PC, because i was working on a local
//server (XAMPP) and it wont send out mail(), so i wasn't getting the success message
//as soon as i installed the application.. the mail() function worked and i get the success message
//and product is added to cart. Though didn't receive the mail in my inbox for reason i don't know but i
//will update this answer to confirm that the sending mail works. but the fact that i got the success message. it will work on a LIVE server
$message_bd = '';
unset($_POST['co_submit']);
foreach ($_POST as $key => $value) {
$message_bd .= "$key: $value\n";
}
$to = $AdminEmailFor_CO; //This is a custom field i created which stores the admin email in the database and can be changed from wordpress dashboard (you can write directly your admin email)
$subject = $SubjectFor_CO; // Same as the subject. They are stored the in options table
$header = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if ( mail($to, $subject, $message_bd ) ) {
//Success Message & reset Fields
$success_call = sprintf(__('Success: Product has been added to your cart. Click the view cart button below to proceed with your custom order. View Cart', 'izzycart-function-code'), wc_get_cart_url() );
$ProductTitle = $ProductURL = $ProductPriceValue = $ProductWeight = "";
$productPrice_converted = 0;
}
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
HTML FORM has been updated to the below
<form method="post" action="">
<div class="co-success"><?= $success_call ?></div>
<div class="form-group">
<label for="co_currency"><?php _e('Select Currency', 'izzycart-function-code'); ?></label>
<select class="form-control" id="co_currency" name="co_currency">
<option value="USD">USD</option>
<option value="RMB">RMB</option>
</select>
</div>
<div id="is_amazon" class="form-group is_amazon">
<label class="disInBlk" for="co_isAmazon"><?php _e('Is this an Amazon Product?','izzycart-function-code').':'; ?></label>
<input type="checkbox" name="co_isAmazon" id="co-isAmazon" <?php echo (isset($_POST['co_isAmazon'])?'checked="checked"':'') ?>>
</div>
<div class="form-group">
<label for="co_productTitle"><?php _e('Product Name/Title','izzycart-function-code').':'; ?></label>
<input type="text" name="co_productTitle" class="form-control" id="co-productTitle" value="<?= $ProductTitle ?>">
<div class="co-error"><?php echo $error_pTitle ?></div>
</div>
<div class="form-group">
<label for="co_productLink"><?php _e('Product Link','izzycart-function-code').':'; ?></label>
<input type="text" name="co_productLink" class="form-control" id="co-productLink" value="<?= $ProductURL ?>" placeholder="<?php _e('http://...', 'izzycart-function-code'); ?>">
<div class="co-error"><?php echo $error_pLink ?></div>
</div>
<div class="form-group">
<label for="co_productPriceUSD"><?php _e('Product Price (USD)','izzycart-function-code').':'; ?></label>
<input type="number" name="co_productPriceUSD" class="form-control" id="co-productPriceUSD" value="<?= $ProductPriceValue ?>" step="0.01">
<div class="co-error"><?php echo $error_pPrice ?></div>
</div>
<div class="form-group">
<label for="co_productShippingFee"><?php _e('Shipping Fee of Product/Item','izzycart-function-code').':'; ?></label>
<div class="co-desc"><?php echo __('N.B: If the product is FREE shipping from the store you\'re buying from, enter 0 as the shipping fee.', 'izzycart-function-code'); ?></div>
<input type="number" name="co_productShippingFee" class="form-control" id="co_productShippingFee" value="<?= $ProductShippingFee ?>" step="0.01">
<div class="co-error"><?php echo $error_pShipping ?></div>
</div>
<div class="form-group">
<label for="co_productPriceNGN"><?php _e('Product Price Converted to NGN','izzycart-function-code').':'; ?></label>
<input type="number" name="co_productPriceNGN" class="form-control" id="co-productPriceNGN" value="<?= $productPrice_converted ?>" readonly>
</div>
<div class="form-group">
<label for="co_productWeightKG"><?php _e('Weight (in KG)','izzycart-function-code').':'; ?></label>
<input type="number" name="co_productWeightKG" class="form-control" id="co-productWeightKG" value="<?= $ProductWeight ?>" step="0.001">
<div class="co-error"><?php echo $error_pweight ?></div>
</div>
<div class="form-group-btn">
<input type="submit" name="co_submit" class="form-control" id="co-submit" value="<?php echo _e('Place Your Order', 'izzycart-function-code'); ?>">
<input type="hidden" name="amountNGNUpdated" value="<?php echo $ExhangeRateUSD; ?>" id="CurrencyEX">
<input type="hidden" name="productCategoryUpdate" value="<?php echo $product_CO_terms; ?>">
</div>
</form>
The result looks like this
showing the validation

Resources