'WordPress onclick counter

Let's say I have a number (0) on my Wordpress website and I want it to increase by 20 each time someone clicks on a button. I also want it to not reset and be visible for everyone. Any ideas on how to do this with html code or any other solutions?



Solution 1:[1]

This is example when click on submit button, you can modify as per your need

  if ( isset( $_POST['submit'] ) ) {
    $option_name = 'order_ref' ;
$counter = get_option( 'order_ref' );

//Limit the counter, based on the range of orders you will be getting per day
if ($counter <= 99 ) {
$counter = $counter + 1;
} else {
$counter = 1;
}

if ( get_option( $option_name ) !== false ) {
// The option already exists, so we just update it.
update_option( $option_name, $counter );

} else {
$deprecated = null;
$autoload = 'no';
add_option( $option_name, $counter, $deprecated, $autoload );
}   

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 CBroe