Woocommerce update_checkout trigger - wordpress

I made a checkout page with a select field, when i change the select, i call
update_checkout
so that i can add some custom fee based on the select value
also the list of options is (or should be based) on shipping method, this is driving me to a loop that i can exit.
I change the select, the checkout is correctly updated with the additional fee, but when i change the shipping method, the update_checkout is triggered and it recalculate the list of options (and this is correct), but at the moment the select is filled with the new values, the update_checkout is triggered again. And this way the update_checkout recalucalte agai refilling the select (and setting it back to default value)
its quiete hard to explain what is happening, but im looking for a way to intercept what is calling update_checkout.

Solved with a hidden filed (ugly solution), setting the value of the hidden field on select change, the on the 'updated_checkout' i grab the value from the hidden field and if is still present in the select i force the selection. it's not perfect, since there are some "flashes" on the select field that may confuse the user

Related

Google Tag Manager- is there a way to track when a checkbox is selected and then the user hits the Checkout button on that same page?

Sorry if this is a dumb question. I'm a GTM noob and from googling I see tutorials on tracking the clicks (checkbox element and Checkout button) separately but was wondering if there's any way this can be one Event in Google Analytics.
For example, on our store's cart page a checkbox to add a product's accessory is selected by default. I want to know how many people are hitting the Checkout button and leaving this "add an accessory" checkbox checked.
Is there a way to push an Event as something like "Checkout click - Add On Checkbox - Selected"?
Thanks in advance!
Yes, you can detect if a checkbox is checked on any event, using a Custom Javascript variable, value of which you then can use in the trigger, or in your tag. Or in a different variable, of course.
If you provide the html of your checkbox, we can give you code for the variable to return the checkbox state if you're not comfortable with JS.
//Upd
In your code, you have a few errors. First, no need to name the function in the CJS variable. Also, you write a bit too much code and rely on JQuery with no need. It can be solved simpler with pure JS like so:
function(){
return document.querySelector("input#add-subscription").checked;
}
Now, about the rest of what you're saying. Having this checkbox action. You have a wrong understanding. This is not a checkbox action. This code only gets the state of the checkbox whenever the value of this variable is being used.
So if you're gonna use the value of this variable when a person clicks on the form submission CTA, then this code will run on that click, assessing the value of the checkbox.
Your amazon example works. But you don't need to assume that the checkbox is checked by default. The default doesn't mean anything here. The state of the checkbox is assessed on the trigger where the value of the CJS var is used, that's it.
We're proceeding with your question: I'm confused about having the multiple criteria (checkbox is checked and user hits Checkout button) and if including both as triggers would work You're making another mistake here. They're not both triggers. One of them is a trigger indeed, which is a click trigger. The other, however, is a condition for the trigger to fire. You know how in the trigger, you click the checkbox that says "some events"? This fella:
Once you have that, you can add conditions. Like, only use this trigger when... when what? Anything really. In our case it would be when the checkbox is true.
Finally, for the checkout click, you don't typically need more than just the click trigger with the CSS selector criteria.
Anyhow, to be short, this is about how your trigger should look like:
Thanks! In this case the checkbox element for my cart page is:
<input id="add-subscription" type="checkbox" checked="checked" class="form-checkbox js-product-subscribe-newux mt-10 sm:mt-0" name="sub" value="remove">
I was thinking the variable could be:
function checked() {
var check = jQuery('form-checkbox js-product-subscribe-newux mt-10 sm:mt-0').attr("checked");
if(check === "checked") {
return true;
} else {
return false;
}
}
However where I get confused is having this checkbox action (checkbox is checked) only count as an event when the user hits the Checkout button. Using this Amazon cart page as an example, assuming the "This is a gift" checkbox is clicked by default, "This is a gift" checkbox would I just then add the Trigger as having two criteria, roughly: {{Checkbox Variable}} = "true" & Click Text = "Proceed to Checkout? I'm confused about having the multiple criteria (checkbox is checked and user hits Checkout button) and if including both as triggers would work in this case so I can see how many times users click to checkout from the cart while leaving that box checked. Or would the Click on the Checkout button need to be it's own separate variable rather than just specifying the Checkout button name in the trigger criteria?

