woocommerce wordpress billing form update data - mysql

what happened is when already registered user come to checkout page and fill billing form. The data update the current user data.
for example first name must go to billing_first_name but it's update first_name also with the same value.
I want it to update billing_first_name only
I want to reverse this process:
add_action('woocommerce_checkout_order_processed', 'custom_process_order1', 10, 1);
function custom_process_order1($order_id) {
    $current_user = wp_get_current_user();
    $current_user_id = get_current_user_id();
    update_user_meta($current_user_id, "first_name", $current_user->billing_first_name);
    update_user_meta($current_user_id, "last_name", $current_user->billing_last_name);
}
here it's update first name with the value of billing_first_name and this is what I want to prevent.
how can I do that ?

use correct meta field name,
add_action('woocommerce_checkout_order_processed', 'custom_process_order1', 10, 1);
function custom_process_order1($order_id) {
    $current_user = wp_get_current_user();
    $current_user_id = get_current_user_id();
    update_user_meta($current_user_id, "billing_first_name", $current_user->billing_first_name);
    update_user_meta($current_user_id, "billing_last_name", $current_user->billing_last_name);
}
https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/
on this page, you can get correct field names

Related

Indesign - Is it possible to update value in cell when I know ID of the product?

I have a question, my colleague is creating product catalog in our company (in Indesign)
He is updating a version from last year, because we have not much new products BUT all the prices (~7000) are new.
I have never worked with Indesign before, so my question is, is it somehow possible to update OLD prices to NEW prices using ID of products, and the price is always located in the cell next to ID? Please check screenshots.
This is the table with new Prices, in csv file.
THANKS for any help.
Nikol
Possible workaround is:
read CSV line by line and store current ID and current price
use current ID for doc.findText() method
the parent of 1st found element should be an IDcell
odlPriceCell should be a current table's cell with index +1
use current price for new odlPriceCell contents
sample code:
var
mDoc = app.activeDocument,
mSource = File("~/Desktop/prices.csv"),
// mTarget = mDoc.stories.everyItem().tables.everyItem(),
cLine, cID, cPrice,
cFound, oldID_Cell, target_Cell,
separator = ",";
app.findTextPreferences = null;
mSource.open("r");
do {
cLine = mSource.readln().split(separator);
cID = cLine[0];
cPrice = cLine[1];
if (!cID.match(/^\d+-\d+/)) continue;
app.findTextPreferences.findWhat = cID;
cFound = mDoc.findText();
if (!cFound.length) continue;
oldID_Cell = cFound[0].texts[0].parent;
if (oldID_Cell.constructor.name !="Cell") continue;
target_Cell = oldID_Cell.parent.cells.item(oldID_Cell.index + 1);
target_Cell.texts[0].contents = cPrice;
} while (!mSource.eof);
mSource.close();
Notice mSource path to modify

The existing data required by the data writer could not be found

On my page for an add-on i am creating works perfectly well unless i try to update an existing row. `public function actionUpdate()
{
$visitor = XenForo_Visitor::getInstance();
$userName = $visitor['username'];
//Get the text that user wrote in the text box
$text3 = $this->_input->filterSingle('simple_text2', XenForo_Input::STRING);
$text4 = $this->_input->filterSingle('simple_text3', XenForo_Input::STRING);
//Create a instance of our DataWriter
$dwSimpleText = XenForo_DataWriter::create('MinecraftAdder_DataWriter_MinecraftAdder');
//Set the field with the data we filtered
$dwSimpleText->setExistingData('Name');
$dwSimpleText->set('Name', $text3);
$dwSimpleText->setExistingData('Rank');
$dwSimpleText->set('Rank', XenForo_Visitor::getUserId());
$dwSimpleText->setExistingData('UUID');
$dwSimpleText->set('UUID', $text4);
$dwSimpleText->setExistingData('UserID');
$dwSimpleText->set('UserID', $userName);
//Save in the database, please!
$dwSimpleText->save();
//Send a response to the user, so he know that everything went fine with this action
return $this->responseRedirect(
XenForo_ControllerResponse_Redirect::SUCCESS,
$this->getDynamicRedirect()
);
}`
I get the error The existing data required by the data writer could not be found. Does anyone know how to fix this?
My Addon page
Your usage of setExistingData is incorrect. That function must be given one of these two values:
The value of the Primary Key column(s) for the row you want to update
An array with all the data for the row you want to update
So in your case, seeing as you don't select the row in advance, you'd use option 1. Assuming UserID is your Primary Key column, your code would be:
public function actionUpdate() {
$visitor = XenForo_Visitor::getInstance();
$userName = $visitor['username'];
//Get the text that user wrote in the text box
$text3 = $this->_input->filterSingle('simple_text2', XenForo_Input::STRING);
$text4 = $this->_input->filterSingle('simple_text3', XenForo_Input::STRING);
//Create a instance of our DataWriter
$dwSimpleText = XenForo_DataWriter::create('MinecraftAdder_DataWriter_MinecraftAdder');
//Set the field with the data we filtered
$dwSimpleText->setExistingData($userName);
$dwSimpleText->set('Name', $text3);
$dwSimpleText->set('Rank', XenForo_Visitor::getUserId());
$dwSimpleText->set('UUID', $text4);
//Save in the database, please!
$dwSimpleText->save();
//Send a response to the user, so he know that everything went fine with this action
return $this->responseRedirect(
XenForo_ControllerResponse_Redirect::SUCCESS,
$this->getDynamicRedirect()
);
}
Some other tips:
If this actionUpdate may be accessed through a form only, you should add $this->_assertPostOnly(); on the top of the function to make sure the request was a POST request.
You may want to check if the Visitor's user_id is 0 so you don't save the information of guests. (Unless that's what you want of course)

Using MD5 and CONCAT in MuSQL WHERE clause

I am creating a reset password procedure. this way:
1- Send reset email to the user (whom forgot his/her password), and this email contain a link to this address:
http://www.example.com/resetpassword.php?userid=1b2798bad6ee465d967cdb71ced504f7
The value of the parameter [userid] is generated by this PHP code:
<?php
md5($row_Recordset2['userID'].date('d-m-Y'));
?>
Note: I did this so that I can get a unique parameter value containing: The MD5 hash of the real user id + the current date (concatenation) , Why? so the link in the email will be available for the current date only. I do not want that link to work in the next day.
2- When the person click on the above link, he/she will be taken to the page [resetpassword.php]
3- In the page [resetpassword.php] page I have this piece of code:
$colname_Recordset1 = "-1";
if (isset($_GET['userid'])) {
$colname_Recordset1 = $_GET['userid'];
}
mysql_select_db($database_aaa_database, $aaa_database);
$query_Recordset1 = sprintf("SELECT * FROM users WHERE md5(CONCAT(userID,
DATE_FORMAT(NOW(),'%d-%m-%Y'))) = %s ", GetSQLValueString($colname_Recordset1,
"text"));
$Recordset1 = mysql_query($query_Recordset1, $aaa_database) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
The SELECT statement return [Query was empty] ... What is the problem and how to solve it?
I have tested this MySQL statement manually:
SELECT userFirstName, md5(CONCAT(userID, DATE_FORMAT(NOW(),'%d-%m-%Y'))) from users
And it return many rows, one of the rows is like this:
Sam 1b2798bad6ee465d967cdb71ced504f7
So, the:
md5(CONCAT(userID, DATE_FORMAT(NOW(),'%d-%m-%Y')))
works fine and it return the same exact value generated by the PHP code :
<?php
md5($row_Recordset2['userID'].date('d-m-Y'));
?>
PHP give: 1b2798bad6ee465d967cdb71ced504f7
MySQL give: 1b2798bad6ee465d967cdb71ced504f7
But this:
md5(CONCAT(userID, DATE_FORMAT(NOW(),'%d-%m-%Y')))
seems to be NOT WORKING in the WHERE clause:
sprintf("SELECT * FROM users WHERE md5(CONCAT(userID,
DATE_FORMAT(NOW(),'%d-%m-%Y'))) = %s ", GetSQLValueString($colname_Recordset1,
"text"));
By the way, I am using Dreamweaver.
I don't know how to solve this problem. Any help will be highly appreciated.

