Answer the question
In order to leave comments, you need to log in
How to get POST field data for customer registration after order form processing?
Hello! There is a woocommerce store .
I want to make it so that when ordering a product, the company name field is checked and if it is new, then a new user with the client role is created, and automatically without registrations and entering the site.
I wrote the function of checking the required field and creating a user, it remains only to get the value of the form fields to check, and I have a problem with this.
I'm trying to make a check by connecting to the woocommerce_thankyou hook , but the form field can't be caught. $_POST["billing_name"]
Code:
add_action( 'woocommerce_thankyou', 'create_customer' );
function create_customer() {
$customers = get_users( array( 'role' => 'customer' ) );
foreach( $customers as $customer ) :
$my_customer = get_user_meta( $customer->ID, 'billing_company', true );
if($my_customer!=$_POST["billing_company"]) {
$userdata = array(
'user_pass' => '123',
'user_login' => $_POST["billing_name"],
'user_email' => $_POST["billing_email"],
'user_company' => $_POST["billing_company"],
'role' => 'customer',
);
wp_insert_user( $userdata );
}
endforeach;
}
Answer the question
In order to leave comments, you need to log in
Try to catch not the form, but the order. There in its fields there is data about the client
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question