Woocommerce function to fill form
-
Hello,
I need to create connection with third part application to fill Shipping Address form. I create code and add it to function.php in Woocommerce plugin but, I couldn’t find way to put data to this form. I know that my code work (I test downland data in other server), but when I put it into Woocommerce function nothing happen. This is part of my code (I know that I have connection with third part application, but I ‘m not sure two of things – take the Woocommerce login user email, and method to put downland data to shipping form):$email=get_option( ‘woocommerce_registration_generate_username’ ) ? ’email’ : ’email username’;
//Woocommerce form add dataó
add_filter( ‘woocommerce_shipping_fields’ ,’fillFormData’);
function fillFormData($fields){
//Parameter given by WordPress to search data in Zoho CRM.
$loginEmail=get_option( ‘woocommerce_registration_generate_username’ ) ? ’email’ : ’email username’;
//Array with data to generate Access Token.
$postRequestToken = array(…….);
//Connect with App Access token generator.
$cURLConnectionToken = curl_init(…..);
curl_setopt($cURLConnectionToken, CURLOPT_POSTFIELDS, $postRequestToken);
curl_setopt($cURLConnectionToken, CURLOPT_RETURNTRANSFER, true);
$apiResponse = curl_exec($cURLConnectionToken);
curl_close($cURLConnectionToken);
//Convert JSON response to Array with token;
$tokenArray=json_decode($apiResponse,true);
$accessToken=$tokenArray[‘access_token’];
//Search Contact in App from login email.
$cURLConnectionContact = curl_init();
curl_setopt($cURLConnectionContact, CURLOPT_URL,’…./search?criteria=(Email:equals:’.$loginEmail.’)’);
curl_setopt($cURLConnectionContact, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURLConnectionContact, CURLOPT_HTTPHEADER, array(‘….’.$accessToken));
$contactData = curl_exec($cURLConnectionContact);
curl_close($cURLConnectionContact);
//Take the record information from response.
$contact=json_decode($contactData, true);
//Get Contact information.
$contact_email=$contact[‘Email’];
$contact_first_name=$contact[‘First_Name’];
$contact_last_name=$contact[‘Last_Name’];
$contact_phone=$contact[‘Phone’];
$contact_accountInfo=$contact[‘Account_Name’];
$contact_accountId=$contact_accountInfo[‘id’];
//Get Account record
$cURLConnectionAccount = curl_init();
curl_setopt($cURLConnectionAccount, CURLOPT_URL,’…..’.$contact_accountId);
curl_setopt($cURLConnectionAccount, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURLConnectionAccount, CURLOPT_HTTPHEADER, array(‘….. ‘.$accessToken));
$accountData = curl_exec($cURLConnectionAccount);
curl_close($cURLConnectionAccount);
//Take the record information from response.
$contact_account=json_decode($accountData, true);
//Get Account information
$contact_account_name=$contact_account[‘Account_Name’];
$contact_account_number=$contact_account[‘Account_Number’];
$contact_address_line=$contact_account[‘Shipping_Street’];
$contact_city=$contact_account[‘Shipping_City’];
$contact_postcode=$contact_account[‘Shipping_Code’];
$contact_state=$contact_account[‘Shipping_State’];
$contact_country=$contact_account[‘Shipping_Country’];
$contact_sic_code=$contact_account[‘SIC_Code’];//WooCommerce form for Shipping
$fields[‘shipping_first_name’][‘label’] =’First name’ ;
$fields[‘shipping_first_name’][‘placeholder’] =$contact_first_name ;
$fields[‘shipping_first_name’][‘value’] = $contact_first_name ;
$_POST[‘shipping_first_name’]= $contact_first_name ;
$fields[ ‘shipping_first_name’ ][‘required’] = true;
$fields[‘shipping_last_name’][‘label’] = ‘Last name’;
$fields[‘shipping_last_name’][‘placeholder’] = $contact_last_name;
$fields[‘shipping_last_name’][‘value’] = $contact_last_name;
$fields[ ‘shipping_last_name’ ][‘required’] = true;
$fields[‘shipping_email’] = array(
‘label’ => __(‘Email address’, ‘woocommerce’),
‘placeholder’ => _x($contact_email, ‘placeholder’, ‘woocommerce’),
‘required’ => true,
‘clear’ => false,
‘type’ => ’email’,
‘class’ => array( ‘form-row-wide’) ,
‘autocomplete’ => $contact_email,
‘value’ => $contact_email,
‘priority’=>21
);
$fields[‘shipping_phone’] = array(
‘label’ => __(‘Phone’, ‘woocommerce’),
‘placeholder’ => _x($contact_phone, ‘placeholder’, ‘woocommerce’),
‘required’ => false,
‘type’ => ‘text’,
‘class’ => array(‘form-row-wide’),
‘clear’ => false ,
‘autocomplete’ => $contact_phone,
‘value’ => $contact_phone,
‘priority’=>22
);
$fields[‘shipping_company’][‘label’] = ‘Company’;
$fields[‘shipping_company’][‘placeholder’] = $contact_account_name;
$fields[‘shipping_company’][‘value’] = $contact_account_name;
$fields[‘shipping_account_number’] = array(
‘label’ => __(‘Account number’, ‘woocommerce’),
‘placeholder’ => _x($contact_account_number, ‘placeholder’, ‘woocommerce’),
‘required’ => false,
‘clear’ => false,
‘type’ => ‘text’,
‘class’ => array(‘form-row-wide’) ,
‘autocomplete’ => $contact_account_number,
‘priority’=>31
);
$fields[‘shipping_address_1’][‘label’] = ‘Address line’;
$fields[‘shipping_address_1’][‘placeholder’] = $contact_address_line;
$fields[‘shipping_address_1’][‘value’] = $contact_address_line;
$fields[ ‘shipping_address_1’ ][‘required’] = true;
$fields[‘shipping_city’][‘label’] = ‘City’;
$fields[‘shipping_city’][‘placeholder’] = $contact_city;
$fields[ ‘shipping_city’ ][‘required’] = true;
$fields[‘shipping_postcode’][‘label’] = ‘Postcode’;
$fields[‘shipping_postcode’][‘placeholder’] = $contact_postcode;
$fields[ ‘shipping_postcode’ ][‘required’] = true;
$fields[‘shipping_country’][‘label’] = ‘Country’;
$fields[‘shipping_country’][‘placeholder’] = $contact_country;
$fields[ ‘shipping_country’ ][‘required’] = true;
$fields[‘shipping_state’][‘label’] = ‘State’;
$fields[‘shipping_state’][‘placeholder’] = $contact_state;
$fields[‘shipping_sic_code’] = array(
‘label’ => __(‘SIC Code’, ‘woocommerce’),
‘placeholder’ => _x($contact_sic_code, ‘placeholder’, ‘woocommerce’),
‘required’ => false,
‘clear’ => false,
‘type’ => ‘text’,
‘class’ => array(‘form-row-wide’),
‘autocomplete’ => $contact_sic_code,
‘priority’=>80
);return $fields;
} -
Hi there,
You’re in the wrong forum. To get help with the WooCommerce plugin you need to post in these forums:
https://wordpress.org/support/plugin/woocommerce
The forums you are currently posting are for providing support to WordPress.com hosted sites only.
-
Hi,
Sorry for that but I create account on website https://woocommerce.com, and from it side they send me to this forum, so that why I write here about my problem. -
Please contact WooCommerce support directly for help with their plugin. The forum you’re posting in now is for the hosting provider, WordPress.com, and we can only help with sites that are hosted on our servers.
If you’re using the free version of WooCommerce you can post in their community forum, here:
https://wordpress.org/support/plugin/woocommerce/
Or if you’re using any premium or payment gatewy add-on downloaded from WooCommerce.com you can reach live chat and email support here:
- The topic ‘Woocommerce function to fill form’ is closed to new replies.