I'm trying to add a custom field to the dokan shipping settings... I've tried this code but it breaks the site.
add_filter( 'dokan_shipping_settings_form_top', 'extra_fields', 10, 2);
function extra_fields( $current_user, $profile_info ){
$seller_url= isset( $profile_info['seller_url'] ) ? $profile_info['seller_url'] : '';
?>
<div class="gregcustom dokan-form-group">
<label class="dokan-w3 dokan-control-label" for="setting_address">
<?php _e( 'Website', 'dokan' ); ?>
</label>
<div class="dokan-w5">
<input type="text" class="dokan-form-control input-md valid" name="seller_url" id="reg_seller_url" value="<?php echo $seller_url; ?>" />
</div>
</div>
<?php
}
//save the field value
add_action( 'dokan_store_profile_saved', 'save_extra_fields', 15 );
function save_extra_fields( $store_id ) {
$dokan_settings = dokan_get_store_info($store_id);
if ( isset( $_POST['seller_url'] ) ) {
$dokan_settings['seller_url'] = $_POST['seller_url'];
}
update_user_meta( $store_id, 'dokan_profile_settings', $dokan_settings );
}
// show on the store page
add_action( 'dokan_store_header_info_fields', 'save_seller_url', 10);
function save_seller_url($store_user){
$store_info = dokan_get_store_info( $store_user);
?>
<?php if ( isset( $store_info['seller_url'] ) && !empty( $store_info['seller_url'] ) ) { ?>
<i class="fa fa-globe"></i>
<?php echo esc_html( $store_info['seller_url'] ); ?>
<?php } ?>
<?php
}
I've tried to use 'dokan_shipping_settings_form_top' but it's not working. I am using the Dokan Regular Shipping (dashboard/settings/regular-shipping) rather than Zone Wise shipping.
Related
i have a cart icon on the header.When the page is scrolled this cart icon is floating in a fixed position.when hover over cart icon the cart contents like name price subtotal all are displaying.now when adding a product the cart count is updating correctly.nut cart contents are updating only after refresh.
code of cart in header.php
<li>
<a href="<?php echo get_template_directory_uri(); ?>/cart"
><i class="uil uil-shopping-cart-alt"></i>
<div>Cart</div></a
>
<span class="counter" id="cart-count"><?php
$cart_count = WC()->cart->get_cart_contents_count();
//echo sprintf ( _n( '%d', '%d', $cart_count ), $cart_count );
echo $cart_count;
?></span>
</li>
updating cart count code in functions.php
add_filter( 'woocommerce_add_to_cart_fragments', 'refresh_cart_count', 50, 1 );
function refresh_cart_count( $fragments ){
ob_start();
?>
<span class="counter" id="cart-count"><?php
$cart_count = WC()->cart->get_cart_contents_count();
//echo sprintf ( _n( '%d', '%d', $cart_count ), $cart_count );
echo $cart_count;
?></span>
<?php
$fragments['#cart-count'] = ob_get_clean();
return $fragments;
}
this is the code displaying when hovering over the cart
<div class="miniBasketContent"><div class="miniBasketHeader">Your basket</div><div class="items"><?php
global $woocommerce;
$items = $woocommerce->cart->get_cart();
$total = $woocommerce->cart->total;
foreach($items as $item => $values) { $_product = wc_get_product( $values['data']->get_id() );$getProductDetail = wc_get_product( $values['product_id'] );$price = get_post_meta($values['product_id'] , '_price', true);?><div class="item"><div class="image"><?php echo $getProductDetail->get_image();?></div><div class="info"><?php echo $_product->get_title();?></div><div class="price"><?php echo $price;?> AED</div></div><?php } ?></div><div class="miniBasketFooter"><div class="info"><div class="total"><span><?php echo $total; ?>AED</span>Total</div>Show basketGo to checkout</div></div></div>
what to do to update cart contents inside popup without reloading page.
You can try the below solution
demo_cart_link() Use this function where you want to display cart count HTML.
function.php
if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.3', '>=' ) ) {
add_filter( 'woocommerce_add_to_cart_fragments', 'demo_cart_link_fragment', 10 , 1 );
} else {
add_filter( 'add_to_cart_fragments', 'demo_cart_link_fragment', 10 , 1 );
}
if ( ! function_exists( 'demo_cart_link_fragment' ) ) {
function demo_cart_link_fragment( $fragments ) {
global $woocommerce;
ob_start();
demo_cart_link();
$fragments['a.cart-contents'] = ob_get_clean();
return $fragments;
}
}
if ( ! function_exists( 'demo_cart_link' ) ) {
function demo_cart_link() {
?>
<a class="cart-contents" href="<?php echo esc_url( wc_get_cart_url() ); ?>" title="<?php esc_attr_e( 'View your shopping cart', 'paperfig' ); ?>" type="button" data-toggle="modal">
<i class="fas fa-shopping-basket"></i>
<span class="cart-numbers"><?php echo wp_kses_data( sprintf( _n( ' %d', ' %d', WC()->cart->get_cart_contents_count(), 'paperfig' ), WC()->cart->get_cart_contents_count() ) );?></span>
</a>
<?php
}
}
I tried to change the variation on a product from select option to radio inputs. I duplicated on my child theme and updated the file variable.php. Made some changes, but when I try to add to cart, I have the error:
Invalid value posted for Size
This is the HTML from the Select version:
<select id="size" class="" name="attribute_size" data-attribute_name="attribute_size" data-show_option_none="yes">
<option value="">Choose an option</option>
<option value="15" class="attached enabled">15</option>
<option value="15.5" class="attached enabled">15.5</option>
<option value="16" class="attached enabled">16</option>
</select>
And this is the HTML with the radio inputs:
<ul class="product-size">
<li class="size">
<div>
<input style="display:none" type="radio" data-attribute-name="attribute_size" name="attribute_size" value="15" id="size_v_15">
<label for="size_v_15">15</label>
</div>
</li>
<li class="size">
<div>
<input style="display:none" type="radio" data-attribute-name="attribute_size" name="attribute_size" value="15.5" id="size_v_15.5" checked="checked">
<label for="size_v_15.5">15.5</label>
</div>
</li>
<li class="size">
<div>
<input style="display:none" type="radio" data-attribute-name="attribute_size" name="attribute_size" value="16" id="size_v_16">
<label for="size_v_16">16</label>
</div>
</li>
</ul>
As you can see, both name and value are the same in those two versions. However, I get the above error. In case you need the code I change in variable.php file, here it is:
<?php
function print_attribute_radio($checked_value, $value, $label, $name)
{
$checked = sanitize_title($checked_value) === $checked_value ? checked($checked_value, sanitize_title($value) , false) : checked($checked_value, $value, false);
$input_name = 'attribute_' . esc_attr($name);
$esc_value = esc_attr($value);
$id = esc_attr($name . '_v_' . $value);
$filtered_label = apply_filters('woocommerce_variation_option_name', $label);
printf('<div><input style="display:none" type="radio" data-attribute-name="%1$s" name="%1$s" value="%2$s" id="%3$s" %4$s><label for="%3$s">%5$s</label></div>', $input_name, $esc_value, $id, $checked, $filtered_label);
}
if (sanitize_title($attribute_name) == 'size'):
$sanitized_name = sanitize_title($attribute_name);
if (isset($_REQUEST['attribute_' . $sanitized_name])) {
$checked_value = $_REQUEST['attribute_' . $sanitized_name];
}
elseif (isset($selected_attributes[$sanitized_name])) {
$checked_value = $selected_attributes[$sanitized_name];
}
else {
$checked_value = '';
}
?>
<h3>Choose Your Size</h3>
<ul class="product-size">
<?php
foreach($options as $option) {
echo '<li class="size">';
print_attribute_radio($checked_value, $option, $option, $sanitized_name);
echo '</li>';
} ?>
</ul>
<script type="text/javascript">
jQuery('.product-size > li').click(function(e) {
jQuery('.product-size > li').removeClass('size-selected');
jQuery(this).addClass('size-selected');
var option_id = jQuery(this).find("input").attr("checked",true);
});
</script>
<?php endif; ?>
I add your code to standard woocommerce template variable.php
The main goal here is to take request parametrs that woocommece standard select give to variations_form and replace it with our custom parametrs in hidden inputs.
It a dirty trick, cos some standart woocommerce behavior will be not work and you need more code to return it, but you already can properly add product to your cart.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
global $product;
// get arr as varition id - value and vaiation attr name - key
$product_variations_arr = $product->get_available_variations();
$varitions_id_value_arr = [];
foreach ($product_variations_arr as $variation_arr) {
$varitions_id_value_arr[ current( $variation_arr['attributes'] ) ] = $variation_arr['variation_id'];
}
$attribute_keys = array_keys( $attributes );
do_action( 'woocommerce_before_add_to_cart_form' ); ?>
<?php
function print_attribute_radio($checked_value, $value, $label, $name, $varitions_id_value_arr)
{
$checked = sanitize_title($checked_value) === $checked_value ? checked($checked_value, sanitize_title($value) , false) : checked($checked_value, $value, false);
$input_name = 'attribute_' . esc_attr($name);
$esc_value = esc_attr($value);
$id = esc_attr($name . '_v_' . $value);
$filtered_label = apply_filters('woocommerce_variation_option_name', $label);
printf('<div><input type="radio" data-variation-id="%6$s" data-attribute-name="%1$s" name="%1$s" value="%2$s" id="%3$s" %4$s><label for="%3$s">%5$s</label></div>', $input_name, $esc_value, $id, $checked, $filtered_label, $varitions_id_value_arr[$value]);
}
?>
<form class="variations_form cart" method="post" enctype='multipart/form-data' data-product_id="<?php echo absint( $product->get_id() ); ?>" data-product_variations="<?php echo htmlspecialchars( wp_json_encode( $available_variations ) ) ?>">
<?php do_action( 'woocommerce_before_variations_form' ); ?>
<?php if ( empty( $available_variations ) && false !== $available_variations ) : ?>
<p class="stock out-of-stock"><?php _e( 'This product is currently out of stock and unavailable.', 'woocommerce' ); ?></p>
<?php else : ?>
<?php foreach ( $attributes as $attribute_name => $options ) :
if (sanitize_title($attribute_name) == 'pa_test'):
$sanitized_name = sanitize_title($attribute_name);
if (isset($_REQUEST['attribute_' . $sanitized_name])) {
$checked_value = $_REQUEST['attribute_' . $sanitized_name];
}
elseif (isset($selected_attributes[$sanitized_name])) {
$checked_value = $selected_attributes[$sanitized_name];
}
else {
$checked_value = '';
}
?>
<h3>Choose Your Size</h3>
<ul class="product-size">
<?php
foreach($options as $option) {
echo '<li class="size">';
print_attribute_radio($checked_value, $option, $option, $sanitized_name, $varitions_id_value_arr);
echo '</li>';
}
?>
</ul>
<input type="hidden" name="attribute_pa_test" value="">
<script type="text/javascript">
jQuery('.product-size > li').click(function(e) {
jQuery('.product-size > li').removeClass('size-selected');
jQuery(this).addClass('size-selected');
var option_id = jQuery(this).find("input").attr("checked", true);
var variation_value = jQuery(this).find("input").attr("checked", true).val();
var variation_id = jQuery(this).find("input").attr("checked", true).attr('data-variation-id')
// set choosen variation in hiden inputs
jQuery('input[name=variation_id]').val( variation_id );
jQuery('input[name=attribute_pa_test]').val( variation_value );
});
</script>
<?php endif; ?>
<table class="variations" cellspacing="0">
<tbody>
<tr>
<td class="label"><label for="<?php echo sanitize_title( $attribute_name ); ?>"><?php echo wc_attribute_label( $attribute_name ); ?></label></td>
<td class="value">
<?php
//$selected = isset( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ? wc_clean( stripslashes( urldecode( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ) ) : $product->get_variation_default_attribute( $attribute_name );
//wc_dropdown_variation_attribute_options( array( 'options' => $options, 'attribute' => $attribute_name, 'product' => $product, 'selected' => $selected ) );
//echo end( $attribute_keys ) === $attribute_name ? apply_filters( 'woocommerce_reset_variations_link', '<a class="reset_variations" href="#">' . esc_html__( 'Clear', 'woocommerce' ) . '</a>' ) : '';
?>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
<?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>
<div class="single_variation_wrap">
<?php
/**
* woocommerce_before_single_variation Hook.
*/
do_action( 'woocommerce_before_single_variation' );
/**
* woocommerce_single_variation hook. Used to output the cart button and placeholder for variation data.
* #since 2.4.0
* #hooked woocommerce_single_variation - 10 Empty div for variation data.
* #hooked woocommerce_single_variation_add_to_cart_button - 20 Qty and cart button.
*/
do_action( 'woocommerce_single_variation' );
/**
* woocommerce_after_single_variation Hook.
*/
do_action( 'woocommerce_after_single_variation' );
?>
</div>
<?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>
<?php endif; ?>
<?php do_action( 'woocommerce_after_variations_form' ); ?>
</form>
<?php
do_action( 'woocommerce_after_add_to_cart_form' );
my goal is to move the checkout user registration form to the top of the checkout page (Above the billing form)...
I'm stuck on finding the correct variables and names to hook this form to the place I desire.
Any advice is appreciated! Thank you
You could modify form-billing.php template.
move the following code to the top or the place you want.
<?php if ( ! is_user_logged_in() && $checkout->is_registration_enabled() ) : ?>
<div class="woocommerce-account-fields">
<?php if ( ! $checkout->is_registration_required() ) : ?>
<p class="form-row form-row-wide create-account">
<label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox">
<input class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" id="createaccount" <?php checked( ( true === $checkout->get_value( 'createaccount' ) || ( true === apply_filters( 'woocommerce_create_account_default_checked', false ) ) ), true ) ?> type="checkbox" name="createaccount" value="1" /> <span><?php _e( 'Create an account?', 'woocommerce' ); ?></span>
</label>
</p>
<?php endif; ?>
<?php do_action( 'woocommerce_before_checkout_registration_form', $checkout ); ?>
<?php if ( $checkout->get_checkout_fields( 'account' ) ) : ?>
<div class="create-account">
<?php foreach ( $checkout->get_checkout_fields( 'account' ) as $key => $field ) : ?>
<?php woocommerce_form_field( $key, $field, $checkout->get_value( $key ) ); ?>
<?php endforeach; ?>
<div class="clear"></div>
</div>
<?php endif; ?>
<?php do_action( 'woocommerce_after_checkout_registration_form', $checkout ); ?>
</div>
<?php endif; ?>
How can I add a custom textarea field right below cah on delivery so when you click on the cash on delivery radio button a textarea appears to enter details that get saved into the order?
Copy checkout/payment-method.php file to your theme directory woocommerce folder. i.e your-theme/woocommerce/checkout/payment-method.php
change the content li tag with the following code:
<li class="wc_payment_method payment_method_<?php echo $gateway->id; ?>">
<input id="payment_method_<?php echo $gateway->id; ?>" type="radio" class="input-radio" name="payment_method" value="<?php echo esc_attr( $gateway->id ); ?>" <?php checked( $gateway->chosen, true ); ?> data-order_button_text="<?php echo esc_attr( $gateway->order_button_text ); ?>" />
<label for="payment_method_<?php echo $gateway->id; ?>">
<?php echo $gateway->get_title(); ?> <?php echo $gateway->get_icon(); ?>
</label>
<?php if ( ( $gateway->has_fields() || $gateway->get_description() ) && $gateway->id != "cod" ) : ?>
<div class="payment_box payment_method_<?php echo $gateway->id; ?>" <?php if ( ! $gateway->chosen ) : ?>style="display:none;"<?php endif; ?>>
<?php $gateway->payment_fields(); ?>
</div>
<?php endif; ?>
<?php if ( $gateway->id == "cod" ) : ?>
<div class="payment_box payment_method_<?php echo $gateway->id; ?>" <?php if ( ! $gateway->chosen ) : ?>style="display:none;"<?php endif; ?>>
<?php $gateway->payment_fields(); ?>
<label>Custom Field</label>
<input type="text" name='cod_custom_field'>
</div>
<?php endif; ?>
</li>
Add following code in yout themes functions.php file
/**
* Update the order meta with field value
*/
add_action( 'woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta' );
function my_custom_checkout_field_update_order_meta( $order_id ) {
if ( ! empty( $_POST['cod_custom_field'] ) ) {
update_post_meta( $order_id, 'COD Custom Field', sanitize_text_field( $_POST['cod_custom_field'] ) );
}
}
/**
* Display field value on the order edit page
*/
add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );
function my_custom_checkout_field_display_admin_order_meta($order){
echo '<p><strong>'.__('COD Custom Field').':</strong> ' . get_post_meta( $order->id, 'COD Custom Field', true ) . '</p>';
}
That's it. Hope this help.
So having trouble getting a file uploaded via the front end and actually saving properly.
Funny thing is when I go through the back end user panel it works just fine.
Worth noting this is all on my localhost, running MAMP (apache).
I made sure to include the right files and declare the enctype for the form. I managed to get plain text fields to save just fine. I think I am messing up this part:
if ( !empty( $_POST['map_pdf'] ) )
update_user_meta( $current_user->ID, 'map_pdf', wp_handle_upload( $_POST['map_pdf'], array( 'test_form' => false ) ));
I have seen several other solutions but this is to be displayed in with the users information.
These are the errors I am running into:
Illegal string offset 'size' in /wp-admin/includes/file.php on line 272
File is empty. Please upload something more substantial.
This error could also be caused by uploads being disabled in your php.ini
or by post_max_size being defined as smaller than upload_max_filesize in php.ini.
Profile Page
<?php
/**
* Template Name: User Profile
*
* Allow users to update their profiles from Frontend.
*
*/
/* Get user info. */
global $current_user, $wp_roles;
get_currentuserinfo();
/* Load the registration file. */
require_once( ABSPATH . WPINC . '/registration.php' );
include_once ABSPATH . 'wp-admin/includes/media.php';
include_once ABSPATH . 'wp-admin/includes/file.php';
include_once ABSPATH . 'wp-admin/includes/image.php';
$error = array();
/* If profile was saved, update profile. */
if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'update-user' ) {
/* Update user password. */
if ( !empty($_POST['pass1'] ) && !empty( $_POST['pass2'] ) ) {
if ( $_POST['pass1'] == $_POST['pass2'] )
wp_update_user( array( 'ID' => $current_user->ID, 'user_pass' => esc_attr( $_POST['pass1'] ) ) );
else
$error[] = __('The passwords you entered do not match. Your password was not updated.', 'profile');
}
/* Update user information. */
if ( !empty( $_POST['url'] ) )
wp_update_user( array ('ID' => $current_user->ID, 'user_url' => esc_attr( $_POST['url'] )));
if ( !empty( $_POST['email'] ) ){
if (!is_email(esc_attr( $_POST['email'] )))
$error[] = __('The Email you entered is not valid. please try again.', 'profile');
elseif(email_exists(esc_attr( $_POST['email'] )) != $current_user->id )
$error[] = __('This email is already used by another user. try a different one.', 'profile');
else{
wp_update_user( array ('ID' => $current_user->ID, 'user_email' => esc_attr( $_POST['email'] )));
}
}
$r = get_user_meta( $user->ID, 'map_pdf', true );
if ( !empty( $_POST['first-name'] ) )
update_user_meta( $current_user->ID, 'first_name', esc_attr( $_POST['first-name'] ) );
if ( !empty( $_POST['last-name'] ) )
update_user_meta($current_user->ID, 'last_name', esc_attr( $_POST['last-name'] ) );
if ( !empty( $_POST['display_name'] ) )
wp_update_user(array('ID' => $current_user->ID, 'display_name' => esc_attr( $_POST['display_name'] )));
update_user_meta($current_user->ID, 'display_name' , esc_attr( $_POST['display_name'] ));
if ( !empty( $_POST['description'] ) )
update_user_meta( $current_user->ID, 'description', esc_attr( $_POST['description'] ) );
if ( !empty( $_POST['map_pdf'] ) )
update_user_meta( $current_user->ID, 'map_pdf', wp_handle_upload( $_POST['map_pdf'], array( 'test_form' => false ) ));
/* Redirect so the page will show updated info.*/
/*I am not Author of this Code- i dont know why but it worked for me after changing below line to if ( count($error) == 0 ){ */
if ( count($error) == 0 ) {
//action hook for plugins and extra fields saving
do_action('edit_user_profile_update', $current_user->ID);
wp_redirect( get_permalink().'?updated=true' ); exit;
}
}
?>
<?php get_template_part('templates/header'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="contentarea tk-proxima-nova">
<div class="thecontent">
<h3>Update Information for "<?php echo $current_user->user_login ?>"</h3></br>
<?php if ( $_GET['updated'] == 'true' ) : ?> <div id="message" class="updated"><p>Your profile has been updated.</p></div> <?php endif; ?>
<?php if ( count($error) > 0 ) echo '<p class="error">' . implode("<br />", $error) . '</p>'; ?>
<div id="post-<?php the_ID(); ?>">
<div class="entry-content entry">
<?php the_content(); ?>
<?php if ( !is_user_logged_in() ) : ?>
<p class="warning">
<?php _e('You must be logged in to edit your profile.', 'profile'); ?>
</p><!-- .warning -->
<?php else : ?>
<?php if ( count($error) > 0 ) echo '<p class="error">' . implode("<br />", $error) . '</p>'; ?>
<form method="post" id="adduser" action="<?php the_permalink(); ?>">
<p class="form-username">
<label for="first-name"><?php _e('First Name', 'profile'); ?></label>
<input class="text-input" name="first-name" type="text" id="first-name" value="<?php the_author_meta( 'first_name', $current_user->ID ); ?>" />
</p><!-- .form-username -->
<p class="form-username">
<label for="last-name"><?php _e('Last Name', 'profile'); ?></label>
<input class="text-input" name="last-name" type="text" id="last-name" value="<?php the_author_meta( 'last_name', $current_user->ID ); ?>" />
</p><!-- .form-username -->
<p class="form-email">
<label for="email"><?php _e('E-mail *', 'profile'); ?></label>
<input class="text-input" name="email" type="text" id="email" value="<?php the_author_meta( 'user_email', $current_user->ID ); ?>" />
</p><!-- .form-email -->
<p class="form-url">
<label for="url"><?php _e('Website', 'profile'); ?></label>
<input class="text-input" name="url" type="text" id="url" value="<?php the_author_meta( 'user_url', $current_user->ID ); ?>" />
</p><!-- .form-url -->
<p class="form-password">
<label for="pass1"><?php _e('Password *', 'profile'); ?> </label>
<input class="text-input" name="pass1" type="password" id="pass1" />
</p><!-- .form-password -->
<p class="form-password">
<label for="pass2"><?php _e('Repeat Password *', 'profile'); ?></label>
<input class="text-input" name="pass2" type="password" id="pass2" />
</p><!-- .form-password -->
<p class="form-textarea">
<label for="description"><?php _e('Biographical Information', 'profile') ?></label>
<textarea name="description" id="description" rows="3" cols="50"><?php the_author_meta( 'description', $current_user->ID ); ?></textarea>
</p><!-- .form-textarea -->
<?php
//action hook for plugin and extra fields
do_action('edit_user_profile',$current_user);
?>
<p class="form-submit">
<?php echo $referer; ?>
<input name="updateuser" type="submit" id="updateuser" class="submit button" value="<?php _e('Update', 'profile'); ?>" />
<?php wp_nonce_field( 'update-user' ) ?>
<input name="action" type="hidden" id="action" value="update-user" />
</p><!-- .form-submit -->
</form><!-- #adduser -->
<?php endif; ?>
</div><!-- .entry-content -->
</div><!-- .hentry .post -->
</div><!-- .hentry .post -->
</div><!-- .hentry .post -->
<?php endwhile; ?>
<?php else: ?>
<p class="no-data">
<?php _e('Sorry, no page matched your criteria.', 'profile'); ?>
</p><!-- .no-data -->
<?php endif; ?>
<?php get_template_part('templates/footer'); ?>
And here is the functions.php
add_action( 'show_user_profile', 'extra_user_profile_fields' );
add_action( 'edit_user_profile', 'extra_user_profile_fields' );
function extra_user_profile_fields( $user ) {
$r = get_user_meta( $user->ID, 'map_pdf', true );
?>
<h3>file</h3>
<table class="form-table">
<tr>
<th scope="row">file</th>
<td><input type="file" name="map_pdf" value="" />
<?php //print_r($r);
if (!isset($r['error'])) {
$r = $r['url'];
echo $r;
} else {
$r = $r['error'];
echo $r;
}
?>
</td>
</tr>
</table>
<?php
}
add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );
function save_extra_user_profile_fields( $user_id ) {
$_POST['action'] = 'wp_handle_upload';
if( $_FILES['map_pdf']['error'] === UPLOAD_ERR_OK ) {
$r = wp_handle_upload( $_FILES['map_pdf'] );
update_user_meta( $user_id, 'map_pdf', $r );
}
}
add_action('user_edit_form_tag', 'make_form_accept_uploads');
function make_form_accept_uploads() {
echo ' enctype="multipart/form-data"';
}
Any help is much appreciated. I have been looking everywhere and I have seen others with similar issues but none that are as specific as mine by pulling the userID and having it post back to the user page.
I have a problem with this line just checking exists(1) vs current_user->ID:
elseif(email_exists(esc_attr( $_POST['email'] )) != $current_user->id )
$error[] = __('This email is already used by another user. try a different one.', 'profile');
Would you want to do this?
$current_user_id = $current_user->ID;
$post_email = $_POST['email'];
$esc_email = esc_attr($post_email);
$email_exists = email_exists($esc_email);
$user_by_email = get_user_by( 'email', $esc_email );
$email_user_id = isset($user_by_email->data->ID) ? $user_by_email->data->ID : 0;
}elseif( $email_user_id && ($email_user_id != $current_user_id) ){
$error[] = __('This email is already used by another user. try a different one.', 'profile')