Woocommerce - Turn Off Autocomplete in Checkout Fields via "autocomplete=new-password" - php

I've found a couple of coding examples of this but nothing has worked. It seems such a simple thing to fix. We have an issue with our checkout page when certain users we're guessing have autocomplete on in their browser when checking out, we get duplicate or different Address 1 and 2 values. Even enabling the google api to help with autocomplete, didn't solve our issue. It corrected it some but, not enough.
This is one version of the solution I found in the interwebs melded with my own but, does not do anything....
/* Disable autofill address */
add_filter( 'woocommerce_form_field', 'change_autofill', 1, 1 );
function change_autofill( $field) {
$field = str_replace('autocomplete="billing_address_1"', 'autocomplete="new-password"', $field);
return $field;
}
I would like the ability to pick and choose which input fields to set the autocomplete attribute to "new-password" as I've read this forces all modern browsers to think it's a password field and does not try to fill them. When using inspector, each input field in the checkout has "autocomplete=off" already. That's why we are after this solution, in this manner...

Was able to get this working fully with this code (I was searching the wrong thing):
/* Disable browser autofill on all Woocommerce form fields */
add_filter( 'woocommerce_form_field', 'change_autofill', 1, 1 );
function change_autofill( $field) {
$field = str_replace('autocomplete="off"', 'autocomplete="new-password"', $field);
return $field;
}
This works because all fields are set with the attribute autocomplete=off it may not work for everyone. Use your inspector tool for each field to see. Whatever autocomplete is set to, is what you want your first start of str_replace searching for.
Cheers!

Just a comment regarding the approved answer, it should be:
$field = str_replace('autocomplete="new-password"', 'autocomplete="off"', $field);
instead of:
$field = str_replace('autocomplete="off"', 'autocomplete="new-password"', $field);

Related

How to change which choice in a Gravity Forms radio button field is selected using PHP as part of a gform_pre_submission

My PHP skills are not good but I learn by code example because I am not familiar with the syntax, but in this case I can not find a code example that works.
I want to set a Product Option Radio Button Field's selected value during a gform_pre_submission add_action based on another field's value. I've tried something like this (there are other functions and variables are defined elsewhere in advance, this is an abstract) but this approach isn't working for me and I am wondering what I am missing:
add_action( 'gform_pre_submission_FORMIDhere', 'select_radio_button' );
function select_radio_button( $form) {
foreach( $form['fields'] as &$field ) {
if( 53 === $field->id ) {
foreach( $field->choices as &$choice ) {
echo($aag_kg_nummorn.' / /'.$choice['value']);
if( $aag_kg_nummorn == $choice['value'] ) {
echo('Bingo!');
$choice['isSelected'] = true; // <- THIS line doesn't work for me
}
}
}
}
return $form;
}
Thank you for helping me in advance.
There are a couple of things I want to point out before answering
You should be modifying $_POST instead of the field, I can see you already figured this out.
gform_pre_submission is an action, not a filter, so returning the form here doesn't do anything.
The Answer
Say you have a product option field that has the ID of 2, and it has 3 options
First Option|1
Second Option|2
Third Option|3
Then the code will look like
add_action( 'gform_pre_submission_FORMIDhere', 'select_radio_button' );
function select_radio_button( $form ) {
$_POST['input_2'] = 'New Option|6';
}
I assume you are using this with a payment form that utilizes one of the gravityforms payment add-ons like stripe or Paypal, some of these add-ons (like PayPal Checkout) sends the total value to the payment gateway using JS before this action is fired, so the total value sent to the payment gateway will be the value of the option the user has already selected, but the total value on the entry will use the value you set in the code.
If you need help on how to override this from the JS side as well so you can send the overridden value to the payment gateway, I can write that in a separate answer.

Anyone Added Custom Field in to Task List Show into Dashboard (Phabricator)

