Showing Product View Count on Woo commerce Product Page

前端 未结 2 973
失恋的感觉
失恋的感觉 2020-12-21 11:24

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 p

2条回答
  •  盖世英雄少女心
    2020-12-21 11:43

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

提交回复
热议问题