Issue in setting unique ID in Domino designer

I am new to Domino designer and lotus script,
following my second question,
I have some issue in setting unique ID (for id field in form).
My formula for Id field value :
T_List:=#DbColumn("" : "NoCache"; "Local"; "DBintro";"testview"; 1);
#If(#IsNewDoc & #Elements(T_List)=0;1;#IsNewDoc & !#IsError(T_List);#Subset(T_List;1) + 1;id)
I'm having DB in local (nothing shared).
referred this link an Answer by AndrewB
Server : Local
DBname : DBintro
view name : testview
id - field in the form (which is set when required to save in DB)
Error I'm getting
Field id ! does not exist
Please help me to get out of this..
Thanks
EDIT :1 Updated code
T_List:=#DbColumn("" : "NoCache"; "Local"; "DBintro";"testview"; 1);
T_List:=#Sort(T_List; [DESCENDING]);
#if(#Iserror(T_List);
1;
#Subset(T_List;1)+1
);
Set type of field "testid" to "Number"
Change formula to
_List:=#DbColumn("" : "NoCache"; ""; "testview"; 1);
#If( #IsError(_List);
1;
_List = "";
1;
#Subset(_List; 1) + 1
)
Set column sort to "Descending"
Perhaps re-arranging the logic might help - try this in the formula for Id field. Make the field "Computed When Composed" (next to field typer in properties box - it means it only evaluates when the doc is first created, and remains the same after - saves detecting #IsNewDoc :-D ):
T_List:=#DbColumn("" : "NoCache"; "Local"; "DBintro";"testview"; 1);
#if(#Iserror(T_List);
1;
#Subset(T_List;1)
);
You don't have to worry about the id field returning itself if the doc isn't new, because the computed when composed field stops evaluating after 1st save.
Bad formula for your dbColumn. There should be a colon, not semi-colon between servername and filename. Of course, there is no server named "Local". You would just use "" for local. Also, the filename is the full filename - "DBintro.nsf", not "DBintro".
T_List:=#DbColumn("Notes":"NoCache"; "":"DBintro.nsf";"testview"; 1);
T_List:=#Sort(T_List; [DESCENDING]);
#if(#Iserror(T_List);
1;
#Subset(T_List;1)+1
);
Have you got the unique ID set as a text field because I have found that the formula has to be converted to a text value and not just the unique document id.

Store Facebook Name in MYSQL

I need to store a users public facebook name in my MYSQL database, when they fill out a form in my canvas based application.
This is what I have, but for some reason the name never makes it into the database - everything else does..
$submit = $_POST['submit'];
if(isset($_POST['submit']) )
{
//form data
$name = $me['name'];
$q1 = $_POST['bromance'];
$q2 = $_POST['couple'];
$q3 = $_POST['prime'];
$email = $_POST['email'];
//register the user
$queryvote = mysql_query("INSERT INTO vote VALUES ('','$name','1','$q1','$q2','$q3','$email')");
I can succesfully echo out the users name by using $me['name'];, so I'm struggling to see why I cannot carry it through to my mysql_query. I've even tried populating it into a readonly field in the form, and inserting that value... again though, it never shows in the database.
I know the code I'm using is depreciated, but its needed for this project. Probably a silly error, but we all miss things!
Thanks!