如何在Woocommerce产品页面中显示最近24小时的观看次数

时间:2019-03-07 03:08:03

标签: php wordpress woocommerce counter product

如何在Woocommerce单一产品页面中显示过去24小时的观看次数?

我找到了此代码,它可以工作。但是我怎么只能在过去的24小时内计数?

预先感谢您的回答。

function getPostViews($postID){
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
        return "0 View";
    }
    return $count.' Views';
}
function setPostViews($postID) {
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        $count = 0;
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
    }else{
        $count++;
        update_post_meta($postID, $count_key, $count);
    }
}
// Remove issues with prefetching adding extra views
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);

0 个答案:

没有答案