Double Repeater cloning content in textarea - php

I am busy building a custom post type with repeater metaboxes (sorting and cloning) for storing groups of information.
The first repeater metabox is a single text input and works perfectly.
The problem child:
The second repeater metabox is a double repeater with a text input for the label and a textarea for the content. The data saves and sorts, however when I click the clone button the textarea inherits the value of the last item on the list. This value can be overwritten but when I remove the row it removes the content from the row above as well.
I suspect the issue might be with the row counting. On investigation I found that the new row had the same [number] as the one above. I am unfortunately stumped as to how to fix this and the Codex hasn't yielded much answers.
function show_country_facts_meta_box() {
global $facts_meta_fields, $post;
echo '<input type="hidden" name="facts_meta_box_nonce" value="'.wp_create_nonce(basename(__FILE__)).'" />';
echo '<table class="form-table">';
foreach ($facts_meta_fields as $field) {
$meta = get_post_meta($post->ID, $field['id'], true);
echo '<tr>
<td style="display: inline-block; width: 100%; padding: 0;">';
switch($field['type']) {
case 'double_repeatable':
echo ' <ul id="'.$field['id'].'-repeatable" class="custom_repeatable">';
$i = 0;
if ($meta) {
foreach($meta as $row) {
echo '<li>
<span class="sort hndle">|||</span>
<div class="rowMiddle">
<label>'.$field['options'][0].'</label>
<input type="text" name="'.$field['id'].'['.$i.'][0]" id="'.$field['id'].'" value="'.$row[0].'" size="15"/>
<label>'.$field['options'][1].'</label>
<textarea name="'.$field['id'].'['.$i.'][1]" id="'.$field['id'].'" cols="60" rows="4">'.$row[1].'</textarea>
</div>
<a class="repeatable-remove button" href="#">–</a>
</li>';
$i++;
}
} else {
echo '<li>
<span class="sort hndle">|||</span>
<div class="rowMiddle">
<label>'.$field['options'][0].'</label>
<input type="text" name="'.$field['id'].'['.$i.'][0]" id="'.$field['id'].'" value="'.$row[0].'" size="15"/>
<label>'.$field['options'][1].'</label>
<textarea name="'.$field['id'].'['.$i.'][1]" id="'.$field['id'].'" cols="60" rows="4"></textarea>
</div>
<a class="repeatable-remove button" href="#">–</a>
</li>';
}
echo '</ul>
<span class="description">'.$field['desc'].'</span><br />
<a style="margin-top:10px;" class="repeatable-add button" href="#">+</a>';
break;
}
echo '</td></tr>';
}
echo '</table>';
}
// saving the repeater
function save_facts_custom_meta($post_id) {
global $facts_meta_fields;
if ( !isset( $_POST['facts_meta_box_nonce'] ) || !wp_verify_nonce( $_POST['facts_meta_box_nonce'], basename(__FILE__) ) )
return $post_id;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return $post_id;
if ('page' == $_POST['post_type']) {
if (!current_user_can('edit_page', $post_id))
return $post_id;
} elseif (!current_user_can('edit_post', $post_id)) {
return $post_id;
}
foreach ($facts_meta_fields as $field) {
$old = get_post_meta($post_id, $field['id'], true);
$new = $_POST[$field['id']];
if($field['type'] == 'repeatable')
$new = array_values($new);
if ($new && $new != $old) {
update_post_meta($post_id, $field['id'], $new);
} elseif ('' == $new && $old) {
delete_post_meta($post_id, $field['id'], $old);
}
}
}
add_action('save_post', 'save_facts_custom_meta');
Can anyone shed some light on how I can fix this?

Solved: The issue was in the jQuery.
The script was counting the inputs but not the textarea - including this form field solved the issue.

Related

Check if data attribute of button is same as post class

