Skip to content

Instantly share code, notes, and snippets.

@kigold
Last active April 3, 2017 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kigold/95cddbf9ed7bca3e6dfe6244603986af to your computer and use it in GitHub Desktop.
Save kigold/95cddbf9ed7bca3e6dfe6244603986af to your computer and use it in GitHub Desktop.
Wordpress js script to get user field anf then user the value to change the the data-counter-value of a stats counter
//Select Stat counter element
var y = document.querySelectorAll('.credit_value [data-counter-value="2000000"]');
//Get user income from wp member field if id user_income
var user = document.querySelectorAll('#user_income .wpb_wrapper')[0];
var user_income = user.innerHTML;
var income = user_income.split(" ")[0];
income = income.replace(',', '');
income = Number(income) - 1;
console.log(income);
///set the data-counter-value attribute of the stat counter to the user monthly income
y[0].setAttribute('data-counter-value',String(income));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment