skip to Main Content

Hello to all dear friends,
How can we add a new row actions item to product reviews?

I used the following code, but the new item is not added

add_filter('comment_row_actions','my_action_row', 100, 2);

function my_action_row($actions, $comment){

        
        $actions = '<a href="http://www.google.com/?q='.get_permalink($post->ID).'">check if indexed</a>';

    return $actions;
}

I have included a picture for you
https://postimg.cc/v4K2SwDB

2

Answers


  1. Chosen as BEST ANSWER

    i use this code from my plguins Fatal error: Uncaught Error: Class "CustomReviewsListTable" not found

    add_filter( 'woocommerce_product_reviews_list_table', function( $html, $reviews_list_table ) {
    
    $reviews_list_table->prepare_items();
    ob_start();
    
    ?>
    <div class="wrap">
        <h2><?php echo esc_html( get_admin_page_title() ); ?></h2>
    
        <?php $reviews_list_table->views(); ?>
    
        <form id="reviews-filter" method="get">
            <?php $page = isset( $_REQUEST['page'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ) : 'product-reviews'; ?>
    
            <input type="hidden" name="page" value="<?php echo esc_attr( $page ); ?>" />
            <input type="hidden" name="post_type" value="product" />
            <input type="hidden" name="pagegen_timestamp" value="<?php echo esc_attr( current_time( 'mysql', true ) ); ?>" />
    
            <?php $reviews_list_table->search_box( __( 'Search Reviews', 'woocommerce' ), 'reviews' ); ?>
    
            <?php /* $this->reviews_list_table->display(); */ ?>
    
            <?php
    
                $custom_review_list_table = new CustomReviewsListTable();
                $custom_review_list_table->display();
            ?>
        </form>
    </div>
    <?php
    wp_comment_reply( '-1', true, 'detail' );
    wp_comment_trashnotice();
    return ob_get_clean();
    

    }, 10, 2 );


  2. The comment_row_actions filter is intended for WordPress > Comments, not for Woocommerce > Product > Reviews.

    As of the latest Woocommerce v9.0.2, the "Review action links" is being handled at woocommerce/src/Internal/Admin/ProductReviews/ReviewsListTable.php in which extended from a WordPress core WP_List_Table class.

    The action links are being processed in Woocommerce ReviewsListTable class at handle_row_actions method. However, the plugin is currently not offering any hook that anyone can use to integrate a custom review link.

    In this case, the only way to achieve the functionality is to recreate the Reviews List Table using the woocommerce_product_reviews_list_table filter hook. However, this will require overriding one of the Woocommerce core class.

    Note: This approach is highly not recommended. This answer is only intended to share information on how to achieve such goal.


    Recreate the Woocommerce Reviews List Table using the woocommerce_product_reviews_list_table filter hook (resides at woocommerce/src/Internal/Admin/ProductReviews/Reviews.php)

    add_filter( 'woocommerce_product_reviews_list_table', function( $html, $reviews_list_table ) {
    
        $reviews_list_table->prepare_items();
        ob_start();
    
        ?>
        <div class="wrap">
            <h2><?php echo esc_html( get_admin_page_title() ); ?></h2>
    
            <?php $reviews_list_table->views(); ?>
    
            <form id="reviews-filter" method="get">
                <?php $page = isset( $_REQUEST['page'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ) : 'product-reviews'; ?>
    
                <input type="hidden" name="page" value="<?php echo esc_attr( $page ); ?>" />
                <input type="hidden" name="post_type" value="product" />
                <input type="hidden" name="pagegen_timestamp" value="<?php echo esc_attr( current_time( 'mysql', true ) ); ?>" />
    
                <?php $reviews_list_table->search_box( __( 'Search Reviews', 'woocommerce' ), 'reviews' ); ?>
    
                <?php /* $this->reviews_list_table->display(); */ ?>
    
                <?php
                    $custom_review_list_table = new CustomReviewsListTable();
                    $custom_review_list_table->display();
                ?>
            </form>
        </div>
        <?php
        wp_comment_reply( '-1', true, 'detail' );
        wp_comment_trashnotice();
        return ob_get_clean();
    
    }, 10, 2 );
    

    As you can see on the snippet, $this->reviews_list_table->display() is being overridden by a CustomReviewsListTable class. The CustomReviewsListTable is equivalent to ReviewsListTable.php file but with a modified version of the handle_row_actions method to insert a custom "Review action links".

    Hope this information helps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search