I'm trying to create a post filter by adding a hidden-class to element that don't have a specific category. I have multiple buttons with a 'data-thema'-attribute, I want to check the attribute value of the clicked button and compare it to the classes of the post elements. When the post has no class that equals the data-thema value, I want to add a hidden-class to that element.
Now when a button is clicked, all posts get the class hidden. This is what I want, but it needs to check if there are any posts with the particular class and then remove the hidden-class again.
This is what I have so far:
jQuery
$('.intro .themaWrapper span').on('click', function() {
var clickedTheme = $(this).attr('data-thema');
$('.posts .post').each(function() {
// $(this).addClass('hidden');
if ($(this).hasClass(clickedTheme)) {
$(this).removeClass('hidden');
} else {
$('.posts .post').addClass('hidden');
}
});
});
PHP
foreach( $themas as $category ) {
if( $category->parent == 0 ) {
echo '<span class="btn blue" data-thema="'. esc_attr( $category->slug ) .'">';
echo $category->name;
echo '</span>';
}
}
while ( $query->have_posts() ) {
$query->the_post();
$f = get_fields();
$classes = '';
$terms = wp_get_post_terms( get_the_ID(), 'thema');
foreach($terms as $t) {
$classes .= $t->slug . ' ';
}
echo "<div class='post ". $classes ."'>";
echo "<h2>".get_the_title()."</h2>";
echo "</div>";
}
You can resume the whole logic to a single chained expression:
$('span').on('click', function() {
$('.posts .post')
// Add the hidden class to all the posts
.addClass('hidden')
.removeClass('red')
// Filter those with the same thema
.filter('.' + $(this).data('thema'))
// Remove the hidden class for the filter results
.removeClass('hidden')
.addClass('red');
});
.posts {
margin-top: 20px;
}
.hidden {
display: none;
}
.red {
color: red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<span data-thema="thema-1">Thema 1</span>
<span data-thema="thema-2">Thema 2</span>
<span data-thema="thema-3">Thema 3</span>
<div class="posts">
<div class="post thema-1">Thema 1 div</div>
<div class="post thema-3">Thema 3 div</div>
<div class="post thema-2">Thema 2 div</div>
<div class="post thema-2 thema-1">Thema 1 and Thema 2 div</div>
</div>

Keep checkbox checked after form submit. Custom post type, WordPress

I'm making my own custom post type where I'm currently displaying all images from the gallery with a checkbox for each image. I want the user to be able to be able to check the checkbox for the image that he/she wants to display on the post. This part works. The problem is that the checkbox is unchecked after the form has been submitted. How do I keep it checked?
function po_product_image_html($post) {
echo '<div style="width: 80px; display: inline-block;">';
$imgs = get_media_library_images();
foreach ($imgs as $img)
{
echo '<img style="height: 80px; width: 80px; padding: 10px;" src="'.$img.'" />';
echo '<input name="product_image[]" type="checkbox" value="'.$img.'" />';
}
echo '</div>';
}
The function for saving the form.
function po_products_save_postdata() {
global $post;
update_post_meta($post->ID, 'product_desc', $_POST['product_desc']);
update_post_meta($post->ID, 'product_url', $_POST['product_url']);
update_post_meta($post->ID, 'product_image', $_POST['product_image']);
}
add_action('save_post', 'po_products_save_postdata');
The function for getting the images from media library used in the first code snippet.
function get_media_library_images()
{
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'post_status' => 'inherit',
'posts_per_page' => -1
);
$query_images = new WP_Query($args);
$images = array();
foreach ($query_images->posts as $image)
{
$images[] = $image->guid;
}
return $images;
}
I've tried the isset($_POST['product_image']) thingy to echo checked="checked" in the checkbox, but no luck so far. Is the problem that $_POST['product_image'] is an array?
Best regards, Mac.
Managed to solve it this way:
echo '<div>';
global $post;
$imgs = get_media_library_images();
$post_selected_images = get_post_meta($post->ID, 'product_image', true);
foreach ($imgs as $img) {
<input name="product_image[]" type="checkbox" <?php if(in_array($img, $post_selected_images)) echo 'checked="checked"'; ?> value="<?php echo $img ?>" />
<?php
echo '</div>';
}
echo '</div>';
If the value of the $img variable is stored in the $post_selected_images array I simply echo 'checked="checked"' in the input element.

