I am currently working on a shop, which picks up shoes from the customer, cleans them and then returns them back to the customer.
It features local pickup only in an assigned area, based on a range of postcodes. But if the user types in a postcode that is not included, the site should show a message that the user is not within this area and needs to send the shoes via mail.
My question is whether there is a PHP or JavaScript hook I can catch when the user changes his postcode, so I can display this message.
I already tried to do this based on input change and to look if the ID of the shipping method is existing. But this does not quite work.
$('#billing_postcode').on('change', function (event) {
event.preventDefault()
if ($('#shipping_method_0_local_pickup2')) {
console.log('Pickup is possible')
} else {
console.log('Pickup is not possible')
}
})
Related
I am building an application which includes a custom donation form where users can select:
Frequency: monthly, single
Amount: 3 x Buttons with values, input for custom value
I am using the PayPal Donate SDK and cannot find a way to pass across the amount or frequency so that the amount is pre-filled and the "make this a monthly donation" checkbox selected/deselected based on the users input.
The PayPal button has been added to the page (just absolute styled over the form button) and the SDK opens the donation page in a modal which is my desired result.
This is the code to display my button:
window.PayPal.Donation.Button({
env: "sandbox",
hosted_button_id: "xxxxxxxxxxxx",
onComplete: function() {
// Redirect to success page, save the PP transaction details, etc.
}
}).render("#paypal-donate-button-container");
With the standard PayPal.Buttons API, I am able to pass in a createOrder function like so, where I can set the amount, for example;
window.PayPal.Buttons({
// ...
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: document.querySelector(".selected-premium").dataset.value
},
reference_id: document.querySelector(".selected-premium").dataset.days + "-days"
}]
});
}
}
Is there a way to pass through the amount and frequency using the SDK, similar to how I can do it with the standard payments API? If not, what are the alternatives in 2022 that don't rely on SO answers that use docs that no longer exist/deprecated methods?
With the PayPal Donations flow (this includes the Donate SDK)
You can pass a parameter for the amount and currency_code. If you do pass a prefilled amount, an option to make the donation recurring will not be available.
You cannot pre select the option to make the donation recurring in the Donations flow.
For the case of recurring donations -- since it's not possible to precheck the option to make them recurring in the Donations flow, nor is it possible to prefill the amount and have that choice of recurrence even be available -- what you could do is instead use a Subscription flow for when a recurrence is selected, and have this render in a separate div container that is shown/hidden based on your monthly vs single selection. A subscribe button for your account can be generated at: https://www.paypal.com/billing/plans . The plan it uses must have a specific amount, but this can be overridden in the JS createSubscription function (based on whatever selection or amount was entered on your site) by (in addition to the base plan_id) adding a plan object that contains a billing_cycles object with the amount/frequency you want.
After a user signed in his/her account, he/she will be ask what is his/her user role.
IMG 1: ask user role
After selecting a role, it will then be save in the database,
IMG 2: saved user role
So, how do we retrieve the specific data from Firebase database and then print it in the HTML?
IMG 3: show the user role
These are the codes I used in my .js
function app(user){
function updateMyStatus(e){
var myUpdate={};
myUpdate.email = user.email;
myUpdate.displayName = user.displayName;
myUpdate.status = document.getElementById("clientStatus").value;
fb.child(user.uid).set(myUpdate);
}
function receiveUpdate(received){
var data = received.val();
console.log( data );
document.getElementById('role').innerHTML= "";
}
document.getElementById('userName').innerHTML = user.displayName;
var fb = firebase.database().ref('Accounts');
document.getElementById("clientStatus")
.addEventListener("input",updateMyStatus);
}
and if the user has already a user role(status) as shown in the image 2, how do you hide the Dropbox that is shown in the image 1?
The below will get back your data from Firebase for that account. Then it is a matter of setting the values to their respective HTML elements.
fb.child(AccountId).on(‘value’, callbackFunction)
For reference: https://firebase.google.com/docs/database/web/read-and-write
function receiveUpdate(received){
var data = received.val();
console.log( data );
document.getElementById('role').innerHTML= "";
//hide the dropdown box
document.getElementById("clientStatus").style.display = "none";
}
document.getElementById("clientStatus").addEventListener("input",updateMyStatus);
//put this under your other event listener
fb.child('Accounts').on(‘value’, receiveUpdate);
This code will not work as written. I hope this helps give you a good idea.
Based on your current code, and based on my own understanding of the Firebase Realtime Database, these are the steps you need to take:
Register a listener to listen for changes to the database
To be more specific, you need to add a listener to the particular field that you are interested in in the database.
This listener should preferably not be inside any function.
This listener would check whether a role exists for your user in the database.
If yes, hide the input field and display user's details.
Else, display both the input field and the user's details.
As I have no experience using the Realtime Database (I have only used Cloud Firestore before), I am not very familiar with its syntax. But the link suggested by #Andre Kool and #thezachcannon in the previous post has examples of adding a listener to a particular database reference.
Hope that helped.
I need to check (OnLoad) whether an Account has Notes added to it. I've tried doing this using workflows but that only tests after a Note is added rather than if they are already there i.e. On Change, On updating, On status change etc.
Also tried accessing Notes via JavaScript but seems to not be able to reach the attribute. Will paste JScript here if this will help, though that might be the wrong way to go anyway.
function NotesAlert() {
// the 'notestext' field is the Notes description area
var NotesDesc = Xrm.Page.getAttribute("notestext").getValue();
if(NotesDesc !=null) {
Xrm.Page.getAttribute("dt_legacyuserurn").setValue("Notes exist for
this Acc");
}
}
Whether it is client side (JavaScript) or server side (C# plugins, workflows), you have to query the associated notes (annotations) for that particular account record & do the validation.
If you want to validate it in JS, use web api to get the associated notes of account from onLoad & onSave Form events, even onChange of fields can be done like below.
var query = "/api/data/v8.2/annotations?$filter=_objectid_value eq" + accountId;
If you want to validate in Plugins/Workflows (custom), use fetchxml or query expression to query the associated notes of account from Create, Update messages.
How can I use mixpanel in SPA? I want to track some events created by user.
When user opens page first time randomly generated ID is given to him. After signing in this action is executed.
mixpanel.alias(data.id);
mixpanel.track('Sign In', {
'Email': response.data.email
});
user.setCurrent(data);
In user.setCurrent function I do this:
mixpanel.identify(data.id);
But in my mixpanel account random ID still given to user? What should I do to prevent this?
Using mixpanel.identify doesn't actually change the ID Mixpanel uses:
On the signup confirmation page, you call mixpanel.alias("john#hotmail.com"). This doesn't actually change his ID - he is still being identified using the random ID we originally assigned him.
What you can do is to add the ID you use in your database to the Mixpanel Person, just like you do with the email at the moment. Then configure the Mixpanel UI to show that column in your reports.
mixpanel.track('Sign In', {
'Email': response.data.email,
'UserId': response.data.id
});
I have a form with a submit button that when pressed it emails the contents to a single email address. The email is then manually forwarded to one of 3 people on a rota system.
Is there any way that the submit button could work so that when the first site visitor clicks it the inquiry goes to staff member 1, when the next one does it the inquiry goes to staff member 2 when the next one does it it goes to staff member 3 and then back to staff member 1 when the next one does it.
Any help would be greatly appreciated.
Make a column in database for current active_member
set 0 default value.
get first staff member from database with column active_member value 0
set column active_member to 1 when you send mail to that staff member.
when no member have active_member value column value 0 than Reset all value to 0.
Use PHP sessions to store a server variable, for example: next_email_recip. At the top of your PHP file, you will need to put:
session_start();
if (isset($_SESSION['next_email_recip'])) {
$next_email_recip = $_SESSION['next_email_recip'];
if ($next_email_recip == 3) {
$_SESSION['next_email_recip'] = 1;
}else{
$_SESSION['next_email_recip'] = $next_email_recip + 1;
}
}else{
$next_email_recip = 1;
$_SESSION['next_email_recip'] = 2;
}
In your PHP code, have a simple array:
$arrRecips = array(
"1" => "bob#email.com",
"2" => "joe#email.com",
"3" => "fred#email.com",
);
$this_time_recip = $arrRecips[$next_email_recip];
The best solution is store the email addresses to be used in a table (email_address_table), and each submission in a seperate table (sent_table) then everytime a visitor hits submit, before it saves and gets sent (sent_table), it checks what was the last email address that was used in (sent_table), and check which one is next in the list in the (email_address_table), saves and sent it, that way you can be sure to get an even distribution. And one step further you can add a field (off) in the (email_address_table), that way if somebody is to not use this email address again or it is dedicated and this person is off, you set the status to off, and the rotation will only happen between the remaining agent.
Yes, you can create a table and name it sent_emails. When the first email is sent enter first email address in this table. Then when second user comes and email is sent to him first check this table and if the last two records are of different email ids send to this email address. Do this for all new users like this, means before sending any mail first check their entry in this table for last two records. By creating new table you will also be able to record the time at which emails were sent.