简体   繁体   English

WordPress onclick 柜台

[英]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.假设我的 Wordpress 网站上有一个数字 (0),我希望它在每次有人单击按钮时增加 20。 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?关于如何使用 html 代码或任何其他解决方案执行此操作的任何想法?

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 );
}   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM