Tag: WooCommerce

  • WooCommerce Show Reviews in Separate Standalone Page

    WooCommerce Show Reviews in Separate Standalone Page

    Hi Folks, it is me again. Sometimes we want to show all reviews (perhaps only 5 ⭐⭐⭐⭐⭐) in a separate page for our end users. Obviously to make our customers we have many great 5 star reviews.

    I could not find a perfect solution for this. So, I made a quick shortcode function to acheive this.

    Lets start, shall we?

    Following codes can be put into your child theme > functions.php file

    First we create our shortcode

    add_shortcode( 'woo_reviews', 'show_reviews' );

    Then we define our shortcode function

    function show_reviews( $atts ) {
    
    $atts = shortcode_atts( array(
    'rating' => '',
    'product' => '',
    ), $atts, 'woo_reviews' );
    
    // set up meta query to filter by rating if specified
    $meta_query = array();
    if ( $atts['rating'] ) {
    $meta_query[] = array(
    'key' => 'rating',
    'value' => $atts['rating'],
    'compare' => '='
    );
    }
    
    $comments_query = new WP_Comment_Query( array(
    'post_type' => array( 'product' ),
    'post__in' => $atts['product'],
    'meta_query' => $meta_query,
    ) );
    
    // Output buffer to capture wp_list_comments
    ob_start();
    
    if ( ! empty( $comments_query->comments ) ) {
    echo '<div class="woocommerce">';
    echo '<div id="reviews">';
    echo '<div id="comments">';
    echo '<ol class="commentlist">';
    wp_list_comments( apply_filters( 'woocommerce_product_review_list_args', array( 'callback' => 'woocommerce_comments' ) ), $comments_query->comments );
    echo '</ol>';
    echo '</div>';
    echo '</div>';
    echo '</div>';
    } else {
    echo '<p>No reviews found.</p>';
    }
    
    return ob_get_clean();
    }

    Oh by the way you can do following things as well

    [woo_reviews rating="5"]
    [woo_reviews product="33,34"]
  • Yith WooCommerce Subscriptions : List all the active subscribers

    Yith WooCommerce Subscriptions : List all the active subscribers

    In order to do a custom listing of active subscriptions in Yith WooCommerce Subscription plugin, here is the code you can write:
    Assuming your WordPress database table prefix is the default: “wp_”

    
    function list_all_subscriptions() {
    
    	global $wpdb;
    
    	$query= "";
    	$query .= "SELECT wp_posts.* FROM wp_posts ";
    	$query .= "INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) ";
    	$query .= "WHERE 1=1 ";
    	$query .= "AND wp_posts.post_type = 'ywsbs_subscription' ";
    	$query .= "GROUP BY wp_posts.ID ";
    	$query .= "ORDER BY ID DESC";
    
    	$subscribers = $wpdb->get_results( $query );
    }
    

    Hell, if you want to move one step further and list only active members, then you can throw “AND” condition in the query itself, like below;

    
    function list_all_subscriptions() {
    
    	global $wpdb;
    
    	$query= "";
    	$query .= "SELECT wp_posts.* FROM wp_posts ";
    	$query .= "INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) ";
    	$query .= "WHERE 1=1 ";
    	$query .= "AND wp_posts.post_type = 'ywsbs_subscription' ";
    	$query .= "AND ( wp_postmeta.meta_key = 'status' AND wp_postmeta.meta_value = 'active' ) "; 
            // will filters only active members
    	$query .= "GROUP BY wp_posts.ID ";
    	$query .= "ORDER BY ID DESC";
    
    	$subscribers = $wpdb->get_results( $query );
    }
    

    You can do the pagination as well now.

    Final Note: There is a file /plugins/yith-woocommerce-subscription/includes/admin/class.ywsbs-subscriptions-list-table.php, look or find the function prepare_items() , this is where I derived above query from.