I have added due_date into the Manifest Custom Field. Now I want that where ever task list showing to the user then Due Date also displayed over there.
I know its very small change in codebase but I am not able to debug this.
I missed a step you need I think to call $fields->readFieldsFromStoage($task) and then I used $field->getValueForStorage()
I can't say how correct or legal, of even efficient it is, but it does what I think you wanted
$fields = PhabricatorCustomField::getObjectFields(
$task,PhabricatorCustomField::ROLE_VIEW);
if ($fields){
$fields->readFieldsFromStorage($task);
foreach ($fields->getFields() as $field){
if ($field->getModernFieldKey()=='custom.mycustomfield'){
// in theory you might be able to add it like this
$item->addByline(pht('Due Date:%s', $field->getValueForStorage()));
$item->addByline(pht('Assigned: %s', $owner->renderLink()));
}
}
Hope that helps
Ok not a solution, but a place to start...
To alter this you need to edit
ManiphestTaskListView.php in
phabricator/src/applications/maniphest/view
Where you want to put due date is where "Assigned:" is put
if ($task->getOwnerPHID()) {
$owner = $handles[$task->getOwnerPHID()];
$item->addByline(pht('Assigned: %s', $owner->renderLink()));
}
Pulling in the custom fields may require a little more research, I think you can get to the tasks custom fields via the following
$fields = PhabricatorCustomField::getObjectFields(
$task,PhabricatorCustomField::ROLE_VIEW);
You could then pull out the field you want like this if you have to, I suspect there is a better way of doing this...so you just ask for the specific field
if ($fields){
foreach ($fields->getFields() as $field){
if ($field->getModernFieldKey()=='custom.mycustomfield'){
// in theory you might be able to add it like this
$item->addByline(pht('%s', $field->getXXXX()));
}
}
I'm not sure what you need to do to get the custom field value, i'm using getXXXX() to represent the sort of thing you might need to do, I think the custom fields often have a render() method but again I'm not completely sure how you go about getting that to render in your listview

Woocommerce checkout field maxlength, make input number field only (postcode)

I've been struggling with this for a few days now. What I want to do, it to limit the Postcode/zip fields to 4 numbers. So, to add a maxlength and a type="number" to those fields.
Things I've tried so far:
(functions.php)
add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
$fields['billing']['postcode']['maxlength'] = 4;
return $fields;
}
(functions.php) a jQuery way
(Unable to post, due some sort of code format error?)
EDIT: As it turned out, i was editing the old files on the server ... after editing the right one, the maxlength change works fine as the previously supplied code. But there is still the issue of changing the input type.
i tried adding $fields['billing']['billing_postcode']['type'] = 'number'; but that seems to REMOVE the input field all together for some reason. Possibly due to some error i guess. Not sure.
You'll need to add the attributes in a further subarray called 'custom_attributes', e.g.:
$fields['billing']['postcode']['custom_attributes']['maxlength'] = 4;

Creating configurable product programmatically

I'm trying to create configurable products programmatically in Magento 1.5.1.
I understand I need first to create simple related products, what I did. Now I manage to associate these simple products to make a configurable one.
Here is the critical part...
I keep the ids and some of the attributes values in an array, so I can later make my configurable product, but some of them are missing, I don't know which method to call.
I found this entry in Magento Wiki, that helped me and seems to fit my needs.
However, at the end the author is setting two things :
$product->setConfigurableProductsData($data);
$product->setConfigurableAttributesData($data);
and the values in the arrays have been taken in the admin page source using Firebug....and then translated into PHP arrays (array example for the first call) :
"I’ve harcoded the values for my associated products and attribute
data. You can get attribute data by viewing the source through the
admin interface and using Firebug for Firefox."
$data = array('5791'=>array('0'=>array('attribute_id'=>'491', // I already got this
'label'=>'vhs', // this too
'value_index'=>'5', // but what is value_index ?
'is_percent'=>0,
'pricing_value'=>'')),
'5792'=>array('0'=>array('attribute_id'=>'491',
'label'=>'dvd',
'value_index'=>'6',
'is_percent'=>0,
'pricing_value'=>'')));
My question is : is there a way to retrieve these values without using Firebug (which in my script won't help me a lot !), but programmatically. I already found a way to retrieve attribute values, labels, etc... using its code, but one field I don't know is value_index.
I guess this may be the option position in an option list, but not sure.
Also if someone knows a good/better way to create a configurable product in Magento, please tell me.
Any help is welcome thank you.
It seems you're asking where to retrieve the value_index value where you already have the label. Here's what I had: I didn't test this on 1.5x.
function get_attribute_id($option, $type) {
$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product', $type);
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attributeOptions = $attribute->getSource()->getAllOptions();
foreach ($attributeOptions as $opts_arr) {
if (strtoupper($opts_arr['label']) == strtoupper($option)) {
return $opts_arr['value'];
}
}
return FALSE;
}
$value_index = get_attribute_id('vhs', 'media_format');
No one else seemed to mention the easiest way to figure out what the value_index of vhs is: In the backend, under
Catalog > Manage > media_format > Manage Label/Options
Inspect the source of the individual form inputs. Where you have 'vhs' you should have an input named option[value][6]
As far as I understand your question, there are two options: a) create simple products by script, put the generated id's in an array and create the configurables using the ids or b) read the id's from the admin and put them in your script. Since programming is about automation I'd definately go for option a.

How do I remove unnecessary options from a select field in a Drupal form?

I'm using the better_exposed_filters module to create a set of exposed filters for a view. One of the filters is being displayed as a select field, and I would like the field to only display options that are actually associated with content in the database.
Currently, I am doing this using the hook_form_alter() method. For simplification, in the following example the field is called 'foo' and the content type with that field is called 'bar':
function my_module_form_alter(&$form, $form_state, $form_id) {
// Get all the values of foo that matter
$resource = db_query('select distinct field_foo_value from {content_type_bar}');
$foo = array();
while($row = db_fetch_object($resource)) {
$foo[$row->field_foo_value] = $row->field_foo_value;
}
$form['foo']['#options'] = $foo;
}
This works great -- the form displays only the options I want to display. Unfortunately, the view doesn't actually display anything initially and I also get the following error message:
An illegal choice has been detected. Please contact the site administrator.
After I filter options with the form once, everything seems to work fine.
Does anyone know how I can solve this problem? I'm open to an entirely different way of weeding out filter options, if need be, or a way that I can figure out how to address that error.
Under your view argument there should be a section called "Validator options" with ""Action to take if argument does not validate under it. Depending on what you want shown, you should be able to display all values or display an empty page.
I found a solution that works, but it's somewhat hackish. I force the form to think that it's validated, and it doesn't complain anymore, with the following line at the bottom of the function:
$form['foo']['#validated'] = true;

Categories