New field not visible in field group on form

I have added an extra field to a field group, which already contained 4 fields, this field group is used on the form: smmBusRelTable.
The 4 existings fields are appearing without problems, the new field isn't showing up in the form.
The field is visible.
The field exists in the field group on the form.
I have resetted my personalise screen on that form.
I can add the field through personalise, but it won't show up.
It has no CountryCode filled in.
Any ideas?
Some things to try:
Right clicking on the form and click restore.
Go to the control (group, grid, etc) you're expecting to see the fields in, and verify the DataGroup property has the correct Field Group selected. Try clearing this property, saving, then adding it back again.
The init method on the form, set the visible parameter of the field on false. That is why the field showed when i added the field group on a new form.

Something like setVisible() for Dynamics AX 2012

Is there any way to do that?
I mean, if the form fullfill specific conditions setVisible true or false to a control in the form? Or if i check a CheckBox, show some specific ComboBox?
Thanks in advance for your help
I would recommend enabling and disabling fields, rather than hiding them.
Open a Supplier, and on the Invoice and Delivery fast tab choose select the Calculate withholding tax CheckBox. This is the VendTable form.
The Calculate withholding tax control will enable and disable a second control depending upon the value selected.
The second control has it's property AutoDeclaration set to Yes, and the event that fires the change can be found on the forms VendTable data source. Find the relevant field (VendTable > Data Sources > Vend Table > Fields > TaxWithholdCalculate) and notice that the modified method has been overridden, changing the control's enabled property. It also has a visible property should you want to remove it from view.
Top Tip: In case that you are not aware, you can right click on any control on a form and choose the Personalise option from the context menu. From there is a form which contains a very useful box called System name. You can find the name of the control/table field from this.
I suggest you this solution for your second problem:
if i check a CheckBox, show some specific ComboBox?
I assume your form is complete (it has all controls needed : comboboxes, checkboxes, etc). And the controls AutoDeclaration-property is set to 'Yes'.
In the AOT expand the Form till you find the CheckBox, expand it as well
Right-click its Methods and select 'Override method' >> 'Clicked'
Finally you can add this code and save/compile the form:
myComboBox.visible(true);
It should look like:
public void clicked()
{
super();
myComboBox.visible(true);
}

Can we copy the value of one field to another in a repeating table of infopath form?

Hi guys can anyone tell me how to copy a field value in a repeating table to another field when we insert another row. It is just like amazon checkout process. In Amazon checkout process we have to click a check box when our billing address is same as our shipping address.
In this scenario am having one text box and drop down box fields in a repeating table. When am writing something in the text box and inserting another row. here come the problem I have inserted a value in the drop down box, when the value is selected in the drop down box the textbox value from the parent should be copied to the child node. This has to be done without any code behind.
Please help me regarding this issue
You could probably do this using the default value of the child node.
The default value can reference another field either on your main datasource or any secondary datasource.
I would assume that you don't want this updating when the user adds another child node. If that is the case then you will need to uncheck the "Update this value when the value of the foumlua is recalculated."

Is it possible to catch a comboBoxes value before change with a change event

I am displaying a combo box in something of a WYSIWYG preview. I want the user to be able to click on the combo box and see the options inside, but I don't want them to be able to change the value. I tried using preventDefault() on the change event but it doesn't work. I don't want to disable it because I do want the user to be able to "look inside" the dropdown.
So I'm trying to block the change, but can't. My next resort is to change the selected index back to what it was before the change, Is there any way to do this within the scope of a ListEvent.CHANGE event listener?
Current Workaround is to basically re-assign the controls selected item the same way I am defining the selected item when I originally build it (a default selection). So a user sees their change then it immediately changes back to the default selection.
Are you sure that a combobox is what you want? could you do the same thing with a list component that is not selectable?
update:
If you must use a combobox and you dont want the lag from listening for the event and resetting the control, I see two possible options. You could subclass the control and make your own. When you do, hijack any methods that set the value besides the initial selection.
Or, you could try something like this: http://wmcai.blog.163.com/blog/static/4802420088945053961/. The site seems like it is in another language but the code is still there. It will allow you to make your options disabled, so the user cannot choose one of the other options.
HTH

Resources