在 Woo commerce 产品页面上显示产品视图计数 [英] Showing Product View Count on Woo commerce Product Page

查看:20
本文介绍了在 Woo commerce 产品页面上显示产品视图计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 WordPress 网站 www.kampungcourse.id 来选择语言课程.我想展示有多少人看过特定的产品.使用帖子视图计数器插件,它会在主页和博客页面上显示帖子视图,但不会在 woo-commerce 产品页面上显示.任何人都可以帮助自定义代码来实现这一点

i have WordPress site www.kampungcourse.id to choose language program courses. i want to show how many people have watched particular product . using the post view counter plugin it show post view on home page and blog page but not on woo-commerce product pages. can anyone help with custom code to implement this

我尝试使用帖子查看计数器插件,但它不适用于 woo-commerce 的产品页面.

i tried using post view counter plugin but it does not work on product pages that are part of woo-commerce.

推荐答案

请替换此功能如下所示,以在页面顶部的评分栏旁边显示视图.

Please Replace this function as below to show view on top of page next to rating bar.

add_action( 'woocommerce_before_add_to_cart_button', 'add_content_before_rating_button_func',0 );

    function add_content_before_rating_button_func() {        
                global $product;
                $id = $product->id;         
                $meta = get_post_meta( $id, 'views_count', TRUE );
                if(empty($meta))
                {
                    $result = 0;
                }
                else
                {        
                $result = count(explode(',',$meta)); 
                }       

        ?>
                <script>
                var html="";
                var result = "<?php echo $result ?>";
                html += "<div class='custom-visitor-count-st' style='font-size: 20px;'>";
                html += "<i class='fa fa-eye'></i>";
                html += "<span class='cv-value'>";
                html += result;
                html += " Views</span></div>";

                $(html).insertAfter('.woocommerce-product-rating');
                </script>
                <?php
        }

这篇关于在 Woo commerce 产品页面上显示产品视图计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