Rejection Email to the contributor or author from admin

I have created one custom form in admin post editor, to send email templates to authors. I'm facing problem during ajax call that isn't redirecting to the page which I need and getting message post updated when selected template and click on send option
<div id="custom-meta-files" class="row">
<div class="col-md-12">
<form>
<div class="form-group">
<label style="" for="reject_email_template">Template Name</label>
<?php
// The Query
$the_query = new WP_Query( array(
'post_type' => 'email-templates',
'posts_per_page' => -1,
));
if ( $the_query->have_posts() ) { ?>
<select style="display: block;width: 100%;margin: 10px 0;" name="_reject_email" class="form-control" id="reject_email_template">
<?php
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<option value="'.get_the_ID().'">' . get_the_title() . '</option>';
} ?>
</select>
<?php
wp_reset_postdata();
} else {
// no posts found
}
?>
</div>
<button type="submit" class="reject-email-btn btn btn-primary" style="border:none; padding: 6px 1rem;color: #fff; background: #0085ba;text-decoration: none;">Send</button>
</form>
<div id="fromPartsTable"></div>
</div>
save posts in custom fields database
add_action('admin_init','event_meta_init');
function event_meta_init(){
foreach (array('post') as $type){
add_meta_box('my_all_meta', 'Reject Email', 'my_meta_setup', $type, 'normal', 'high');
}
add_action('save_post','my_meta_save');}
function my_meta_setup(){
global $post;
// using an underscore, prevents the meta variable
// from showing up in the custom fields section
$meta = get_post_meta($post->ID,'_post',TRUE);
// instead of writing HTML here, lets do an include
include(MY_THEME_FOLDER . '/metafields/events-fields.php');
// create a custom nonce for submit verification later
echo '<input type="hidden" name="my_meta_noncename" value="' . wp_create_nonce(__FILE__) . '" />';
}
function my_meta_save($post_id){
// authentication checks
// make sure data came from our meta box
if (!wp_verify_nonce($_POST['my_meta_noncename'],__FILE__)) return $post_id;
// check user permissions
if ($_POST['post_type'] == 'page'){
if (!current_user_can('edit_page', $post_id)) return $post_id;
}else{
if (!current_user_can('edit_post', $post_id)) return $post_id;
}
$current_data = get_post_meta($post_id, '_post', TRUE);
$new_data = $_POST['_post'];
my_meta_clean($new_data);
if ($current_data){
if (is_null($new_data)) delete_post_meta($post_id,'_post');
else update_post_meta($post_id,'_post',$new_data);
}elseif (!is_null($new_data)){
add_post_meta($post_id,'_post',$new_data,TRUE);
}
return $post_id;
}
function my_meta_clean(&$arr){
if (is_array($arr)) {
foreach ($arr as $i => $v){
if (is_array($arr[$i])){
my_meta_clean($arr[$i]);
if (!count($arr[$i])){
unset($arr[$i]);
}
}else{
if (trim($arr[$i]) == ''){
unset($arr[$i]);
}
}
}
if (!count($arr)){
$arr = NULL;
}
}
}
My ajax script is
jQuery.noConflict();
(function( $ ) {
function rejection_email(){
$.ajax({
url: "/rejection-email/",
data : {eid:$('#reject_email_template').val()},
success: function(data) {
var result = data
$('#fromPartsTable').html(result);
},
error: function() {
alert('Error occured');
}
});
}
$('.reject-email-btn').click(function(e) {
rejection_email();
});
})(jQuery);

Send SESSION GET information in POST contact form together with the POST fields

On the website i'm currently working on I made a list (cart idea) where customers can put products on. It works with GET method + a session, the code for the making of the session is as follows:
`<?php session_start();
require("dbconnect.php");
?>
<?php
if(!isset($_SESSION['cart'])) {
$cart = array();
$_SESSION['cart'] = $cart;
}
if(isset($_GET['action']) && $_GET['action']=="add"){
$id=intval($_GET['id']);
if(in_array($id, $_SESSION['cart'])){
if (($key = array_search($id, $_SESSION['cart'] !== false))){
unset($_SESSION['cart'][$key]);
}
}
else {
array_push($_SESSION['cart'],$id);
}
}
if(isset($_GET['action']) && $_GET['action']=="delete"){
$id = intval($_GET['id']);
if (in_array($id, $_SESSION['cart'])){
$key = array_search($id, $_SESSION['cart']);
unset($_SESSION['cart'][$key]);
}
}
?>
Nothing special, just a regular cart in a session with an array where I put all the unique product codes to remember what is on the list. Now when customers go to the page where they could send the list of product they also can select how many of each product they want. They have to fill in a number and when they are done they click on the button 'calculate (berekenen in my language)' and they get the subtotal price of all the products, the VAT and the total price. However, I want it this way that the customer can fill in their personal information plus the list plus the amounts to be send in an e-mail. I made selfmade PHP forms myself earlier but now i'm getting stuck. I use GET for the order list but I always use a POST form for my contactforms. How can I manage to make one button that sends the list plus the amounts plus the input of the contact form fields to me? At this moment I tried it as follows (and many more ways, but it all failed so far).
<main>
<div class="main-center">
<div class="offerte-container">
<form action="" method="get" value="offertelijst">
<ul class="offerte-list">
<?php
$per_page = 9;
$args = array(
'post_type'=> 'wpcproduct',
'order' => 'ASC',
'orderby' => 'menu_order',
'posts_per_page' => $per_page
);
$products = new WP_Query($args);
?>
<?php
while($products->have_posts()): $products->the_post();
$id = get_the_ID();
$title = get_the_title();
$permalink = get_permalink();
$price = get_post_meta(get_the_id(),'wpc_product_price',true);
$product_id = get_post_meta(get_the_id(), 'product_ID', true);
if(in_array($id, $_SESSION['cart'])){
echo '<li class="wpc-product-item">';
echo 'Verwijder ';
echo '<input alt="hoeveelheid" maxlengt="2" value="' .$_GET["amount$id"]. '" min="1" type="number" max="99" name="amount'.$id.'" size="3" required> </input>';
echo '<div class="item-title"> ' .$title. ' </div>';
echo '<div class="item-take"> <img width="25px" src="http://bgc-testomgeving.nl/sem/wp-content/themes/sem/images/pijltje.png" /> </div>';
echo '<div class="item-nr"> '.$product_id. '</div>';
if((isset($_GET["amount$id"]) && $_GET["amount$id"] == 1) || $_GET["amount$id"] == "" ){
if (is_numeric($price) && (floor($price) == $price)) {
echo '<div class="item-price"> €' .number_format ($price , 0 , "," , "." ). ',- </div>';
}
else {
echo '<div class="item-price"> €' .$price. '</div>';
}
echo '</li>';
}
else if(isset($_GET["amount$id"]) && floatval($_GET["amount$id"]) > 1){
changeFormat($price);
$priceTotal = number_format($price * floatval($_GET["amount$id"]), 2);
if (is_numeric($priceTotal) && (floor($priceTotal) == $priceTotal)) {
echo '<div class="item-price"> €' .$priceTotal . ',- </div>';
}
else {
echo '<div class="item-price"> €' .$priceTotal . '</div>';
}
echo '</li>';
}}
endwhile;
?>
</ul>
<input type="submit" value="Bereken"> </input>
</form>
<div class="totalprice">
<?php
(float)$total = 0;
while($products->have_posts()): $products->the_post(); {
$id = get_the_ID();
$title = get_the_title();
$permalink = get_permalink();
$price = get_post_meta(get_the_id(),'wpc_product_price',true);
$product_id = get_post_meta(get_the_id(), 'product_ID', true);
if(in_array($id, $_SESSION['cart'])){
if (is_numeric($price) && (floor($price) == $price)) {
$price = number_format($price, 2);
}
else {
$price = str_replace(',', '.', $price);
}
$total += (floatval($price) * floatval($_GET["amount$id"]));
}}
endwhile;
(String)$total;
number_format($total, 2);
$totalDecimal = str_replace('.', ',', $total);
echo 'Subtotaal: €' .$totalDecimal. '<br />';
echo 'BTW: €' . str_replace('.',',', number_format($total * 0.21,2)). '<br />';
echo 'Totaal: €' . str_replace('.',',', number_format($total * 1.21,2));
function changeFormat($var) {
if(is_numeric($var) && (floor($var) == $var)){
return number_format($var, 0) + ',-';
}
else {
if (is_numeric($var)) {
return number_format($var, 2, ',', '.');
}
else if (is_string ($var)){
return str_replace(',', '.', $var);
}
else {
echo "What the hell is dit voor een formaat?";
}
}}
?>
</div>
</div>
</div>
</main>
The calculate function and the orderlist are all working fine and i'm able to make a standard POST form as a contactform but I can't manage to get this done. I want the button 'send' to send the list plus the given amounts per product and the filled in contact forms.
The URL for this project is: http://www.bgc-testomgeving.nl/sem
Underneath the http://www.bgc-testomgeving.nl/sem/offertelijst/ page should be the contact form but every time I try to build this I demolish my perfect order list.
First of all change your form method to post.
<form action="" method="post" value="offertelijst">
Then you have to create inputs for each item in your form element. I see this you have only Amount input in your form:
echo '<input alt="hoeveelheid" maxlengt="2" value="' .$_GET["amount$id"]. '" min="1" type="number" max="99" name="amount'.$id.'" size="3" required> </input>';
Create input for each element, since user doesnt need to see those inputs you can create them as hidden element, here is one example for item title:
echo '<input type="hidden" name="title['.$id.']" value="' .$title. '"</input>';
Put this below this line
echo '<div class="item-title"> ' .$title. ' </div>';
After you created all inputs, also create second button near of this one:
<input type="submit" name="action" value="Bereken">
<input type="submit" name="action" value="Send">
So When the user click Bereken, you will do your calculation things, but if it is Send button, you will mail it to your self. here is Example code:
<?php
// if send button clicked
if($_POST["action"]=="Send")
{
/// mail to your self all element
mail("you#www.com","New Order",implode("-",$_POST));
}
?>
<main>
<div class="main-center">
<div class="offerte-container">
<form action="" method="post" value="offertelijst">
<ul class="offerte-list">
<?php
$per_page = 9;
$args = array(
'post_type'=> 'wpcproduct',
'order' => 'ASC',
'orderby' => 'menu_order',
'posts_per_page' => $per_page
);
$products = new WP_Query($args);
?>
<?php
while($products->have_posts()): $products->the_post();
$id = get_the_ID();
$title = get_the_title();
$permalink = get_permalink();
$price = get_post_meta(get_the_id(),'wpc_product_price',true);
$product_id = get_post_meta(get_the_id(), 'product_ID', true);
if(in_array($id, $_SESSION['cart'])){
echo '<li class="wpc-product-item">';
echo 'Verwijder ';
echo '<input alt="hoeveelheid" maxlengt="2" value="' .$_GET["amount$id"]. '" min="1" type="number" max="99" name="amount'.$id.'" size="3" required> </input>';
echo '<div class="item-title"> ' .$title. ' </div>';
// i added below input for example
echo '<input type="hidden" name="title['.$id.']" value="' .$title. '"</input>';
echo '<div class="item-take"> <img width="25px" src="http://bgc-testomgeving.nl/sem/wp-content/themes/sem/images/pijltje.png" /> </div>';
echo '<div class="item-nr"> '.$product_id. '</div>';
if((isset($_GET["amount$id"]) && $_GET["amount$id"] == 1) || $_GET["amount$id"] == "" ){
if (is_numeric($price) && (floor($price) == $price)) {
echo '<div class="item-price"> €' .number_format ($price , 0 , "," , "." ). ',- </div>';
}
else {
echo '<div class="item-price"> €' .$price. '</div>';
}
echo '</li>';
}
else if(isset($_GET["amount$id"]) && floatval($_GET["amount$id"]) > 1){
changeFormat($price);
$priceTotal = number_format($price * floatval($_GET["amount$id"]), 2);
if (is_numeric($priceTotal) && (floor($priceTotal) == $priceTotal)) {
echo '<div class="item-price"> €' .$priceTotal . ',- </div>';
}
else {
echo '<div class="item-price"> €' .$priceTotal . '</div>';
}
echo '</li>';
}}
endwhile;
?>
</ul>
<input type="submit" name="action" value="Bereken">
<input type="submit" name="action" value="Send">
</form>
<div class="totalprice">
<?php
// is bereken button clickied
if($_POST["action"]=="Bereken") {
(float)$total = 0;
while($products->have_posts()): $products->the_post(); {
$id = get_the_ID();
$title = get_the_title();
$permalink = get_permalink();
$price = get_post_meta(get_the_id(),'wpc_product_price',true);
$product_id = get_post_meta(get_the_id(), 'product_ID', true);
if(in_array($id, $_SESSION['cart'])){
if (is_numeric($price) && (floor($price) == $price)) {
$price = number_format($price, 2);
}
else {
$price = str_replace(',', '.', $price);
}
$total += (floatval($price) * floatval($_GET["amount$id"]));
}}
endwhile;
(String)$total;
number_format($total, 2);
$totalDecimal = str_replace('.', ',', $total);
echo 'Subtotaal: €' .$totalDecimal. '<br />';
echo 'BTW: €' . str_replace('.',',', number_format($total * 0.21,2)). '<br />';
echo 'Totaal: €' . str_replace('.',',', number_format($total * 1.21,2));
}
function changeFormat($var) {
if(is_numeric($var) && (floor($var) == $var)){
return number_format($var, 0) + ',-';
}
else {
if (is_numeric($var)) {
return number_format($var, 2, ',', '.');
}
else if (is_string ($var)){
return str_replace(',', '.', $var);
}
else {
echo "What the hell is dit voor een formaat?";
}
}}
?>
</div>
</div>
</div>
</main>

WP wp_update_user($userdata) Error

I am working with WordPress 3.9 and Woocommerce in templates/../my-account.php. I did not like the default my-account page and wanted the user to be able to edit specific settings so I set it up so the user can change their username, email, or password. That was the goal at least haha.
In the debugging process, I found the problem was with $user_id = wp_update_user( $userdata ); . is_wp_error($user_id) returns false. When I use wp_get_current_user(); I am able to echo user_email, for example, and the user's email is displayed. I'm pretty sure I created the $userdata array correctly, so what do I need to change to be able to update the user's settings?
I could be making a mistake, but to my knowledge I'm doing everything according to the codex docs.
Here's my code for my-account.php if you need other code or more information I can supply. Thank you for any help.
<?php
/**
* My Account
*/
global $woocommerce;
global $current_user;
?>
<style type="text/css">
#edit-account-settings { font-size: 1.2em; width: 280px; }
#edit-account-settings input { width: 100%; }
#edit-submit { font-size: 1em; }
</style>
<?php
wp_get_current_user();
if(is_null($current_user)) {
echo 'Sorry, you are not logged in. '.wp_loginout();
} else {
$php_option = false;
$fName = $current_user->first_name;
$lName = $current_user->last_name;
$username = $current_user->user_login;
$email = $current_user->user_email;
print '<div id="account-settings"><h2>Welcome '.$fName.' '.$lName.'</h2>';
print '<p style="font-size: 1.4em;">User Name: '.$username.'</p>';
print '<p style="font-size: 1.4em;">Email: '.$email.'</p>';
print '<p style="font-size: 1.4em;">Password: ********</p>';
print '<a id="edit-account-settings" href="#" onclick="edit_settings();">Change your account settings</a></div>';
}
?>
<script>
function edit_settings() {
//alert("inside onclick event");
var username = <?php echo json_encode($username); ?>;
var email = <?php echo json_encode($email); ?>;
var data = '<p style="font-size: 1.2em;">To change your settings, enter the new value in the appropriate text field</p>';
data += '<p style="font-size: 1.2em;">If do not want to change your password, enter your current password twice.</p>';
data += '<p style="font-size: 1.2em;">If you want your other settings to remain the same, leave the fields as they are and submit.</p>';
data += '<form id="edit-account-settings" name="edit-account-settings" method="post" action="">';
data += '<label for="un">User Name: </label><input type="text" id="un" name="un" value="'+username+'" maxlength="16" required />';
data += '<label for="email">Email: </label><input type="email" id="em" name="em" value="'+email+'" maxlength="32" required />';
data += '<br /><br /><input type="password" id="p1" name="p1" value="" placeholder="Enter a new password" maxlength="16" required />';
data += '<br /><br /><input type="password" id="p2" name="p2" value="" placeholder="Re-enter password" maxlength="16" required />';
data += '<br /><br /><input type="submit" id="edit-submit" name="edit-submit" value="Submit Changes" />';
data += '</form></div>';
var elem = document.getElementById("account-settings");
elem.innerHTML = data;
}
</script>
<?php
if (isset($_POST['em']) && $_POST['em'] != $email && $_POST['em'] != "") {
$em = $_POST['em'];
$userdata = array(
'user_email' => $em
);
if (!empty($userdata) || isset($userdata['user_email'])) {
$user_id = wp_update_user( $userdata );
if(is_wp_error($user_id)) {
echo "<p style='color: #FF0000;'>Error: Sorry your settings could not be updated. Please try again in a minute.</p>";
} else {
echo "<p style='color: #00FF00;'>Congradulations! Your settings have been updated.</p>";
}
} else {
echo "<p>$userdata is null or undefined</p>";
}
} else {
echo "<p>Your email address is the same</p>";
}
?>
<?php do_action('woocommerce_before_my_account'); ?>
<?php if ($downloads = $woocommerce->customer->get_downloadable_products()) : ?>
<h2><?php _e('Available downloads', 'woocommerce'); ?></h2>
<ul class="digital-downloads">
<?php foreach ($downloads as $download) : ?>
<li><?php if (is_numeric($download['downloads_remaining'])) : ?><span class="count"><?php echo $download['downloads_remaining'] . _n(' download remaining', ' downloads remaining', $download['downloads_remaining'], 'woocommerce'); ?></span><?php endif; ?> <?php echo $download['download_name']; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<h2><?php _e('Recent Orders', 'woocommerce'); ?></h2>
<?php woocommerce_get_template('myaccount/my-orders.php', array( 'recent_orders' => $recent_orders )); ?>
<h2><?php _e('My Address', 'woocommerce'); ?></h2>
<p class="myaccount_address"><?php _e('The following addresses will be used on the checkout page by default.', 'woocommerce'); ?></p>
<?php woocommerce_get_template('myaccount/my-address.php'); ?>
<?php
do_action('woocommerce_after_my_account');
I believe you need to include the user's ID in your $userdata array. For instance:
$userdata = array(
'ID' => $current_user->ID,
'user_email' => $em
);

Categories